mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 21:06:16 +00:00
refactor: use ModifyConstant for infinite chat mixin
This commit is contained in:
parent
92867a6217
commit
a97c047566
1 changed files with 8 additions and 48 deletions
|
|
@ -6,15 +6,12 @@ import land.chipmunk.chipmunkmod.data.ChomeNSBotCommand;
|
|||
import land.chipmunk.chipmunkmod.modules.ChomeNSBotCommandSuggestions;
|
||||
import land.chipmunk.chipmunkmod.util.BotValidationUtilities;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ChatInputSuggestor;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.widget.TextFieldWidget;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.client.gui.screen.ChatScreen;
|
||||
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.Constant;
|
||||
import org.spongepowered.asm.mixin.injection.Inject;
|
||||
import org.spongepowered.asm.mixin.injection.ModifyConstant;
|
||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||
|
||||
import javax.net.ssl.HttpsURLConnection;
|
||||
|
|
@ -26,49 +23,12 @@ import java.net.URL;
|
|||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(value = net.minecraft.client.gui.screen.ChatScreen.class)
|
||||
public abstract class ChatScreenMixin extends Screen {
|
||||
@Shadow
|
||||
private String originalChatText;
|
||||
|
||||
@Shadow
|
||||
private int messageHistoryIndex;
|
||||
|
||||
@Shadow
|
||||
protected TextFieldWidget chatField;
|
||||
|
||||
@Shadow
|
||||
ChatInputSuggestor chatInputSuggestor;
|
||||
|
||||
@Shadow
|
||||
protected abstract void onChatFieldUpdate(String chatText);
|
||||
|
||||
protected ChatScreenMixin(Text title) {
|
||||
super(title);
|
||||
}
|
||||
|
||||
@Mixin(value = ChatScreen.class)
|
||||
public abstract class ChatScreenMixin {
|
||||
// infinite chat
|
||||
@Inject(method = "init", at = @At("HEAD"), cancellable = true)
|
||||
protected void init(CallbackInfo ci) {
|
||||
final MinecraftClient client = MinecraftClient.getInstance();
|
||||
|
||||
this.messageHistoryIndex = 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();
|
||||
|
||||
ci.cancel();
|
||||
@ModifyConstant(method = "init", constant = @Constant(intValue = 256))
|
||||
protected int init$maxLength(final int old) {
|
||||
return Integer.MAX_VALUE;
|
||||
}
|
||||
|
||||
@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue