Fix 1.19.1 client command API bugs ()

This commit is contained in:
apple502j 2022-07-26 20:47:54 +09:00 committed by GitHub
parent d4b7bd1caa
commit 0c17ea96b8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 2 deletions
fabric-command-api-v2/src/client/java/net/fabricmc/fabric

View file

@ -128,7 +128,7 @@ public final class ClientCommandInternals {
return type == builtins.dispatcherUnknownCommand() || type == builtins.dispatcherParseException();
}
// See CommandSuggestor.method_30505. That cannot be used directly as it returns an OrderedText instead of a Text.
// See ChatInputSuggestor.formatException. That cannot be used directly as it returns an OrderedText instead of a Text.
private static Text getErrorMessage(CommandSyntaxException e) {
Text message = Texts.toText(e.getRawMessage());
String context = e.getContext();

View file

@ -37,7 +37,8 @@ abstract class ClientCommandSourceMixin implements FabricClientCommandSource {
@Override
public void sendFeedback(Text message) {
this.client.getMessageHandler().onGameMessage(message, false);
this.client.inGameHud.getChatHud().addMessage(message);
this.client.getNarratorManager().narrate(message);
}
@Override

View file

@ -20,6 +20,7 @@ import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.text.Text;
@ -28,6 +29,13 @@ import net.fabricmc.fabric.impl.command.client.ClientCommandInternals;
@Mixin(ClientPlayerEntity.class)
abstract class ClientPlayerEntityMixin {
@Inject(method = "sendCommand(Ljava/lang/String;)Z", at = @At("HEAD"), cancellable = true)
private void onSendCommand(String command, CallbackInfoReturnable<Boolean> cir) {
if (ClientCommandInternals.executeCommand(command)) {
cir.setReturnValue(true);
}
}
@Inject(method = "sendCommand(Ljava/lang/String;Lnet/minecraft/text/Text;)V", at = @At("HEAD"), cancellable = true)
private void onSendCommand(String command, Text preview, CallbackInfo info) {
if (ClientCommandInternals.executeCommand(command)) {