From ac807ba9f8617560b2e17af3e54b83fb8ee4def6 Mon Sep 17 00:00:00 2001 From: sychic <47618543+Sychic@users.noreply.github.com> Date: Fri, 15 Mar 2024 21:38:01 -0400 Subject: [PATCH] feat: add clicked commands to chat history closes #172 --- .../sk1er/patcher/config/PatcherConfig.java | 9 +++++++++ .../GuiChatMixin_SafeChatClicksHistory.java | 19 +++++++++++++++++++ src/main/resources/patcher.mixins.json | 5 +++-- 3 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 src/main/java/club/sk1er/patcher/mixins/features/GuiChatMixin_SafeChatClicksHistory.java diff --git a/src/main/java/club/sk1er/patcher/config/PatcherConfig.java b/src/main/java/club/sk1er/patcher/config/PatcherConfig.java index b803e6ad7..0f222bfec 100644 --- a/src/main/java/club/sk1er/patcher/config/PatcherConfig.java +++ b/src/main/java/club/sk1er/patcher/config/PatcherConfig.java @@ -1121,6 +1121,13 @@ public static int getInventoryScale() { ) public static boolean safeChatClicks; + @Property( + type = PropertyType.SWITCH, name = "Safe Chat Clicks History", + description = "Adds commands sent from clicking chat messages to the chat history.", + category = "Screens", subcategory = "Chat" + ) + public static boolean safeChatClicksHistory; + @Property( type = PropertyType.SWITCH, name = "Smart Disconnect", description = "Choose between disconnecting or relogging when clicking the disconnect button.\n§eOnly works on Multiplayer servers.", @@ -1311,6 +1318,8 @@ public PatcherConfig() { addDependency("cacheFontData", "optimizedFontRenderer"); addDependency("chunkUpdateLimit", "limitChunks"); + addDependency("safeChatClicksHistory", "safeChatClicks"); + Arrays.asList( "screenshotNoFeedback", "compactScreenshotResponse", "autoCopyScreenshot", "screenshotPreview", "previewTime", "previewAnimationStyle", "previewScale", "favoriteScreenshot", diff --git a/src/main/java/club/sk1er/patcher/mixins/features/GuiChatMixin_SafeChatClicksHistory.java b/src/main/java/club/sk1er/patcher/mixins/features/GuiChatMixin_SafeChatClicksHistory.java new file mode 100644 index 000000000..89bbadc51 --- /dev/null +++ b/src/main/java/club/sk1er/patcher/mixins/features/GuiChatMixin_SafeChatClicksHistory.java @@ -0,0 +1,19 @@ +package club.sk1er.patcher.mixins.features; + +import club.sk1er.patcher.config.PatcherConfig; +import net.minecraft.client.gui.Gui; +import net.minecraft.client.gui.GuiChat; +import net.minecraft.client.gui.GuiScreen; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.ModifyArg; + +@Mixin(GuiScreen.class) +public abstract class GuiChatMixin_SafeChatClicksHistory extends Gui { + + @ModifyArg(method = "handleComponentClick", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiScreen;sendChatMessage(Ljava/lang/String;Z)V"), index = 1) + public boolean patcher$handleComponentClick(boolean addToChat) { + + return addToChat || (PatcherConfig.safeChatClicksHistory && ((Object) this) instanceof GuiChat); + } +} diff --git a/src/main/resources/patcher.mixins.json b/src/main/resources/patcher.mixins.json index 9d7884995..46e15d184 100644 --- a/src/main/resources/patcher.mixins.json +++ b/src/main/resources/patcher.mixins.json @@ -24,8 +24,6 @@ "accessors.KeyBindingAccessor", "accessors.MinecraftAccessor", "accessors.MinecraftForgeClientAccessor", - "accessors.optifine.ConfigAccessor", - "accessors.optifine.CustomColorsAccessor", "accessors.PositionedSoundAccessor", "accessors.RenderManagerAccessor", "accessors.ResourcePackRepositoryAccessor", @@ -33,6 +31,8 @@ "accessors.SoundManagerAccessor", "accessors.SoundRegistryAccessor", "accessors.WorldRendererAccessor", + "accessors.optifine.ConfigAccessor", + "accessors.optifine.CustomColorsAccessor", "bugfixes.BlockFluidRendererMixin_FixStitching", "bugfixes.BlockModelRendererMixin_SmoothLighting", "bugfixes.CommandHandlerMixin_CaseCommands", @@ -129,6 +129,7 @@ "features.FontRenderMixin_ShadowTypes", "features.GuiAchievementMixin_CancelRender", "features.GuiChatMixin_ExtendedChatLength", + "features.GuiChatMixin_SafeChatClicksHistory", "features.GuiContainerMixin_ClickOutOfContainers", "features.GuiContainerMixin_DropModifierKey", "features.GuiIngameForgeMixin_ActionbarText",