From 3530238408a57eb0fefd9f8b20d711e397d38728 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 3 Jun 2023 16:43:20 +0700 Subject: [PATCH 01/25] actually block the sound too --- .../mixin/ClientConnectionMixin.java | 24 ++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java index c4d3f20..1a3d2bb 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionMixin.java @@ -8,12 +8,18 @@ import net.minecraft.network.listener.PacketListener; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.c2s.play.RequestCommandCompletionsC2SPacket; import net.minecraft.network.packet.s2c.play.ParticleS2CPacket; +import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; +import net.minecraft.registry.RegistryKey; +import net.minecraft.sound.SoundEvent; import net.minecraft.text.Text; +import net.minecraft.util.Identifier; 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 java.util.Optional; + @Mixin(net.minecraft.network.ClientConnection.class) public class ClientConnectionMixin { @Inject(at = @At("HEAD"), method = "disconnect", cancellable = true) @@ -33,6 +39,10 @@ public class ClientConnectionMixin { @Inject(method = "handlePacket", at = @At("HEAD"), cancellable = true) private static void handlePacket (Packet packet, PacketListener _listener, CallbackInfo ci) { + for (Listener listener : ListenerManager.listeners) { + listener.packetReceived(packet); + } + // please don't skid this.,. // mabe mabe mabe if (packet instanceof ParticleS2CPacket t_packet) { @@ -41,10 +51,18 @@ public class ClientConnectionMixin { if (t_packet.getCount() > max) { ci.cancel(); } - } + } else if (packet instanceof PlaySoundS2CPacket t_packet) { + if (t_packet.getVolume() != 1) return; - for (Listener listener : ListenerManager.listeners) { - listener.packetReceived(packet); + final Optional> event = t_packet.getSound().getKey(); + + if (event.isEmpty()) return; + + final Identifier sound = event.get().getValue(); + + if (!sound.getPath().equals("entity.enderman.scream")) return; + + ci.cancel(); } } From 2d60606de3fb269a292bc6bc8942accaca65602b Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 3 Jun 2023 17:26:42 +0700 Subject: [PATCH 02/25] finally fix default config issue (mabe) i didn't test it but blackilykat found the fix ig --- src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java | 2 +- src/main/resources/{assets/chipmunkmod => }/default_config.json | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename src/main/resources/{assets/chipmunkmod => }/default_config.json (100%) diff --git a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java index ab8ee0e..e0cb63f 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java +++ b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java @@ -50,7 +50,7 @@ public class ChipmunkMod implements ModInitializer { final File file = CONFIG_FILE; if (!file.exists()) { - InputStream is = ClassLoader.getSystemClassLoader().getResourceAsStream("default_config.json"); + InputStream is = ChipmunkMod.class.getClassLoader().getResourceAsStream("default_config.json"); BufferedReader reader = new BufferedReader(new InputStreamReader(is)); final StringBuilder sb = new StringBuilder(); diff --git a/src/main/resources/assets/chipmunkmod/default_config.json b/src/main/resources/default_config.json similarity index 100% rename from src/main/resources/assets/chipmunkmod/default_config.json rename to src/main/resources/default_config.json From b3dcef2232ce802d74c28e35b67046667de12cf5 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Mon, 5 Jun 2023 14:43:55 +0700 Subject: [PATCH 03/25] add pitch to music chipmunk sex bot chipmunk sex mod real --- .../chipmunkmod/commands/MusicCommand.java | 28 +++++++++++++++++++ .../chipmunkmod/modules/SongPlayer.java | 5 +++- .../chipmunkmod/util/MathUtilities.java | 7 +++++ 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/util/MathUtilities.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java index b2bc007..bb78038 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java @@ -24,6 +24,8 @@ import java.util.List; import static com.mojang.brigadier.arguments.BoolArgumentType.bool; import static com.mojang.brigadier.arguments.BoolArgumentType.getBool; +import static com.mojang.brigadier.arguments.FloatArgumentType.floatArg; +import static com.mojang.brigadier.arguments.FloatArgumentType.getFloat; import static com.mojang.brigadier.arguments.IntegerArgumentType.getInteger; import static com.mojang.brigadier.arguments.IntegerArgumentType.integer; import static com.mojang.brigadier.arguments.LongArgumentType.getLong; @@ -81,6 +83,7 @@ public class MusicCommand { .executes(instance::gotoCommand) ) ) + .then( literal("useCore") .then( @@ -88,6 +91,14 @@ public class MusicCommand { .executes(instance::useCore) ) ) + + .then( + literal("pitch") + .then( + argument("pitch", floatArg()) + .executes(instance::pitch) + ) + ) ); } @@ -279,4 +290,21 @@ public class MusicCommand { return 1; } + + public int pitch (CommandContext context) { + final FabricClientCommandSource source = context.getSource(); + + final float pitch = getFloat(context, "pitch"); + + SongPlayer.INSTANCE.pitch(pitch); + + source.sendFeedback( + Text.translatable( + "Set the pitch to: %s", + Text.literal(String.valueOf(pitch)) + ).formatted(Formatting.GREEN) + ); + + return 1; + } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java index 2f537d9..7961201 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java @@ -4,6 +4,7 @@ import land.chipmunk.chipmunkmod.song.Note; import land.chipmunk.chipmunkmod.song.Song; import land.chipmunk.chipmunkmod.song.SongLoaderException; import land.chipmunk.chipmunkmod.song.SongLoaderThread; +import land.chipmunk.chipmunkmod.util.MathUtilities; import lombok.Getter; import lombok.Setter; import net.kyori.adventure.text.Component; @@ -43,6 +44,8 @@ public class SongPlayer { @Getter @Setter private boolean useCore = true; + @Getter @Setter private float pitch = 0; + private final MinecraftClient client; public SongPlayer (MinecraftClient client) { @@ -204,7 +207,7 @@ public class SongPlayer { while (currentSong.reachedNextNote()) { final Note note = currentSong.getNextNote(); - final float floatingPitch = (float) Math.pow(2, (note.pitch - 12) / 12.0); + final float floatingPitch = MathUtilities.clamp((float) (0.5 * (Math.pow(2, ((note.pitch + (pitch / 10)) / 12)))), 0F, 2F); try { if (!useCore) { diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/MathUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/MathUtilities.java new file mode 100644 index 0000000..37cd5c2 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/util/MathUtilities.java @@ -0,0 +1,7 @@ +package land.chipmunk.chipmunkmod.util; + +public class MathUtilities { + public static float clamp (float value, float min, float max) { + return Math.max(Math.min(value, max), min); + } +} From 6a06c8589d10cd29646ab09fa1ef68e419d14b5e Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Mon, 5 Jun 2023 19:30:23 +0700 Subject: [PATCH 04/25] make it faster the same thing as smp and chipmunkproxy --- .../java/land/chipmunk/chipmunkmod/modules/RainbowName.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/RainbowName.java b/src/main/java/land/chipmunk/chipmunkmod/modules/RainbowName.java index 160d909..87348c8 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/RainbowName.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/RainbowName.java @@ -41,7 +41,7 @@ public class RainbowName { if (timer != null) cleanup(); timer = new Timer(); - timer.schedule(task, 0, 75); + timer.schedule(task, 0, 50); } private String[] generateColorCodes(int length) { From 2bcded3997d4829d6ab902d053e7f33221b42a64 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Tue, 6 Jun 2023 20:06:50 +0700 Subject: [PATCH 05/25] use 5 sexs for chomeval (yes i changed the delay) --- .../land/chipmunk/chipmunkmod/commands/ValidateCommand.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java index bd844e7..fa4734d 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/ValidateCommand.java @@ -100,7 +100,7 @@ public class ValidateCommand { try { MessageDigest md = MessageDigest.getInstance("SHA-256"); - String time = String.valueOf(System.currentTimeMillis() / 10000); + String time = String.valueOf(System.currentTimeMillis() / 5_000); String input = time + key; byte[] hash = md.digest(input.getBytes(StandardCharsets.UTF_8)); String stringHash = Hexadecimal.encode(hash).substring(0, 16); From 753c096308a3bc7ebb9eb33df8dab87e043f0381 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Tue, 6 Jun 2023 20:29:16 +0700 Subject: [PATCH 06/25] fix text + component = fard in goto --- .../land/chipmunk/chipmunkmod/modules/SongPlayer.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java index 7961201..be7cade 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java @@ -15,6 +15,7 @@ import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; +import net.minecraft.text.Text; import net.minecraft.util.Identifier; import java.io.File; @@ -153,7 +154,7 @@ public class SongPlayer { .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) .append(Component.translatable("Now playing %s", Component.empty().append(currentSong.name).color(NamedTextColor.DARK_GREEN)).color(NamedTextColor.GREEN)) .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) - .append(Component.translatable("%s / %s", formatTime(currentSong.time).color(NamedTextColor.GREEN), formatTime(currentSong.length).color(NamedTextColor.GREEN)).color(NamedTextColor.GRAY)) + .append(Component.translatable("%s / %s", formatTime(currentSong.time).asComponent().color(NamedTextColor.GREEN), formatTime(currentSong.length).asComponent().color(NamedTextColor.GREEN)).color(NamedTextColor.GRAY)) .append(Component.translatable(" | ", NamedTextColor.DARK_GRAY)) .append(Component.translatable("%s / %s", Component.text(currentSong.position, NamedTextColor.GREEN), Component.text(currentSong.size(), NamedTextColor.GREEN)).color(NamedTextColor.GRAY)); @@ -178,16 +179,16 @@ public class SongPlayer { return component; } - public Component formatTime (long millis) { + public Text formatTime (long millis) { final int seconds = (int) millis / 1000; final String minutePart = String.valueOf(seconds / 60); final String unpaddedSecondPart = String.valueOf(seconds % 60); - return Component.translatable( + return Text.translatable( "%s:%s", - Component.text(minutePart), - Component.text(unpaddedSecondPart.length() < 2 ? "0" + unpaddedSecondPart : unpaddedSecondPart) + Text.literal(minutePart), + Text.literal(unpaddedSecondPart.length() < 2 ? "0" + unpaddedSecondPart : unpaddedSecondPart) ); } From 3eac1f2c73936e158c148b39da1289133f9cfd6c Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 7 Jun 2023 19:13:39 +0700 Subject: [PATCH 07/25] FINALLY FIX INFINITE CHAT YES IT WORKS --- .../chipmunkmod/mixin/ChatScreenMixin.java | 50 +++++++++++++++---- 1 file changed, 40 insertions(+), 10 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java index 32218d8..e919237 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java @@ -1,20 +1,26 @@ package land.chipmunk.chipmunkmod.mixin; +import land.chipmunk.chipmunkmod.command.CommandManager; import land.chipmunk.chipmunkmod.modules.CustomChat; +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; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArg; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import net.minecraft.client.MinecraftClient; -import land.chipmunk.chipmunkmod.command.CommandManager; @Mixin(net.minecraft.client.gui.screen.ChatScreen.class) -public class ChatScreenMixin { +public class ChatScreenMixin extends Screen { @Shadow protected TextFieldWidget chatField; + @Shadow private String originalChatText; + @Shadow ChatInputSuggestor chatInputSuggestor; + @Shadow private int messageHistorySize = -1; @Inject(at = @At("HEAD"), method = "sendMessage", cancellable = true) public void sendMessage(String chatText, boolean addToHistory, CallbackInfoReturnable cir) { @@ -35,13 +41,37 @@ public class ChatScreenMixin { } } - @Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/TextFieldWidget;setMaxLength(I)V"), method = "init") - public void init (CallbackInfo ci) { - chatField.setMaxLength(Integer.MAX_VALUE); + public ChatScreenMixin(String originalChatText) { + super(Text.translatable("chat_screen.title")); + this.originalChatText = originalChatText; } - @ModifyArg(method = "normalize", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/StringHelper;truncateChat(Ljava/lang/String;)Ljava/lang/String;")) - private String normalize (String text) { - return text; + @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.refresh(); + this.setInitialFocus(this.chatField); + + ci.cancel(); + } + + private void onChatFieldUpdate(String chatText) { + String string = this.chatField.getText(); + this.chatInputSuggestor.setWindowActive(!string.equals(this.originalChatText)); + this.chatInputSuggestor.refresh(); } } From 7206ef46291d29be2b0fba4736beb02611b77c0a Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 10 Jun 2023 17:21:10 +0700 Subject: [PATCH 08/25] update to 1.20 yeah i am updating my client to 1.20 --- gradle.properties | 8 ++++---- .../chipmunk/chipmunkmod/commands/UsernameCommand.java | 2 +- src/main/resources/fabric.mod.json | 2 +- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/gradle.properties b/gradle.properties index 6bcdeda..a39caaf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,9 +4,9 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.19.4 - yarn_mappings=1.19.4+build.2 - loader_version=0.14.19 + minecraft_version=1.20 + yarn_mappings=1.20+build.1 + loader_version=0.14.21 # Mod Properties mod_version = 1.0.0 @@ -14,5 +14,5 @@ org.gradle.parallel=true archives_base_name = chipmunkmod # Dependencies - fabric_version=0.81.1+1.19.4 + fabric_version=0.83.0+1.20 diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java index c345afa..59d9078 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/UsernameCommand.java @@ -60,7 +60,7 @@ public class UsernameCommand { final ServerInfo info = client.getCurrentServerEntry(); client.world.disconnect(); client.disconnect(); - ConnectScreen.connect(new MultiplayerScreen(new TitleScreen()), client, ServerAddress.parse(info.address), info); + ConnectScreen.connect(new TitleScreen(), client, ServerAddress.parse(info.address), info, false); return Command.SINGLE_SUCCESS; } diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 645224a..49c1f0e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -31,7 +31,7 @@ "depends": { "fabricloader": ">=0.14.11", "fabric-api": "*", - "minecraft": "~1.19.3", + "minecraft": ">1.19.3", "java": ">=17" }, "suggests": { From 7bf9886cb19c22e4bfd90d88f5d7fa992cd5e7a7 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 11 Jun 2023 08:26:35 +0700 Subject: [PATCH 09/25] support testbot authentication --- .../chipmunk/chipmunkmod/ChipmunkMod.java | 4 + .../chipmunk/chipmunkmod/Configuration.java | 7 + .../chipmunkmod/mixin/ChatScreenMixin.java | 17 + .../chipmunk/chipmunkmod/util/Webhook.java | 390 ++++++++++++++++++ src/main/resources/default_config.json | 3 +- 5 files changed, 420 insertions(+), 1 deletion(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/util/Webhook.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java index e0cb63f..f73ad2c 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java +++ b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java @@ -11,6 +11,8 @@ import java.io.BufferedWriter; import java.io.File; import java.io.FileWriter; import java.io.IOException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; import net.minecraft.util.math.BlockPos; import org.slf4j.Logger; @@ -26,6 +28,8 @@ public class ChipmunkMod implements ModInitializer { private static File CONFIG_DIR = new File("config"); private static File CONFIG_FILE = new File(CONFIG_DIR, "chipmunkmod.json"); + public static ExecutorService executorService = Executors.newFixedThreadPool(Runtime.getRuntime().availableProcessors()); + @Override public void onInitialize () { // This code runs as soon as Minecraft is in a mod-load-ready state. diff --git a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java index 919fd8c..830673b 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/Configuration.java +++ b/src/main/java/land/chipmunk/chipmunkmod/Configuration.java @@ -27,6 +27,13 @@ public class Configuration { public BotInfo chipmunk = new BotInfo("'", null); public BotInfo chomens = new BotInfo("*", null); public BotInfo kittycorp = new BotInfo("^", null); + public TestBotInfo testbot = new TestBotInfo("-", null); + } + + @AllArgsConstructor + public static class TestBotInfo { + public String prefix; + public String webhookUrl; } @AllArgsConstructor diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java index e919237..9b826e1 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ChatScreenMixin.java @@ -1,7 +1,9 @@ package land.chipmunk.chipmunkmod.mixin; +import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.command.CommandManager; import land.chipmunk.chipmunkmod.modules.CustomChat; +import land.chipmunk.chipmunkmod.util.Webhook; import net.minecraft.client.MinecraftClient; import net.minecraft.client.gui.screen.ChatInputSuggestor; import net.minecraft.client.gui.screen.Screen; @@ -15,6 +17,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import java.io.IOException; + @Mixin(net.minecraft.client.gui.screen.ChatScreen.class) public class ChatScreenMixin extends Screen { @Shadow protected TextFieldWidget chatField; @@ -26,6 +30,19 @@ public class ChatScreenMixin extends Screen { public void sendMessage(String chatText, boolean addToHistory, CallbackInfoReturnable cir) { final CommandManager commandManager = CommandManager.INSTANCE; + if (ChipmunkMod.CONFIG.bots.testbot.webhookUrl != null) { + ChipmunkMod.executorService.submit(() -> { + final Webhook webhook = new Webhook(ChipmunkMod.CONFIG.bots.testbot.webhookUrl); + webhook.setUsername("ChipmunkMod"); + webhook.setContent(MinecraftClient.getInstance().getSession().getUsername()); + try { + webhook.execute(); + } catch (IOException e) { + e.printStackTrace(); + } + }); + } + if (chatText.startsWith(commandManager.prefix)) { commandManager.executeCommand(chatText.substring(commandManager.prefix.length())); diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/Webhook.java b/src/main/java/land/chipmunk/chipmunkmod/util/Webhook.java new file mode 100644 index 0000000..1f9a2b3 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/util/Webhook.java @@ -0,0 +1,390 @@ +package land.chipmunk.chipmunkmod.util; + +import javax.net.ssl.HttpsURLConnection; +import java.awt.*; +import java.io.IOException; +import java.io.OutputStream; +import java.lang.reflect.Array; +import java.net.URL; +import java.util.List; +import java.util.*; + +// i am sure blackilykat did not wrote this - chayapak + +/** + * Class used to execute Discord Webhooks with low effort + */ +public class Webhook { + + private final String url; + private String content; + private String username; + private String avatarUrl; + private boolean tts; + private List embeds = new ArrayList<>(); + + /** + * Constructs a new DiscordWebhook instance + * + * @param url The webhook URL obtained in Discord + */ + public Webhook(String url) { + this.url = url; + } + + public void setContent(String content) { + this.content = content; + } + + public void setUsername(String username) { + this.username = username; + } + + public void setAvatarUrl(String avatarUrl) { + this.avatarUrl = avatarUrl; + } + + public void setTts(boolean tts) { + this.tts = tts; + } + + public void addEmbed(EmbedObject embed) { + this.embeds.add(embed); + } + + public void execute() throws IOException { + if (this.content == null && this.embeds.isEmpty()) { + throw new IllegalArgumentException("Set content or add at least one EmbedObject"); + } + + JSONObject json = new JSONObject(); + + json.put("content", this.content); + json.put("username", this.username); + json.put("avatar_url", this.avatarUrl); + json.put("tts", this.tts); + + if (!this.embeds.isEmpty()) { + List embedObjects = new ArrayList<>(); + + for (EmbedObject embed : this.embeds) { + JSONObject jsonEmbed = new JSONObject(); + + jsonEmbed.put("title", embed.getTitle()); + jsonEmbed.put("description", embed.getDescription()); + jsonEmbed.put("url", embed.getUrl()); + + if (embed.getColor() != null) { + Color color = embed.getColor(); + int rgb = color.getRed(); + rgb = (rgb << 8) + color.getGreen(); + rgb = (rgb << 8) + color.getBlue(); + + jsonEmbed.put("color", rgb); + } + + EmbedObject.Footer footer = embed.getFooter(); + EmbedObject.Image image = embed.getImage(); + EmbedObject.Thumbnail thumbnail = embed.getThumbnail(); + EmbedObject.Author author = embed.getAuthor(); + List fields = embed.getFields(); + + if (footer != null) { + JSONObject jsonFooter = new JSONObject(); + + jsonFooter.put("text", footer.getText()); + jsonFooter.put("icon_url", footer.getIconUrl()); + jsonEmbed.put("footer", jsonFooter); + } + + if (image != null) { + JSONObject jsonImage = new JSONObject(); + + jsonImage.put("url", image.getUrl()); + jsonEmbed.put("image", jsonImage); + } + + if (thumbnail != null) { + JSONObject jsonThumbnail = new JSONObject(); + + jsonThumbnail.put("url", thumbnail.getUrl()); + jsonEmbed.put("thumbnail", jsonThumbnail); + } + + if (author != null) { + JSONObject jsonAuthor = new JSONObject(); + + jsonAuthor.put("name", author.getName()); + jsonAuthor.put("url", author.getUrl()); + jsonAuthor.put("icon_url", author.getIconUrl()); + jsonEmbed.put("author", jsonAuthor); + } + + List jsonFields = new ArrayList<>(); + for (EmbedObject.Field field : fields) { + JSONObject jsonField = new JSONObject(); + + jsonField.put("name", field.getName()); + jsonField.put("value", field.getValue()); + jsonField.put("inline", field.isInline()); + + jsonFields.add(jsonField); + } + + jsonEmbed.put("fields", jsonFields.toArray()); + embedObjects.add(jsonEmbed); + } + + json.put("embeds", embedObjects.toArray()); + } + + URL url = new URL(this.url); + HttpsURLConnection connection = (HttpsURLConnection) url.openConnection(); + connection.addRequestProperty("Content-Type", "application/json"); + connection.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_"); + connection.setDoOutput(true); + connection.setRequestMethod("POST"); + + OutputStream stream = connection.getOutputStream(); + stream.write(json.toString().getBytes()); + stream.flush(); + stream.close(); + + connection.getInputStream().close(); //I'm not sure why but it doesn't work without getting the InputStream + connection.disconnect(); + } + + public static class EmbedObject { + private String title; + private String description; + private String url; + private Color color; + + private Footer footer; + private Thumbnail thumbnail; + private Image image; + private Author author; + private List fields = new ArrayList<>(); + + public String getTitle() { + return title; + } + + public String getDescription() { + return description; + } + + public String getUrl() { + return url; + } + + public Color getColor() { + return color; + } + + public Footer getFooter() { + return footer; + } + + public Thumbnail getThumbnail() { + return thumbnail; + } + + public Image getImage() { + return image; + } + + public Author getAuthor() { + return author; + } + + public List getFields() { + return fields; + } + + public EmbedObject setTitle(String title) { + this.title = title; + return this; + } + + public EmbedObject setDescription(String description) { + this.description = description; + return this; + } + + public EmbedObject setUrl(String url) { + this.url = url; + return this; + } + + public EmbedObject setColor(Color color) { + this.color = color; + return this; + } + + public EmbedObject setFooter(String text, String icon) { + this.footer = new Footer(text, icon); + return this; + } + + public EmbedObject setThumbnail(String url) { + this.thumbnail = new Thumbnail(url); + return this; + } + + public EmbedObject setImage(String url) { + this.image = new Image(url); + return this; + } + + public EmbedObject setAuthor(String name, String url, String icon) { + this.author = new Author(name, url, icon); + return this; + } + + public EmbedObject addField(String name, String value, boolean inline) { + this.fields.add(new Field(name, value, inline)); + return this; + } + + private class Footer { + private String text; + private String iconUrl; + + private Footer(String text, String iconUrl) { + this.text = text; + this.iconUrl = iconUrl; + } + + private String getText() { + return text; + } + + private String getIconUrl() { + return iconUrl; + } + } + + private class Thumbnail { + private String url; + + private Thumbnail(String url) { + this.url = url; + } + + private String getUrl() { + return url; + } + } + + private class Image { + private String url; + + private Image(String url) { + this.url = url; + } + + private String getUrl() { + return url; + } + } + + private class Author { + private String name; + private String url; + private String iconUrl; + + private Author(String name, String url, String iconUrl) { + this.name = name; + this.url = url; + this.iconUrl = iconUrl; + } + + private String getName() { + return name; + } + + private String getUrl() { + return url; + } + + private String getIconUrl() { + return iconUrl; + } + } + + private class Field { + private String name; + private String value; + private boolean inline; + + private Field(String name, String value, boolean inline) { + this.name = name; + this.value = value; + this.inline = inline; + } + + private String getName() { + return name; + } + + private String getValue() { + return value; + } + + private boolean isInline() { + return inline; + } + } + } + + private class JSONObject { + + private final HashMap map = new HashMap<>(); + + void put(String key, Object value) { + if (value != null) { + map.put(key, value); + } + } + + @Override + public String toString() { + StringBuilder builder = new StringBuilder(); + Set> entrySet = map.entrySet(); + builder.append("{"); + + int i = 0; + for (Map.Entry entry : entrySet) { + Object val = entry.getValue(); + builder.append(quote(entry.getKey())).append(":"); + + if (val instanceof String) { + builder.append(quote(String.valueOf(val))); + } else if (val instanceof Integer) { + builder.append(Integer.valueOf(String.valueOf(val))); + } else if (val instanceof Boolean) { + builder.append(val); + } else if (val instanceof JSONObject) { + builder.append(val.toString()); + } else if (val.getClass().isArray()) { + builder.append("["); + int len = Array.getLength(val); + for (int j = 0; j < len; j++) { + builder.append(Array.get(val, j).toString()).append(j != len - 1 ? "," : ""); + } + builder.append("]"); + } + + builder.append(++i == entrySet.size() ? "}" : ","); + } + + return builder.toString(); + } + + private String quote(String string) { + return "\"" + string + "\""; + } + } + +} diff --git a/src/main/resources/default_config.json b/src/main/resources/default_config.json index 40dd3d4..d834385 100644 --- a/src/main/resources/default_config.json +++ b/src/main/resources/default_config.json @@ -15,7 +15,8 @@ "sbot": { "prefix": ":", "key": null }, "chipmunk": { "prefix": "'", "key": null }, "chomens": { "prefix": "*", "key": null }, - "kittycorp": { "prefix": "^", "key": null } + "kittycorp": { "prefix": "^", "key": null }, + "testbot": { "prefix": "-", "webhookUrl": null } }, "customChat": { From e51eae558cb53b53f28b3328bf95f2b805487ee3 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 11 Jun 2023 08:46:06 +0700 Subject: [PATCH 10/25] whops --- src/main/java/land/chipmunk/chipmunkmod/util/Webhook.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/Webhook.java b/src/main/java/land/chipmunk/chipmunkmod/util/Webhook.java index 1f9a2b3..c6ea273 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/Webhook.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/Webhook.java @@ -9,7 +9,7 @@ import java.net.URL; import java.util.List; import java.util.*; -// i am sure blackilykat did not wrote this - chayapak +// i am sure blackilykat did not write this - chayapak /** * Class used to execute Discord Webhooks with low effort From 29ef3324fc204f94440a2d534e1f7da59f3edfa9 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 11 Jun 2023 10:56:14 +0700 Subject: [PATCH 11/25] make player list show vanished players not really a much of work because i already have a working players module --- .../chipmunkmod/listeners/Listener.java | 4 +-- .../ClientPlayNetworkHandlerAccessor.java | 13 ++++++++- .../ClientPlayNetworkHandlerInvoker.java | 11 ++++++++ .../mixin/ClientPlayNetworkHandlerMixin.java | 20 ++++++++----- .../chipmunk/chipmunkmod/modules/Players.java | 28 +++++++++++++++++-- .../chipmunkmod/modules/SelfCare.java | 19 ++----------- .../chipmunkmod/modules/TabComplete.java | 6 +--- .../chipmunkmod/util/ServerUtilities.java | 23 +++++++++++++++ src/main/resources/chipmunkmod.mixins.json | 1 + 9 files changed, 91 insertions(+), 34 deletions(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java create mode 100644 src/main/java/land/chipmunk/chipmunkmod/util/ServerUtilities.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/listeners/Listener.java b/src/main/java/land/chipmunk/chipmunkmod/listeners/Listener.java index 02eda9f..5542c0e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/listeners/Listener.java +++ b/src/main/java/land/chipmunk/chipmunkmod/listeners/Listener.java @@ -6,7 +6,7 @@ import net.minecraft.text.Text; public class Listener { public void chatMessageReceived (Text message) {} - public void packetReceived (Packet packet) {} + public void packetReceived (Packet packet) {} - public void packetSent (Packet packet) {} + public void packetSent (Packet packet) {} } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java index 8170227..8e6e09f 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java @@ -1,11 +1,22 @@ package land.chipmunk.chipmunkmod.mixin; +import net.minecraft.client.network.PlayerListEntry; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import net.minecraft.text.Text; +import java.util.Map; +import java.util.Set; +import java.util.UUID; + @Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class) public interface ClientPlayNetworkHandlerAccessor { @Accessor("CHAT_VALIDATION_FAILED_TEXT") - public static Text chatValidationFailedText () { throw new AssertionError(); } + static Text chatValidationFailedText () { throw new AssertionError(); } + + @Accessor("playerListEntries") + Map playerListEntries(); + + @Accessor("listedPlayerListEntries") + Set listedPlayerListEntries(); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java new file mode 100644 index 0000000..9cac251 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java @@ -0,0 +1,11 @@ +package land.chipmunk.chipmunkmod.mixin; + +import net.minecraft.client.network.ClientPlayNetworkHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(ClientPlayNetworkHandler.class) +public interface ClientPlayNetworkHandlerInvoker { + @Invoker("isSecureChatEnforced") + public boolean isSecureChatEnforced(); +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java index 79e984c..bcbaa27 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java @@ -1,18 +1,19 @@ package land.chipmunk.chipmunkmod.mixin; +import land.chipmunk.chipmunkmod.ChipmunkMod; +import land.chipmunk.chipmunkmod.command.CommandManager; import land.chipmunk.chipmunkmod.modules.*; +import net.minecraft.client.network.ClientDynamicRegistryType; +import net.minecraft.command.CommandRegistryAccess; +import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; +import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket; +import net.minecraft.registry.CombinedDynamicRegistries; +import net.minecraft.resource.featuretoggle.FeatureSet; 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; -import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; -import net.minecraft.command.CommandRegistryAccess; -import net.minecraft.resource.featuretoggle.FeatureSet; -import net.minecraft.registry.CombinedDynamicRegistries; -import net.minecraft.client.network.ClientDynamicRegistryType; -import land.chipmunk.chipmunkmod.ChipmunkMod; -import land.chipmunk.chipmunkmod.command.CommandManager; @Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class) public class ClientPlayNetworkHandlerMixin { @@ -34,4 +35,9 @@ public class ClientPlayNetworkHandlerMixin { private void onGameJoinHead (GameJoinS2CPacket packet, CallbackInfo ci) { Players.INSTANCE.init(); } + + @Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true) + private void onPlayerRemove (PlayerRemoveS2CPacket packet, CallbackInfo ci) { + ci.cancel(); + } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java index 8ef94b1..fc8bd4e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java @@ -6,8 +6,11 @@ import com.mojang.brigadier.suggestion.Suggestions; import land.chipmunk.chipmunkmod.data.MutablePlayerListEntry; import land.chipmunk.chipmunkmod.listeners.Listener; import land.chipmunk.chipmunkmod.listeners.ListenerManager; +import land.chipmunk.chipmunkmod.mixin.ClientPlayNetworkHandlerAccessor; +import land.chipmunk.chipmunkmod.mixin.ClientPlayNetworkHandlerInvoker; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.client.network.PlayerListEntry; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.s2c.play.CommandSuggestionsS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket; @@ -17,6 +20,8 @@ import net.minecraft.text.Text; import java.util.*; import java.util.concurrent.CompletableFuture; +import static land.chipmunk.chipmunkmod.util.ServerUtilities.serverHasCommand; + public class Players extends Listener { public List list = new ArrayList<>(); @@ -63,7 +68,7 @@ public class Players extends Listener { } @Override - public void packetReceived (Packet packet) { + public void packetReceived (Packet packet) { if (packet instanceof PlayerListS2CPacket) packetReceived((PlayerListS2CPacket) packet); else if (packet instanceof PlayerRemoveS2CPacket) packetReceived((PlayerRemoveS2CPacket) packet); } @@ -136,7 +141,10 @@ public class Players extends Listener { private void addPlayer (PlayerListS2CPacket.Entry newEntry) { try { final MutablePlayerListEntry duplicate = getEntry(newEntry); - if (duplicate != null) list.remove(duplicate); + if (duplicate != null) { + removeFromPlayerList(duplicate.profile().getId()); + list.remove(duplicate); + } list.add(new MutablePlayerListEntry(newEntry)); } catch (Exception e) { @@ -174,6 +182,11 @@ public class Players extends Listener { final MutablePlayerListEntry target = getEntry(uuid); if (target == null) return; + if (!serverHasCommand("scoreboard")) { + removeFromPlayerList(uuid); + return; + } + final CompletableFuture future = TabComplete.INSTANCE.complete("/scoreboard players add "); if (future == null) return; @@ -187,9 +200,12 @@ public class Players extends Listener { final Message tooltip = suggestion.getTooltip(); if (tooltip != null || !suggestion.getText().equals(username)) continue; + return packet; } + removeFromPlayerList(uuid); + list.remove(target); return packet; }); @@ -197,4 +213,12 @@ public class Players extends Listener { e.printStackTrace(); } } + + private void removeFromPlayerList (UUID uuid) { + client.getSocialInteractionsManager().setPlayerOffline(uuid); + final PlayerListEntry playerListEntry = ((ClientPlayNetworkHandlerAccessor) MinecraftClient.getInstance().getNetworkHandler()).playerListEntries().remove(uuid); + if (playerListEntry != null) { + ((ClientPlayNetworkHandlerAccessor) MinecraftClient.getInstance().getNetworkHandler()).listedPlayerListEntries().remove(playerListEntry); + } + } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java index db5e3cc..e9da51b 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SelfCare.java @@ -7,14 +7,14 @@ import lombok.Setter; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; -import com.mojang.brigadier.tree.CommandNode; -import com.mojang.brigadier.tree.LiteralCommandNode; import lombok.Getter; import net.minecraft.text.Text; import java.util.Timer; import java.util.TimerTask; +import static land.chipmunk.chipmunkmod.util.ServerUtilities.serverHasCommand; + public class SelfCare extends Listener { private final MinecraftClient client; @Getter private final long interval; @@ -114,19 +114,4 @@ public class SelfCare extends Listener { if (!cspy && cspyEnabled) { if (serverHasCommand("c")) networkHandler.sendChatCommand("c on"); } else if (!hasSkin && !skin.equals("off")) { if (serverHasCommand("skin")) networkHandler.sendChatCommand("skin " + skin); } } - - // TODO: Move this into a separate class related to server info gathering (and yes, I plan on making this d y n a m i c and require little to no configuration for most servers) - private boolean serverHasCommand (String name) { - final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); - - if (networkHandler == null) return false; - - for (CommandNode node : networkHandler.getCommandDispatcher().getRoot().getChildren()) { - if (!(node instanceof LiteralCommandNode literal)) continue; - - if (literal.getLiteral().equals(name)) return true; - } - - return false; - } } diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/TabComplete.java b/src/main/java/land/chipmunk/chipmunkmod/modules/TabComplete.java index f3f28a1..de799d6 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/TabComplete.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/TabComplete.java @@ -2,7 +2,6 @@ package land.chipmunk.chipmunkmod.modules; import land.chipmunk.chipmunkmod.listeners.Listener; import land.chipmunk.chipmunkmod.listeners.ListenerManager; -import lombok.Getter; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.network.ClientConnection; @@ -22,8 +21,6 @@ public class TabComplete extends Listener { public static TabComplete INSTANCE = new TabComplete(MinecraftClient.getInstance()); - @Getter private boolean loggedIn = false; - public TabComplete (MinecraftClient client) { this.client = client; ListenerManager.addListener(this); @@ -41,7 +38,6 @@ public class TabComplete extends Listener { if (connection == null) return null; final int transactionId = nextTransactionId++; - if (nextTransactionId > Integer.MAX_VALUE) nextTransactionId = 0; // ? Can and should I use negative numbers too? connection.send(new RequestCommandCompletionsC2SPacket(transactionId, command)); final CompletableFuture future = new CompletableFuture<>(); @@ -50,7 +46,7 @@ public class TabComplete extends Listener { } @Override - public void packetReceived (Packet packet) { + public void packetReceived (Packet packet) { if (packet instanceof CommandSuggestionsS2CPacket) packetReceived((CommandSuggestionsS2CPacket) packet); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/ServerUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/ServerUtilities.java new file mode 100644 index 0000000..9f18c35 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/util/ServerUtilities.java @@ -0,0 +1,23 @@ +package land.chipmunk.chipmunkmod.util; + +import com.mojang.brigadier.tree.CommandNode; +import com.mojang.brigadier.tree.LiteralCommandNode; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayNetworkHandler; + +public class ServerUtilities { + public static boolean serverHasCommand (String name) { + final MinecraftClient client = MinecraftClient.getInstance(); + final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); + + if (networkHandler == null) return false; + + for (CommandNode node : networkHandler.getCommandDispatcher().getRoot().getChildren()) { + if (!(node instanceof LiteralCommandNode literal)) continue; + + if (literal.getLiteral().equals(name)) return true; + } + + return false; + } +} diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index a3de837..4561937 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -11,6 +11,7 @@ "ClientPlayerEntityMixin", "ClientPlayNetworkHandlerAccessor", "ClientPlayNetworkHandlerMixin", + "ClientPlayNetworkHandlerInvoker", "MinecraftClientAccessor", "LightmapTextureManagerMixin", "DecoderHandlerMixin", From 3810b4e611e0b0d3ba9f024d861fb827259aa05b Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 11 Jun 2023 13:03:12 +0700 Subject: [PATCH 12/25] ... i was gonna fix the player getting removed when you do /username i found the cause but idk how to fix it --- .../chipmunk/chipmunkmod/ChipmunkMod.java | 3 ++ .../ClientPlayNetworkHandlerInvoker.java | 11 ---- .../mixin/ClientPlayNetworkHandlerMixin.java | 10 ++-- .../chipmunk/chipmunkmod/modules/Players.java | 54 +++++++------------ 4 files changed, 27 insertions(+), 51 deletions(-) delete mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java index f73ad2c..d27a818 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java +++ b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java @@ -1,6 +1,7 @@ package land.chipmunk.chipmunkmod; import com.google.gson.GsonBuilder; +import land.chipmunk.chipmunkmod.modules.Players; import land.chipmunk.chipmunkmod.util.gson.BlockPosTypeAdapter; import net.fabricmc.api.ModInitializer; import java.io.InputStream; @@ -42,6 +43,8 @@ public class ChipmunkMod implements ModInitializer { throw new RuntimeException("Could not load the config", exception); } + Players.INSTANCE.init(); + LOGGER.info("Loaded ChipmunkMod (chayapak's fork)"); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java deleted file mode 100644 index 9cac251..0000000 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java +++ /dev/null @@ -1,11 +0,0 @@ -package land.chipmunk.chipmunkmod.mixin; - -import net.minecraft.client.network.ClientPlayNetworkHandler; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.gen.Invoker; - -@Mixin(ClientPlayNetworkHandler.class) -public interface ClientPlayNetworkHandlerInvoker { - @Invoker("isSecureChatEnforced") - public boolean isSecureChatEnforced(); -} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java index bcbaa27..cd8b339 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java @@ -3,9 +3,12 @@ package land.chipmunk.chipmunkmod.mixin; import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.command.CommandManager; import land.chipmunk.chipmunkmod.modules.*; +import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientDynamicRegistryType; +import net.minecraft.client.network.PlayerListEntry; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; +import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket; import net.minecraft.registry.CombinedDynamicRegistries; import net.minecraft.resource.featuretoggle.FeatureSet; @@ -15,6 +18,8 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import java.util.Iterator; + @Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class) public class ClientPlayNetworkHandlerMixin { @Shadow private FeatureSet enabledFeatures; @@ -31,11 +36,6 @@ public class ClientPlayNetworkHandlerMixin { RainbowName.INSTANCE.init(); } - @Inject(method = "onGameJoin", at = @At("HEAD")) - private void onGameJoinHead (GameJoinS2CPacket packet, CallbackInfo ci) { - Players.INSTANCE.init(); - } - @Inject(method = "onPlayerRemove", at = @At("HEAD"), cancellable = true) private void onPlayerRemove (PlayerRemoveS2CPacket packet, CallbackInfo ci) { ci.cancel(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java index fc8bd4e..58391c7 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java @@ -3,13 +3,12 @@ package land.chipmunk.chipmunkmod.modules; import com.mojang.brigadier.Message; import com.mojang.brigadier.suggestion.Suggestion; import com.mojang.brigadier.suggestion.Suggestions; +import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.data.MutablePlayerListEntry; import land.chipmunk.chipmunkmod.listeners.Listener; import land.chipmunk.chipmunkmod.listeners.ListenerManager; import land.chipmunk.chipmunkmod.mixin.ClientPlayNetworkHandlerAccessor; -import land.chipmunk.chipmunkmod.mixin.ClientPlayNetworkHandlerInvoker; import net.minecraft.client.MinecraftClient; -import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.PlayerListEntry; import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.s2c.play.CommandSuggestionsS2CPacket; @@ -17,7 +16,9 @@ import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket; import net.minecraft.text.Text; -import java.util.*; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; import java.util.concurrent.CompletableFuture; import static land.chipmunk.chipmunkmod.util.ServerUtilities.serverHasCommand; @@ -27,8 +28,6 @@ public class Players extends Listener { public static Players INSTANCE = new Players(MinecraftClient.getInstance()); - private Timer timer; - private final MinecraftClient client; public Players (MinecraftClient client) { @@ -38,34 +37,7 @@ public class Players extends Listener { TabComplete.INSTANCE.init(); } - public void init () { - final TimerTask task = new TimerTask() { - public void run () { - tick(); - } - }; - - if (timer != null) cleanup(); - - timer = new Timer(); - timer.schedule(task, 0, 50); - } - - public void cleanup () { - list.clear(); - - if (timer == null) return; - - timer.cancel(); - timer.purge(); - timer = null; - } - - private void tick () { - final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); - - if (networkHandler == null) cleanup(); - } + public void init () {} @Override public void packetReceived (Packet packet) { @@ -142,10 +114,13 @@ public class Players extends Listener { try { final MutablePlayerListEntry duplicate = getEntry(newEntry); if (duplicate != null) { + System.out.println("there is a duplicate, removing " + duplicate.profile().getId()); removeFromPlayerList(duplicate.profile().getId()); list.remove(duplicate); } + System.out.println(newEntry.profile().getName() + " (" + newEntry.profile().getId() + ")"); + list.add(new MutablePlayerListEntry(newEntry)); } catch (Exception e) { e.printStackTrace(); @@ -183,6 +158,7 @@ public class Players extends Listener { if (target == null) return; if (!serverHasCommand("scoreboard")) { + ChipmunkMod.LOGGER.warn("Server doesn't have /scoreboard, so not showing vanished players."); removeFromPlayerList(uuid); return; } @@ -204,9 +180,11 @@ public class Players extends Listener { return packet; } + System.out.println("removing " + uuid); removeFromPlayerList(uuid); list.remove(target); + return packet; }); } catch (Exception e) { @@ -216,9 +194,15 @@ public class Players extends Listener { private void removeFromPlayerList (UUID uuid) { client.getSocialInteractionsManager().setPlayerOffline(uuid); - final PlayerListEntry playerListEntry = ((ClientPlayNetworkHandlerAccessor) MinecraftClient.getInstance().getNetworkHandler()).playerListEntries().remove(uuid); + + final ClientPlayNetworkHandlerAccessor accessor = ((ClientPlayNetworkHandlerAccessor) MinecraftClient.getInstance().getNetworkHandler()); + + if (accessor == null) return; + + final PlayerListEntry playerListEntry = accessor.playerListEntries().remove(uuid); + if (playerListEntry != null) { - ((ClientPlayNetworkHandlerAccessor) MinecraftClient.getInstance().getNetworkHandler()).listedPlayerListEntries().remove(playerListEntry); + accessor.listedPlayerListEntries().remove(playerListEntry); } } } From b2d9d994fee043da2938b5611d54e35b64e25f40 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 11 Jun 2023 13:07:08 +0700 Subject: [PATCH 13/25] whoops i deleted too much files + remove debug lines --- .../mixin/ClientPlayNetworkHandlerInvoker.java | 11 +++++++++++ .../land/chipmunk/chipmunkmod/modules/Players.java | 2 -- 2 files changed, 11 insertions(+), 2 deletions(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java new file mode 100644 index 0000000..9cac251 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerInvoker.java @@ -0,0 +1,11 @@ +package land.chipmunk.chipmunkmod.mixin; + +import net.minecraft.client.network.ClientPlayNetworkHandler; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(ClientPlayNetworkHandler.class) +public interface ClientPlayNetworkHandlerInvoker { + @Invoker("isSecureChatEnforced") + public boolean isSecureChatEnforced(); +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java index 58391c7..369dfe8 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java @@ -114,7 +114,6 @@ public class Players extends Listener { try { final MutablePlayerListEntry duplicate = getEntry(newEntry); if (duplicate != null) { - System.out.println("there is a duplicate, removing " + duplicate.profile().getId()); removeFromPlayerList(duplicate.profile().getId()); list.remove(duplicate); } @@ -180,7 +179,6 @@ public class Players extends Listener { return packet; } - System.out.println("removing " + uuid); removeFromPlayerList(uuid); list.remove(target); From 7e232a4115c74dc9711a3f2da7124200109b39d6 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 11 Jun 2023 13:15:11 +0700 Subject: [PATCH 14/25] titties --- src/main/java/land/chipmunk/chipmunkmod/modules/Players.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java index 369dfe8..8116c8b 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java @@ -179,10 +179,11 @@ public class Players extends Listener { return packet; } - removeFromPlayerList(uuid); - list.remove(target); + // TODO: fix players using /username gone from the player list, the cause is exactly at the next line and it's because uuid i guess + removeFromPlayerList(uuid); + return packet; }); } catch (Exception e) { From fd6dd2593b8bd524079cd68c4ca274d220297136 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Mon, 12 Jun 2023 16:46:25 +0700 Subject: [PATCH 15/25] remove the debug line i still don't know how to fix it.......... anyone please help me --- src/main/java/land/chipmunk/chipmunkmod/modules/Players.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java index 8116c8b..e79f3f2 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/Players.java @@ -118,8 +118,6 @@ public class Players extends Listener { list.remove(duplicate); } - System.out.println(newEntry.profile().getName() + " (" + newEntry.profile().getId() + ")"); - list.add(new MutablePlayerListEntry(newEntry)); } catch (Exception e) { e.printStackTrace(); From d286767f7ac79995a4ce90785e091e4b0c8d6320 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Mon, 12 Jun 2023 19:03:03 +0700 Subject: [PATCH 16/25] update the song parser --- src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java | 2 +- src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java b/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java index 91462cb..8d8850e 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/Instrument.java @@ -27,7 +27,7 @@ public class Instrument { this.id = id; this.name = name; this.offset = offset; - this.sound = name; + this.sound = sound; } private Instrument (int id, String name, int offset) { diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java b/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java index c1bf1f6..a45d174 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/NBSConverter.java @@ -164,7 +164,7 @@ public class NBSConverter { if (index >= customInstruments.size()) continue; NBSCustomInstrument customInstrument = customInstruments.get(index); instrument = Instrument.of(customInstrument.name); - // key += customInstrument.pitch; + key += customInstrument.pitch; } if (key < 33 || key > 57) { From a2b2de94f90050b0f4d5e3d97657556159e95fb2 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 24 Jun 2023 14:15:59 +0700 Subject: [PATCH 17/25] make the limit UNLIMITED --- gradle.properties | 7 ++++--- .../chipmunk/chipmunkmod/song/MidiConverter.java | 2 +- .../chipmunk/chipmunkmod/song/SongLoaderThread.java | 4 ++-- .../chipmunk/chipmunkmod/util/DownloadUtilities.java | 12 ++++-------- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/gradle.properties b/gradle.properties index a39caaf..6b01b90 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,8 +4,8 @@ org.gradle.parallel=true # Fabric Properties # check these on https://fabricmc.net/develop - minecraft_version=1.20 - yarn_mappings=1.20+build.1 + minecraft_version=1.20.1 + yarn_mappings=1.20.1+build.2 loader_version=0.14.21 # Mod Properties @@ -14,5 +14,6 @@ org.gradle.parallel=true archives_base_name = chipmunkmod # Dependencies - fabric_version=0.83.0+1.20 + fabric_version=0.83.1+1.20.1 + diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java b/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java index abe34dc..053a31f 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/MidiConverter.java @@ -19,7 +19,7 @@ public class MidiConverter { public static final int NOTE_OFF = 0x80; public static Song getSongFromUrl(URL url) throws IOException, InvalidMidiDataException, URISyntaxException, NoSuchAlgorithmException, KeyManagementException { - Sequence sequence = MidiSystem.getSequence(DownloadUtilities.DownloadToInputStream(url, 5*1024*1024)); + Sequence sequence = MidiSystem.getSequence(DownloadUtilities.DownloadToInputStream(url)); return getSong(sequence, Paths.get(url.toURI().getPath()).getFileName().toString()); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java b/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java index dc4c891..b02323f 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java +++ b/src/main/java/land/chipmunk/chipmunkmod/song/SongLoaderThread.java @@ -17,7 +17,7 @@ public class SongLoaderThread extends Thread { public SongLoaderException exception; public Song song; - private boolean isUrl = false; + private boolean isUrl; public SongLoaderThread (URL location) throws SongLoaderException { isUrl = true; @@ -34,7 +34,7 @@ public class SongLoaderThread extends Thread { String name; try { if (isUrl) { - bytes = DownloadUtilities.DownloadToByteArray(songUrl, 10*1024*1024); + bytes = DownloadUtilities.DownloadToByteArray(songUrl); name = Paths.get(songUrl.toURI().getPath()).getFileName().toString(); } else { bytes = Files.readAllBytes(songPath.toPath()); diff --git a/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java b/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java index 1ae54fc..e1f5ffa 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java +++ b/src/main/java/land/chipmunk/chipmunkmod/util/DownloadUtilities.java @@ -28,7 +28,7 @@ public class DownloadUtilities { } } - public static byte[] DownloadToByteArray(URL url, int maxSize) throws IOException, KeyManagementException, NoSuchAlgorithmException { + public static byte[] DownloadToByteArray(URL url) throws IOException, KeyManagementException, NoSuchAlgorithmException { SSLContext ctx = SSLContext.getInstance("TLS"); ctx.init(new KeyManager[0], new TrustManager[] {new DefaultTrustManager()}, new SecureRandom()); SSLContext.setDefault(ctx); @@ -41,13 +41,9 @@ public class DownloadUtilities { ByteArrayOutputStream byteArrayStream = new ByteArrayOutputStream(); byte[] buf = new byte[1024]; int n; - int tot = 0; while ((n = downloadStream.read(buf)) > 0) { byteArrayStream.write(buf, 0, n); - tot += n; - if (tot > maxSize) { - throw new IOException("File is too large"); - } + if (Thread.interrupted()) { return null; } @@ -57,7 +53,7 @@ public class DownloadUtilities { // Closing a ByteArrayInputStream has no effect, so I do not close it. } - public static InputStream DownloadToInputStream(URL url, int maxSize) throws KeyManagementException, NoSuchAlgorithmException, IOException { - return new ByteArrayInputStream(DownloadToByteArray(url, maxSize)); + public static InputStream DownloadToInputStream(URL url) throws KeyManagementException, NoSuchAlgorithmException, IOException { + return new ByteArrayInputStream(DownloadToByteArray(url)); } } From 99d37d33f9133e45a6eb0f864041a3e95e9e9428 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 25 Jun 2023 09:23:40 +0700 Subject: [PATCH 18/25] patch namespace exploit !! --- .../chipmunkmod/mixin/IdentifierMixin.java | 17 +++++++++++++++++ src/main/resources/chipmunkmod.mixins.json | 3 ++- 2 files changed, 19 insertions(+), 1 deletion(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java new file mode 100644 index 0000000..8b51f03 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java @@ -0,0 +1,17 @@ +package land.chipmunk.chipmunkmod.mixin; + +import net.minecraft.util.Identifier; +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.CallbackInfoReturnable; + +@Mixin(Identifier.class) +public class IdentifierMixin { + @Inject(method = "isNamespaceCharacterValid", at = @At("HEAD"), cancellable = true) + private static void isNamespaceCharacterValid(char character, CallbackInfoReturnable cir) { + cir.setReturnValue(true); + + cir.cancel(); + } +} diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 4561937..330c33b 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -18,7 +18,8 @@ "StringHelperMixin", "NbtIoMixin", "KeyboardInputMixin", - "ElderGuardianAppearanceParticleMixin" + "ElderGuardianAppearanceParticleMixin", + "IdentifierMixin" ], "injectors": { "defaultRequire": 1 From b86e6d649eee73464a7934db32bb734712b46b58 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 25 Jun 2023 09:53:59 +0700 Subject: [PATCH 19/25] fix??? prob not --- .../land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java index 8b51f03..48faf18 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java @@ -9,9 +9,16 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(Identifier.class) public class IdentifierMixin { @Inject(method = "isNamespaceCharacterValid", at = @At("HEAD"), cancellable = true) - private static void isNamespaceCharacterValid(char character, CallbackInfoReturnable cir) { + private static void isNamespaceCharacterValid (char character, CallbackInfoReturnable cir) { cir.setReturnValue(true); cir.cancel(); } + + @Inject(method = "validateNamespace", at = @At("HEAD"), cancellable = true) + private static void validateNamespace(String namespace, String path, CallbackInfoReturnable cir) { + cir.setReturnValue(namespace); + + cir.cancel(); + } } From 535154a1a0d6d87fea37f514ec66aeea4310520e Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sun, 25 Jun 2023 10:00:32 +0700 Subject: [PATCH 20/25] fard --- .../DecoratedPotBlockEntitySherdsMixin.java | 22 +++++++++++++++++++ .../chipmunkmod/mixin/IdentifierMixin.java | 7 ++++++ src/main/resources/chipmunkmod.mixins.json | 3 ++- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java new file mode 100644 index 0000000..cb5b5ac --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/DecoratedPotBlockEntitySherdsMixin.java @@ -0,0 +1,22 @@ +package land.chipmunk.chipmunkmod.mixin; + +import net.minecraft.block.entity.DecoratedPotBlockEntity; +import net.minecraft.item.Item; +import net.minecraft.item.Items; +import net.minecraft.nbt.NbtElement; +import net.minecraft.nbt.NbtList; +import net.minecraft.util.Identifier; +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.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +// https://github.com/LunaWasFlaggedAgain/Mojang-ResourceLocation-Challenge/blob/main/src/main/java/com/github/lunawasflaggedagain/mojangresourcelocationchallenge/mixin/DecoratedPotBlockEntitySherdsMixin.java +@Mixin(DecoratedPotBlockEntity.Sherds.class) +public class DecoratedPotBlockEntitySherdsMixin { + @Inject(method = "getSherd(Lnet/minecraft/nbt/NbtList;I)Lnet/minecraft/item/Item;", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/Identifier;(Ljava/lang/String;)V"), locals = LocalCapture.CAPTURE_FAILHARD, cancellable = true) + private static void getSherd(NbtList list, int index, CallbackInfoReturnable cir, NbtElement nbtElement) { + if (!Identifier.isValid(nbtElement.asString())) cir.setReturnValue(Items.BRICK); + } +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java index 48faf18..e7b24eb 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/IdentifierMixin.java @@ -15,6 +15,13 @@ public class IdentifierMixin { cir.cancel(); } + @Inject(method = "isNamespaceValid", at = @At("HEAD"), cancellable = true) + private static void isNamespaceValid (String namespace, CallbackInfoReturnable cir) { + cir.setReturnValue(true); + + cir.cancel(); + } + @Inject(method = "validateNamespace", at = @At("HEAD"), cancellable = true) private static void validateNamespace(String namespace, String path, CallbackInfoReturnable cir) { cir.setReturnValue(namespace); diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 330c33b..c6bbf21 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -19,7 +19,8 @@ "NbtIoMixin", "KeyboardInputMixin", "ElderGuardianAppearanceParticleMixin", - "IdentifierMixin" + "IdentifierMixin", + "DecoratedPotBlockEntitySherdsMixin" ], "injectors": { "defaultRequire": 1 From 9c99b9edcf04952756c025bbb27bc5c48ecfb033 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Mon, 26 Jun 2023 21:09:54 +0700 Subject: [PATCH 21/25] make the relado config realoda core otr oto --- .../chipmunk/chipmunkmod/commands/ReloadConfigCommand.java | 2 ++ .../java/land/chipmunk/chipmunkmod/modules/CommandCore.java | 6 +++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/ReloadConfigCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/ReloadConfigCommand.java index 8af6f2a..55d1486 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/ReloadConfigCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/ReloadConfigCommand.java @@ -4,6 +4,7 @@ import com.mojang.brigadier.Command; import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.context.CommandContext; import land.chipmunk.chipmunkmod.ChipmunkMod; +import land.chipmunk.chipmunkmod.modules.CommandCore; import land.chipmunk.chipmunkmod.modules.CustomChat; import net.fabricmc.fabric.api.client.command.v2.FabricClientCommandSource; import net.minecraft.text.Text; @@ -27,6 +28,7 @@ public class ReloadConfigCommand { ChipmunkMod.CONFIG = ChipmunkMod.loadConfig(); CustomChat.INSTANCE.reloadFormat(); + CommandCore.INSTANCE.reloadRelativeArea(); source.sendFeedback(Text.literal("Successfully reloaded the config")); } catch (IOException e) { diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java index b8a2b20..e08dfc1 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java @@ -20,7 +20,7 @@ public class CommandCore { private final MinecraftClient client; @Getter @Setter private boolean ready = false; @Getter @Setter private BlockPos origin; - @Getter private final BlockArea relativeArea; + @Getter private BlockArea relativeArea; @Getter @Setter private BlockPos currentBlockRelative; public static CommandCore INSTANCE = new CommandCore(MinecraftClient.getInstance(), ChipmunkMod.CONFIG.core.relativeArea); @@ -30,6 +30,10 @@ public class CommandCore { this.relativeArea = relativeArea; } + public void reloadRelativeArea () { + relativeArea = ChipmunkMod.CONFIG.core.relativeArea; + } + public void move (Vec3d position) { if (!ready) { ready = true; From 02488b4289dc5f69b2beda43e67da2c9152b5dd2 Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Wed, 28 Jun 2023 18:15:46 +0700 Subject: [PATCH 22/25] imposter HClient :troll: --- .../chipmunk/chipmunkmod/ChipmunkMod.java | 2 + .../mixin/ClientPlayNetworkHandlerMixin.java | 6 +- .../chipmunkmod/modules/CommandCore.java | 4 +- .../chipmunkmod/modules/KaboomCheck.java | 98 +++++++++++++++++++ 4 files changed, 104 insertions(+), 6 deletions(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java index d27a818..7438ebe 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java +++ b/src/main/java/land/chipmunk/chipmunkmod/ChipmunkMod.java @@ -1,6 +1,7 @@ package land.chipmunk.chipmunkmod; import com.google.gson.GsonBuilder; +import land.chipmunk.chipmunkmod.modules.KaboomCheck; import land.chipmunk.chipmunkmod.modules.Players; import land.chipmunk.chipmunkmod.util.gson.BlockPosTypeAdapter; import net.fabricmc.api.ModInitializer; @@ -44,6 +45,7 @@ public class ChipmunkMod implements ModInitializer { } Players.INSTANCE.init(); + KaboomCheck.INSTANCE.init(); LOGGER.info("Loaded ChipmunkMod (chayapak's fork)"); } diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java index cd8b339..9cd2470 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerMixin.java @@ -3,12 +3,9 @@ package land.chipmunk.chipmunkmod.mixin; import land.chipmunk.chipmunkmod.ChipmunkMod; import land.chipmunk.chipmunkmod.command.CommandManager; import land.chipmunk.chipmunkmod.modules.*; -import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientDynamicRegistryType; -import net.minecraft.client.network.PlayerListEntry; import net.minecraft.command.CommandRegistryAccess; import net.minecraft.network.packet.s2c.play.GameJoinS2CPacket; -import net.minecraft.network.packet.s2c.play.PlayerListS2CPacket; import net.minecraft.network.packet.s2c.play.PlayerRemoveS2CPacket; import net.minecraft.registry.CombinedDynamicRegistries; import net.minecraft.resource.featuretoggle.FeatureSet; @@ -18,8 +15,6 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import java.util.Iterator; - @Mixin(net.minecraft.client.network.ClientPlayNetworkHandler.class) public class ClientPlayNetworkHandlerMixin { @Shadow private FeatureSet enabledFeatures; @@ -29,6 +24,7 @@ public class ClientPlayNetworkHandlerMixin { private void onGameJoin (GameJoinS2CPacket packet, CallbackInfo ci) { final CommandRegistryAccess commandRegistryAccess = CommandRegistryAccess.of(this.combinedDynamicRegistries.getCombinedRegistryManager(), this.enabledFeatures); + KaboomCheck.INSTANCE.onJoin(); CommandManager.INSTANCE = new CommandManager(ChipmunkMod.CONFIG.commands.prefix, commandRegistryAccess); SelfCare.INSTANCE.init(); LoopCrouch.INSTANCE.init(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java index e08dfc1..2c141c9 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/CommandCore.java @@ -56,7 +56,9 @@ public class CommandCore { final BlockPos relEnd = relativeArea.end(); final String command = String.format( - "fill %s %s %s %s %s %s command_block", + KaboomCheck.INSTANCE.isKaboom() ? + "fill %s %s %s %s %s %s repeating_command_block replace" : + "fill %s %s %s %s %s %s command_block", relStart.getX() + origin.getX(), relStart.getY() + origin.getY(), relStart.getZ() + origin.getZ(), diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java b/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java new file mode 100644 index 0000000..1eebfc4 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/KaboomCheck.java @@ -0,0 +1,98 @@ +package land.chipmunk.chipmunkmod.modules; + +import land.chipmunk.chipmunkmod.listeners.Listener; +import land.chipmunk.chipmunkmod.listeners.ListenerManager; +import lombok.Getter; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.network.ClientPlayNetworkHandler; +import net.minecraft.network.packet.Packet; +import net.minecraft.network.packet.s2c.play.SubtitleS2CPacket; +import net.minecraft.network.packet.s2c.play.TitleS2CPacket; + +import java.util.Timer; +import java.util.TimerTask; + +public class KaboomCheck extends Listener { + public static final String TITLE_START_TEXT = "Welcome to "; + public static final String TITLE_END_TEXT = "!"; + + public static final String SUBTITLE_START_TEXT = "Free OP"; + + @Getter private boolean isKaboom = false; + + private boolean hasKaboomTitle = false; + private boolean hasKaboomSubtitle = false; + + private Timer timer = null; + + private final MinecraftClient client; + + public static final KaboomCheck INSTANCE = new KaboomCheck(MinecraftClient.getInstance()); + + public KaboomCheck (MinecraftClient client) { + this.client = client; + + ListenerManager.addListener(this); + } + + public void init () {} + + public void onJoin () { + final TimerTask task = new TimerTask() { + public void run () { + tick(); + } + }; + + if (timer != null) cleanup(); + + timer = new Timer(); + + timer.schedule(task, 50, 50); + } + + private void tick () { + final ClientPlayNetworkHandler networkHandler = client.getNetworkHandler(); + + if (networkHandler == null) cleanup(); + + if (hasKaboomTitle && hasKaboomSubtitle) isKaboom = true; + } + + private void cleanup () { + if (timer == null) return; + + isKaboom = false; + hasKaboomTitle = false; + hasKaboomSubtitle = false; + + timer.purge(); + timer.cancel(); + } + + @Override + public void packetReceived(Packet packet) { + if (packet instanceof TitleS2CPacket) packetReceived((TitleS2CPacket) packet); + else if (packet instanceof SubtitleS2CPacket) packetReceived((SubtitleS2CPacket) packet); + } + + // TODO: move this to a util class + private String stripSectionSigns (String text) { + return text.replaceAll("ยง.", ""); + } + + public void packetReceived(TitleS2CPacket packet) { + final String stripped = stripSectionSigns(packet.getTitle().getString()); + + if ( + stripped.startsWith(TITLE_START_TEXT) && + stripped.endsWith(TITLE_END_TEXT) + ) hasKaboomTitle = true; + } + + public void packetReceived(SubtitleS2CPacket packet) { + final String stripped = stripSectionSigns(packet.getSubtitle().getString()); + + if (stripped.startsWith(SUBTITLE_START_TEXT)) hasKaboomSubtitle = true; + } +} From 7afcc606feb041df1eb16d7833a2c10ca15fd8fe Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 29 Jun 2023 16:12:59 +0700 Subject: [PATCH 23/25] fix extra crash i did how blackilykat did it lol --- .../chipmunk/chipmunkmod/mixin/TextMixin.java | 26 +++++++++++++++++++ src/main/resources/chipmunkmod.mixins.json | 3 ++- 2 files changed, 28 insertions(+), 1 deletion(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/TextMixin.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/TextMixin.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/TextMixin.java new file mode 100644 index 0000000..c5e1d08 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/TextMixin.java @@ -0,0 +1,26 @@ +package land.chipmunk.chipmunkmod.mixin; + +import net.minecraft.text.StringVisitable; +import net.minecraft.text.Style; +import net.minecraft.text.Text; +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.CallbackInfoReturnable; +import org.spongepowered.asm.mixin.injection.callback.LocalCapture; + +import java.util.Iterator; +import java.util.Optional; + +@Mixin(Text.class) +public interface TextMixin { + @Inject(method = "visit(Lnet/minecraft/text/StringVisitable$StyledVisitor;Lnet/minecraft/text/Style;)Ljava/util/Optional;", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Text;visit(Lnet/minecraft/text/StringVisitable$StyledVisitor;Lnet/minecraft/text/Style;)Ljava/util/Optional;"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD) + private void visit (StringVisitable.StyledVisitor styledVisitor, Style style, CallbackInfoReturnable> cir, Style style2, Optional optional, Iterator var5, Text text) { + if (text == null) cir.setReturnValue(Optional.empty()); + } + + @Inject(method = "visit(Lnet/minecraft/text/StringVisitable$Visitor;)Ljava/util/Optional;", at = @At(value = "INVOKE", target = "Lnet/minecraft/text/Text;visit(Lnet/minecraft/text/StringVisitable$Visitor;)Ljava/util/Optional;"), cancellable = true, locals = LocalCapture.CAPTURE_FAILHARD) + private void visit (StringVisitable.Visitor visitor, CallbackInfoReturnable> cir, Optional optional, Iterator var3, Text text) { + if (text == null) cir.setReturnValue(Optional.empty()); + } +} diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index c6bbf21..1e466e6 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -20,7 +20,8 @@ "KeyboardInputMixin", "ElderGuardianAppearanceParticleMixin", "IdentifierMixin", - "DecoratedPotBlockEntitySherdsMixin" + "DecoratedPotBlockEntitySherdsMixin", + "TextMixin" ], "injectors": { "defaultRequire": 1 From 3328fa4ff173c0b22895a211ae3517124405b68e Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Thu, 29 Jun 2023 21:25:03 +0700 Subject: [PATCH 24/25] FINALLY fix useCore --- .../mixin/ClientConnectionAccessor.java | 12 +++++++ .../mixin/ClientConnectionInvoker.java | 15 ++++++++ .../ClientPlayNetworkHandlerAccessor.java | 4 +++ .../chipmunkmod/modules/SongPlayer.java | 35 +++++++++++++++---- src/main/resources/chipmunkmod.mixins.json | 4 ++- 5 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionAccessor.java create mode 100644 src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionInvoker.java diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionAccessor.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionAccessor.java new file mode 100644 index 0000000..bc030c5 --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionAccessor.java @@ -0,0 +1,12 @@ +package land.chipmunk.chipmunkmod.mixin; + +import net.minecraft.network.ClientConnection; +import net.minecraft.network.listener.PacketListener; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(ClientConnection.class) +public interface ClientConnectionAccessor { + @Accessor("packetListener") + PacketListener packetListener (); +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionInvoker.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionInvoker.java new file mode 100644 index 0000000..a9800cb --- /dev/null +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientConnectionInvoker.java @@ -0,0 +1,15 @@ +package land.chipmunk.chipmunkmod.mixin; + +import net.minecraft.network.ClientConnection; +import net.minecraft.network.listener.PacketListener; +import net.minecraft.network.packet.Packet; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Invoker; + +@Mixin(ClientConnection.class) +public interface ClientConnectionInvoker { + @Invoker("handlePacket") + static void handlePacket (Packet packet, PacketListener listener) { + throw new AssertionError(); + } +} diff --git a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java index 8e6e09f..acb74c0 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java +++ b/src/main/java/land/chipmunk/chipmunkmod/mixin/ClientPlayNetworkHandlerAccessor.java @@ -1,6 +1,7 @@ package land.chipmunk.chipmunkmod.mixin; import net.minecraft.client.network.PlayerListEntry; +import net.minecraft.network.ClientConnection; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.gen.Accessor; import net.minecraft.text.Text; @@ -14,6 +15,9 @@ public interface ClientPlayNetworkHandlerAccessor { @Accessor("CHAT_VALIDATION_FAILED_TEXT") static Text chatValidationFailedText () { throw new AssertionError(); } + @Accessor("connection") + ClientConnection connection(); + @Accessor("playerListEntries") Map playerListEntries(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java index be7cade..331edb4 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java @@ -1,5 +1,8 @@ package land.chipmunk.chipmunkmod.modules; +import land.chipmunk.chipmunkmod.mixin.ClientConnectionAccessor; +import land.chipmunk.chipmunkmod.mixin.ClientConnectionInvoker; +import land.chipmunk.chipmunkmod.mixin.ClientPlayNetworkHandlerAccessor; import land.chipmunk.chipmunkmod.song.Note; import land.chipmunk.chipmunkmod.song.Song; import land.chipmunk.chipmunkmod.song.SongLoaderException; @@ -13,15 +16,17 @@ import net.kyori.adventure.text.serializer.gson.GsonComponentSerializer; import net.minecraft.client.MinecraftClient; import net.minecraft.client.network.ClientPlayNetworkHandler; import net.minecraft.client.network.ClientPlayerEntity; +import net.minecraft.network.packet.s2c.play.PlaySoundS2CPacket; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvent; import net.minecraft.text.Text; import net.minecraft.util.Identifier; +import net.minecraft.util.math.random.Random; import java.io.File; import java.net.URL; import java.nio.file.Path; -import java.util.Arrays; import java.util.LinkedList; import java.util.Timer; import java.util.TimerTask; @@ -141,7 +146,7 @@ public class SongPlayer { } }; - playTimer.schedule(playTask, 50, 50); + playTimer.schedule(playTask, 60, 50); if (currentSong != null) currentSong.play(); } @@ -211,15 +216,31 @@ public class SongPlayer { final float floatingPitch = MathUtilities.clamp((float) (0.5 * (Math.pow(2, ((note.pitch + (pitch / 10)) / 12)))), 0F, 2F); try { - if (!useCore) { - if (floatingPitch < 0 || floatingPitch > 2) return; - + if (!useCore && client.player != null) { final String[] thing = note.instrument.sound.split(":"); if (thing[1] == null) return; // idk if this can be null but ill just protect it for now i guess - client.player.playSound(SoundEvent.of(Identifier.of(thing[0], thing[1])), SoundCategory.RECORDS, note.volume, floatingPitch); - } else CommandCore.INSTANCE.run("execute as " + SELECTOR + " at @s run playsound " + note.instrument.sound + " record @s ~ ~ ~ " + note.volume + " " + floatingPitch); + final ClientPlayNetworkHandlerAccessor networkHandlerAccessor = (ClientPlayNetworkHandlerAccessor) client.getNetworkHandler(); + + final ClientConnectionAccessor clientConnectionAccessor = (ClientConnectionAccessor) networkHandlerAccessor.connection(); + + ClientConnectionInvoker.handlePacket( + new PlaySoundS2CPacket( + RegistryEntry.of(SoundEvent.of(Identifier.of(thing[0], thing[1]))), + SoundCategory.RECORDS, + client.player.getX(), + client.player.getY(), + client.player.getZ(), + note.volume, + floatingPitch, + Random.create().nextLong() + ), + clientConnectionAccessor.packetListener() + ); + } else { + CommandCore.INSTANCE.run("execute as " + SELECTOR + " at @s run playsound " + note.instrument.sound + " record @s ~ ~ ~ " + note.volume + " " + floatingPitch); + } } catch (Exception e) { e.printStackTrace(); } diff --git a/src/main/resources/chipmunkmod.mixins.json b/src/main/resources/chipmunkmod.mixins.json index 1e466e6..16cfcb5 100644 --- a/src/main/resources/chipmunkmod.mixins.json +++ b/src/main/resources/chipmunkmod.mixins.json @@ -21,7 +21,9 @@ "ElderGuardianAppearanceParticleMixin", "IdentifierMixin", "DecoratedPotBlockEntitySherdsMixin", - "TextMixin" + "TextMixin", + "ClientConnectionInvoker", + "ClientConnectionAccessor" ], "injectors": { "defaultRequire": 1 From 1547326a54def1fcbe6b3b0d38befe05ff91779a Mon Sep 17 00:00:00 2001 From: ChomeNS <95471003+ChomeNS@users.noreply.github.com> Date: Sat, 1 Jul 2023 09:39:38 +0700 Subject: [PATCH 25/25] add actionbar ig useful for servers with command block ratelimit --- .../chipmunkmod/commands/MusicCommand.java | 28 +++++++++++++++---- .../chipmunkmod/modules/SongPlayer.java | 5 ++-- 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java b/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java index bb78038..0e34a42 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java +++ b/src/main/java/land/chipmunk/chipmunkmod/commands/MusicCommand.java @@ -60,10 +60,10 @@ public class MusicCommand { .then( literal("list") - .executes(c -> instance.list(c, root)) + .executes(c -> instance.list(root)) .then( argument("location", filepath(root)) - .executes(c -> instance.list(c, getPath(c, "location"))) + .executes(c -> instance.list(getPath(c, "location"))) ) ) @@ -92,6 +92,14 @@ public class MusicCommand { ) ) + .then( + literal("actionbar") + .then( + argument("boolean", bool()) + .executes(instance::actionbar) + ) + ) + .then( literal("pitch") .then( @@ -156,9 +164,7 @@ public class MusicCommand { return 1; } - public int list (CommandContext context, Path path) throws CommandSyntaxException { - final FabricClientCommandSource source = context.getSource(); - + public int list (Path path) throws CommandSyntaxException { final CommandManager commandManager = CommandManager.INSTANCE; final String prefix = commandManager.prefix; @@ -291,6 +297,18 @@ public class MusicCommand { return 1; } + public int actionbar (CommandContext context) { + final FabricClientCommandSource source = context.getSource(); + + final boolean enabled = getBool(context, "boolean"); + + SongPlayer.INSTANCE.actionbar(enabled); + + source.sendFeedback(Text.literal("Showing actionbar is now " + (enabled ? "enabled" : "disabled"))); + + return 1; + } + public int pitch (CommandContext context) { final FabricClientCommandSource source = context.getSource(); diff --git a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java index 331edb4..1bcb73b 100644 --- a/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java +++ b/src/main/java/land/chipmunk/chipmunkmod/modules/SongPlayer.java @@ -49,6 +49,7 @@ public class SongPlayer { private int ticksUntilPausedActionbar = 20; @Getter @Setter private boolean useCore = true; + @Getter @Setter private boolean actionbar = true; @Getter @Setter private float pitch = 0; @@ -129,8 +130,8 @@ public class SongPlayer { else ticksUntilPausedActionbar = 20; try { - if (!useCore) client.player.sendActionBar(generateActionbar()); - else CommandCore.INSTANCE.run("title " + SELECTOR + " actionbar " + GsonComponentSerializer.gson().serialize(generateActionbar())); + if (!useCore && actionbar) client.player.sendActionBar(generateActionbar()); + else if (actionbar) CommandCore.INSTANCE.run("title " + SELECTOR + " actionbar " + GsonComponentSerializer.gson().serialize(generateActionbar())); } catch (Exception e) { e.printStackTrace(); }