From 42ec7a26988d4889cff5f3764659837efab833ff Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 7 Oct 2023 11:07:56 +0700 Subject: [PATCH] fix infinite chat not working with other mods (specifically symbol chat) --- .../chipmunkmod/mixin/ChatScreenMixin.java | 34 ------------------- .../mixin/TextFieldWidgetMixin.java | 20 +++++++++++ src/main/resources/chipmunkmod.mixins.json | 3 +- 3 files changed, 22 insertions(+), 35 deletions(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/TextFieldWidgetMixin.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java index 2843296..01cd34a 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java @@ -28,40 +28,13 @@ import java.util.List; @Mixin(value = net.minecraft.client.gui.screen.ChatScreen.class) public class ChatScreenMixin extends Screen { - @Shadow protected TextFieldWidget chatField; @Shadow private String originalChatText; - @Shadow ChatInputSuggestor chatInputSuggestor; - @Shadow private int messageHistorySize = -1; public ChatScreenMixin(String originalChatText) { super(Text.translatable("chat_screen.title")); this.originalChatText = originalChatText; } - @Inject(at = @At("TAIL"), method = "init", cancellable = true) - public void init (CallbackInfo ci) { - final MinecraftClient client = MinecraftClient.getInstance(); - - this.messageHistorySize = client.inGameHud.getChatHud().getMessageHistory().size(); - this.chatField = new TextFieldWidget(client.advanceValidatingTextRenderer, 4, this.height - 12, this.width - 4, 12, Text.translatable("chat.editBox")) { - protected MutableText getNarrationMessage() { - return super.getNarrationMessage().append(ChatScreenMixin.this.chatInputSuggestor.getNarration()); - } - }; - this.chatField.setMaxLength(Integer.MAX_VALUE); - this.chatField.setDrawsBackground(false); - this.chatField.setText(this.originalChatText); - this.chatField.setChangedListener(this::onChatFieldUpdate); - this.chatField.setFocusUnlocked(false); - this.addSelectableChild(this.chatField); - this.chatInputSuggestor = new ChatInputSuggestor(this.client, this, this.chatField, this.textRenderer, false, false, 1, 10, true, -805306368); - this.chatInputSuggestor.setCanLeave(false); - this.chatInputSuggestor.refresh(); - this.setInitialFocus(this.chatField); - - ci.cancel(); - } - @Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true) private void sendMessage (String chatText, boolean addToHistory, CallbackInfoReturnable cir) { final MinecraftClient client = MinecraftClient.getInstance(); @@ -143,11 +116,4 @@ public class ChatScreenMixin extends Screen { cir.cancel(); } - - @Unique - private void onChatFieldUpdate(String chatText) { - String string = this.chatField.getText(); - this.chatInputSuggestor.setWindowActive(!string.equals(this.originalChatText)); - this.chatInputSuggestor.refresh(); - } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/TextFieldWidgetMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/TextFieldWidgetMixin.java new file mode 100644 index 0000000..c56b682 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/TextFieldWidgetMixin.java @@ -0,0 +1,20 @@ +package land.chipmunk.chipmunkmod.mixin; + +import net.minecraft.client.gui.widget.TextFieldWidget; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(TextFieldWidget.class) +public class TextFieldWidgetMixin { + @Shadow private int maxLength; + + @Inject(method = "setMaxLength", at = @At("HEAD"), cancellable = true) + private void setMaxLength (int length, CallbackInfo ci) { + this.maxLength = Integer.MAX_VALUE; + + ci.cancel(); + } +} diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index b52bc7c..e677ea7 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -22,7 +22,8 @@ "SharedConstantsMixin", "TextSerializerMixin", "CommandDispatcherMixin", - "SoundSystemMixin" + "SoundSystemMixin", + "TextFieldWidgetMixin" ], "injectors": { "defaultRequire": 1