forked from ChomeNS/chipmunkmod
fix infinite chat not working with other mods (specifically symbol chat)
This commit is contained in:
parent
31f49729fd
commit
42ec7a2698
3 changed files with 22 additions and 35 deletions
|
@ -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<Boolean> 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();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
}
|
|
@ -22,7 +22,8 @@
|
|||
"SharedConstantsMixin",
|
||||
"TextSerializerMixin",
|
||||
"CommandDispatcherMixin",
|
||||
"SoundSystemMixin"
|
||||
"SoundSystemMixin",
|
||||
"TextFieldWidgetMixin"
|
||||
],
|
||||
"injectors": {
|
||||
"defaultRequire": 1
|
||||
|
|
Loading…
Reference in a new issue