mirror of
https://code.chipmunk.land/ChomeNS/chipmunkmod.git
synced 2025-11-13 21:06:16 +00:00
feat: (re-)add infinite chat
This commit is contained in:
parent
64a87a59d8
commit
e84b975266
1 changed files with 43 additions and 7 deletions
|
|
@ -6,7 +6,10 @@ 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 org.spongepowered.asm.mixin.Mixin;
|
||||
import org.spongepowered.asm.mixin.Shadow;
|
||||
|
|
@ -17,17 +20,50 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||
import javax.net.ssl.HttpsURLConnection;
|
||||
import java.io.IOException;
|
||||
import java.io.OutputStream;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@Mixin(value = net.minecraft.client.gui.screen.ChatScreen.class)
|
||||
public class ChatScreenMixin extends Screen {
|
||||
public abstract class ChatScreenMixin extends Screen {
|
||||
@Shadow private String originalChatText;
|
||||
|
||||
public ChatScreenMixin(String originalChatText) {
|
||||
super(Text.translatable("chat_screen.title"));
|
||||
this.originalChatText = 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);
|
||||
}
|
||||
|
||||
// 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();
|
||||
}
|
||||
|
||||
@Inject(method = "sendMessage", at = @At("HEAD"), cancellable = true)
|
||||
|
|
@ -41,7 +77,7 @@ public class ChatScreenMixin extends Screen {
|
|||
if (ChipmunkMod.CONFIG.bots.testbot.webhookUrl != null && chatText.startsWith(ChipmunkMod.CONFIG.bots.testbot.prefix)) {
|
||||
ChipmunkMod.executorService.submit(() -> {
|
||||
try {
|
||||
final URL url = new URL(ChipmunkMod.CONFIG.bots.testbot.webhookUrl);
|
||||
final URL url = new URI(ChipmunkMod.CONFIG.bots.testbot.webhookUrl).toURL();
|
||||
|
||||
final HttpsURLConnection connection = (HttpsURLConnection) url.openConnection();
|
||||
connection.addRequestProperty("Content-Type", "application/json");
|
||||
|
|
@ -61,7 +97,7 @@ public class ChatScreenMixin extends Screen {
|
|||
|
||||
connection.getInputStream().close();
|
||||
connection.disconnect();
|
||||
} catch (IOException e) {
|
||||
} catch (IOException | URISyntaxException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
});
|
||||
|
|
@ -98,7 +134,7 @@ public class ChatScreenMixin extends Screen {
|
|||
}
|
||||
}
|
||||
|
||||
if (client == null) return;
|
||||
if (client.player == null) return;
|
||||
|
||||
if (chatText.startsWith("/")) {
|
||||
client.player.networkHandler.sendChatCommand(chatText.substring(1));
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue