From de0341400abcfca65afe5d65053ab520aa20844c Mon Sep 17 00:00:00 2001 From: Wyvest <45589059+Wyvest@users.noreply.github.com> Date: Thu, 23 Dec 2021 00:27:46 +0700 Subject: fix chat screenshot feature with patcher & betterchat fix chat animating when chat tabs cancel --- .../raeids/stratus/hook/GuiIngameForgeHook.java | 6 --- .../com/raeids/stratus/mixin/GuiChatMixin.java | 11 ++--- .../raeids/stratus/mixin/GuiIngameForgeMixin.java | 29 ------------ .../com/raeids/stratus/mixin/GuiNewChatMixin.java | 51 +++++++++++++++++----- .../mixin/GuiUtilRenderComponentsMixin.java | 27 ------------ .../kotlin/com/raeids/stratus/hook/ChatTabs.kt | 3 +- .../com/raeids/stratus/hook/ModCompatHooks.kt | 20 +++++++++ src/main/resources/mixins.stratus.json | 2 - 8 files changed, 66 insertions(+), 83 deletions(-) delete mode 100644 src/main/java/com/raeids/stratus/hook/GuiIngameForgeHook.java delete mode 100644 src/main/java/com/raeids/stratus/mixin/GuiIngameForgeMixin.java delete mode 100644 src/main/java/com/raeids/stratus/mixin/GuiUtilRenderComponentsMixin.java create mode 100644 src/main/kotlin/com/raeids/stratus/hook/ModCompatHooks.kt (limited to 'src') diff --git a/src/main/java/com/raeids/stratus/hook/GuiIngameForgeHook.java b/src/main/java/com/raeids/stratus/hook/GuiIngameForgeHook.java deleted file mode 100644 index 542b4a5..0000000 --- a/src/main/java/com/raeids/stratus/hook/GuiIngameForgeHook.java +++ /dev/null @@ -1,6 +0,0 @@ -package com.raeids.stratus.hook; - -public interface GuiIngameForgeHook { - int getX(); - int getY(); -} diff --git a/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java index e0a2161..350f000 100644 --- a/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java +++ b/src/main/java/com/raeids/stratus/mixin/GuiChatMixin.java @@ -1,13 +1,12 @@ package com.raeids.stratus.mixin; +import com.raeids.stratus.Stratus; import com.raeids.stratus.config.StratusConfig; -import com.raeids.stratus.hook.ChatSearchingKt; -import com.raeids.stratus.hook.ChatTab; -import com.raeids.stratus.hook.ChatTabs; -import com.raeids.stratus.hook.GuiNewChatHook; +import com.raeids.stratus.hook.*; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiChat; import net.minecraft.client.gui.GuiScreen; +import net.minecraft.util.MathHelper; import org.lwjgl.input.Mouse; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -71,7 +70,9 @@ public abstract class GuiChatMixin extends GuiScreen { ChatSearchingKt.getInputField().mouseClicked(mouseX, mouseY, mouseButton); } GuiNewChatHook hook = ((GuiNewChatHook) Minecraft.getMinecraft().ingameGUI.getChatGUI()); - if (hook.shouldCopy() && hook.getRight() <= mouseX && hook.getRight() + 9 > mouseX) { + float f = mc.ingameGUI.getChatGUI().getChatScale(); + int x = MathHelper.floor_float((float) mouseX / f); + if (hook.shouldCopy() && (hook.getRight() + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) <= x && (hook.getRight() + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) + 9 > x) { try { Toolkit.getDefaultToolkit().getSystemClipboard().setContents(new StringSelection(hook.getStratusChatComponent(Mouse.getY())), null); } catch (Exception e) { diff --git a/src/main/java/com/raeids/stratus/mixin/GuiIngameForgeMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiIngameForgeMixin.java deleted file mode 100644 index 4445f99..0000000 --- a/src/main/java/com/raeids/stratus/mixin/GuiIngameForgeMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.raeids.stratus.mixin; - -import com.raeids.stratus.hook.GuiIngameForgeHook; -import net.minecraftforge.client.GuiIngameForge; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.ModifyArgs; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; - -@Mixin(value = GuiIngameForge.class, remap = false, priority = Integer.MIN_VALUE) -public class GuiIngameForgeMixin implements GuiIngameForgeHook { - private int stratus$x = 0; - private int stratus$y = 0; - @ModifyArgs(method = "renderChat", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/renderer/GlStateManager;translate(FFF)V", remap = true)) - private void captureTranslate(Args args) { - stratus$x = Math.round(args.get(0)); - stratus$y = Math.round(args.get(1)); - } - - @Override - public int getX() { - return stratus$x; - } - - @Override - public int getY() { - return stratus$y; - } -} diff --git a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java index 86db154..8fbf6b5 100644 --- a/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java +++ b/src/main/java/com/raeids/stratus/mixin/GuiNewChatMixin.java @@ -1,12 +1,11 @@ package com.raeids.stratus.mixin; -import club.sk1er.patcher.config.PatcherConfig; -import com.llamalad7.betterchat.BetterChat; import com.raeids.stratus.Stratus; import com.raeids.stratus.config.StratusConfig; import com.raeids.stratus.hook.ChatSearchingKt; import com.raeids.stratus.hook.ChatTabs; import com.raeids.stratus.hook.GuiNewChatHook; +import com.raeids.stratus.hook.ModCompatHooks; import gg.essential.universal.UMouse; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.*; @@ -25,13 +24,15 @@ import org.spongepowered.asm.mixin.injection.invoke.arg.Args; import java.util.List; -@Mixin(GuiNewChat.class) +@Mixin(value = GuiNewChat.class, priority = Integer.MIN_VALUE) public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Unique private int stratus$right = 0; @Unique private boolean stratus$shouldCopy; @Unique private boolean stratus$chatCheck; @Shadow @Final private Minecraft mc; @Shadow @Final private List drawnChatLines; + @SuppressWarnings({"FieldCanBeLocal", "unused"}) + private float percentComplete; @Shadow public abstract boolean getChatOpen(); @@ -40,13 +41,20 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { @Shadow public abstract int getLineCount(); @Shadow private int scrollPos; + @Shadow @Final private List chatLines; + + @Shadow public abstract void deleteChatLine(int id); + @Unique private static final ResourceLocation COPY = new ResourceLocation("stratus:copy.png"); - @Inject(method = "setChatLine", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/MathHelper;floor_float(F)I", shift = At.Shift.AFTER)) - private void setDoing(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { - if (StratusConfig.INSTANCE.getChatTabs()) { - ChatTabs.INSTANCE.setDoing(true); - } + @Inject(method = "printChatMessageWithOptionalDeletion", at = @At("HEAD"), cancellable = true) + private void handlePrintChatMessage(IChatComponent chatComponent, int chatLineId, CallbackInfo ci) { + handleChatTabMessage(chatComponent, chatLineId, mc.ingameGUI.getUpdateCounter(), false, ci); + } + + @Inject(method = "setChatLine", at = @At("HEAD"), cancellable = true) + private void handleSetChatLine(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { + handleChatTabMessage(chatComponent, chatLineId, updateCounter, displayOnly, ci); } @Inject(method = "drawChat", at = @At("HEAD")) @@ -78,11 +86,11 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { int bottom = args.get(3); if (mc.currentScreen instanceof GuiChat) { float f = this.getChatScale(); - int mouseX = MathHelper.floor_double(UMouse.getScaledX()) - (3 + (Stratus.INSTANCE.isBetterChat() ? BetterChat.getSettings().xOffset : 0)); - int mouseY = MathHelper.floor_double(UMouse.getScaledY()) - (27 + (Stratus.INSTANCE.isBetterChat() ? BetterChat.getSettings().yOffset : 0) + (Stratus.INSTANCE.isPatcher() && PatcherConfig.chatPosition ? 12 : 0)); + int mouseX = MathHelper.floor_double(UMouse.getScaledX()) - 3; + int mouseY = MathHelper.floor_double(UMouse.getScaledY()) - 27 + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getYOffset() : 0) + (Stratus.INSTANCE.isPatcher() && ModCompatHooks.getChatPosition() ? 12 : 0); mouseX = MathHelper.floor_float((float)mouseX / f); mouseY = -(MathHelper.floor_float((float)mouseY / f)); //WHY DO I NEED TO DO THIS - if (mouseX >= left && mouseY < bottom && mouseX < right + 9 && mouseY >= top) { + if (mouseX >= (left + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) && mouseY < bottom && mouseX < (right + 9 + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getXOffset() : 0)) && mouseY >= top) { stratus$shouldCopy = true; drawCopyChatBox(right, top); } @@ -111,6 +119,25 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { return stratus$shouldCopy; } + private void handleChatTabMessage(IChatComponent chatComponent, int chatLineId, int updateCounter, boolean displayOnly, CallbackInfo ci) { + if (StratusConfig.INSTANCE.getChatTabs()) { + if (!ChatTabs.INSTANCE.shouldRender(chatComponent)) { + percentComplete = 1.0F; + if (chatLineId != 0) { + deleteChatLine(chatLineId); + } + if (!displayOnly) { + chatLines.add(0, new ChatLine(updateCounter, chatComponent, chatLineId)); + while (this.chatLines.size() > (Stratus.INSTANCE.isPatcher() ? 32767 : 100)) + { + this.chatLines.remove(this.chatLines.size() - 1); + } + } + ci.cancel(); + } + } + } + private void drawCopyChatBox(int right, int top) { stratus$chatCheck = true; GlStateManager.enableRescaleNormal(); @@ -139,7 +166,7 @@ public abstract class GuiNewChatMixin extends Gui implements GuiNewChatHook { ScaledResolution scaledresolution = new ScaledResolution(this.mc); int i = scaledresolution.getScaleFactor(); float f = this.getChatScale(); - int k = mouseY / i - (27 + (Stratus.INSTANCE.isBetterChat() ? BetterChat.getSettings().yOffset : 0) + (Stratus.INSTANCE.isPatcher() && PatcherConfig.chatPosition ? 12 : 0)); + int k = mouseY / i - (27 + (Stratus.INSTANCE.isPatcher() && ModCompatHooks.getChatPosition() ? 12 : 0)) + (Stratus.INSTANCE.isBetterChat() ? ModCompatHooks.getYOffset() : 0); k = MathHelper.floor_float((float) k / f); if (k >= 0) { diff --git a/src/main/java/com/raeids/stratus/mixin/GuiUtilRenderComponentsMixin.java b/src/main/java/com/raeids/stratus/mixin/GuiUtilRenderComponentsMixin.java deleted file mode 100644 index 8579f7a..0000000 --- a/src/main/java/com/raeids/stratus/mixin/GuiUtilRenderComponentsMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.raeids.stratus.mixin; - -import com.raeids.stratus.config.StratusConfig; -import com.raeids.stratus.hook.ChatTabs; -import net.minecraft.client.gui.FontRenderer; -import net.minecraft.client.gui.GuiUtilRenderComponents; -import net.minecraft.util.IChatComponent; -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 java.util.Collections; -import java.util.List; - -@Mixin(GuiUtilRenderComponents.class) -public class GuiUtilRenderComponentsMixin { - @Inject(method = "splitText", at = @At("HEAD"), cancellable = true) - private static void cancelText(IChatComponent k, int s1, FontRenderer chatcomponenttext, boolean l, boolean chatcomponenttext2, CallbackInfoReturnable> cir) { - if (StratusConfig.INSTANCE.getChatTabs() && ChatTabs.INSTANCE.isDoing()) { - if (!ChatTabs.INSTANCE.shouldRender(k)) { - cir.setReturnValue(Collections.emptyList()); - } - ChatTabs.INSTANCE.setDoing(false); - } - } -} diff --git a/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt b/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt index b162671..ffef559 100644 --- a/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt +++ b/src/main/kotlin/com/raeids/stratus/hook/ChatTabs.kt @@ -10,7 +10,6 @@ object ChatTabs { private val GSON = GsonBuilder().setPrettyPrinting().create() private val PARSER = JsonParser() val tabs = arrayListOf() - var isDoing = false var currentTab: ChatTab? = null set(value) { if (value != null) { @@ -58,7 +57,7 @@ object ChatTabs { } private fun generateDefaultTabs(): JsonArray { - val all = ChatTab("ALL", false, null, null, null, null, null, "/ac ") + val all = ChatTab("ALL", false, null, null, null, null, null, "") val party = ChatTab( "PARTY", false, diff --git a/src/main/kotlin/com/raeids/stratus/hook/ModCompatHooks.kt b/src/main/kotlin/com/raeids/stratus/hook/ModCompatHooks.kt new file mode 100644 index 0000000..e2ac629 --- /dev/null +++ b/src/main/kotlin/com/raeids/stratus/hook/ModCompatHooks.kt @@ -0,0 +1,20 @@ +package com.raeids.stratus.hook + +import club.sk1er.patcher.config.PatcherConfig +import com.llamalad7.betterchat.BetterChat + +// This exists because mixin doesn't like dummy classes +object ModCompatHooks { + @JvmStatic + val xOffset + get() = BetterChat.getSettings().xOffset + + @JvmStatic + val yOffset + get() = BetterChat.getSettings().yOffset + + @JvmStatic + val chatPosition + get() = PatcherConfig.chatPosition + +} diff --git a/src/main/resources/mixins.stratus.json b/src/main/resources/mixins.stratus.json index 7e8339e..5388c40 100644 --- a/src/main/resources/mixins.stratus.json +++ b/src/main/resources/mixins.stratus.json @@ -6,8 +6,6 @@ "mixins": [ "GuiChatMixin", "GuiNewChatAccessor", - "GuiUtilRenderComponentsMixin", - "GuiIngameForgeMixin", "EntityPlayerSPMixin", "GuiNewChatMixin" ], -- cgit