summaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/mixins
diff options
context:
space:
mode:
authorVixid <52578495+VixidDev@users.noreply.github.com>2024-04-25 08:43:01 +0100
committerGitHub <noreply@github.com>2024-04-25 09:43:01 +0200
commitf3b3b44296b8a6ac77ecad433ca28e7a03a9eaf2 (patch)
tree4a1e45727434c16489c748fad7eefe4117be5875 /src/main/java/at/hannibal2/skyhanni/mixins
parented53f750e6b68067f58a5e706db220760d57029f (diff)
downloadskyhanni-f3b3b44296b8a6ac77ecad433ca28e7a03a9eaf2.tar.gz
skyhanni-f3b3b44296b8a6ac77ecad433ca28e7a03a9eaf2.tar.bz2
skyhanni-f3b3b44296b8a6ac77ecad433ca28e7a03a9eaf2.zip
Feature: SBA style Enchant Parsing (#654)
Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/mixins')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiChatHook.kt40
-rw-r--r--src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiChat.java22
2 files changed, 62 insertions, 0 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiChatHook.kt b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiChatHook.kt
new file mode 100644
index 000000000..354707f85
--- /dev/null
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/hooks/GuiChatHook.kt
@@ -0,0 +1,40 @@
+package at.hannibal2.skyhanni.mixins.hooks
+
+import net.minecraft.event.HoverEvent
+import net.minecraft.util.ChatComponentText
+import net.minecraft.util.ChatStyle
+import net.minecraft.util.IChatComponent
+
+object GuiChatHook {
+
+ lateinit var replacement: ChatComponentText
+
+ fun replaceEntireComponent(title: String, chatStyle: ChatStyle) {
+ if (!this::replacement.isInitialized) return
+
+ // Initialise new component
+ val newComponent = ChatComponentText(title)
+ newComponent.setChatStyle(chatStyle)
+
+ replacement = newComponent
+ }
+
+ fun replaceOnlyHoverEvent(hoverEvent: HoverEvent) {
+ if (!this::replacement.isInitialized) return
+
+ // Initialise new component
+ val newComponent = ChatComponentText(replacement.chatComponentText_TextValue)
+ newComponent.setChatStyle(replacement.chatStyle)
+ newComponent.chatStyle.chatHoverEvent = hoverEvent
+
+ replacement = newComponent
+ }
+
+ fun getReplacementAsIChatComponent(): IChatComponent {
+ if (!this::replacement.isInitialized) {
+ // Return an extremely basic chat component as to not error downstream
+ return ChatComponentText("Original component was not set")
+ }
+ return replacement
+ }
+}
diff --git a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiChat.java b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiChat.java
index 5225cf221..97ef80364 100644
--- a/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiChat.java
+++ b/src/main/java/at/hannibal2/skyhanni/mixins/transformers/MixinGuiChat.java
@@ -1,16 +1,22 @@
package at.hannibal2.skyhanni.mixins.transformers;
+import at.hannibal2.skyhanni.events.ChatHoverEvent;
import at.hannibal2.skyhanni.features.commands.tabcomplete.TabComplete;
+import at.hannibal2.skyhanni.mixins.hooks.GuiChatHook;
import com.google.common.collect.Lists;
import net.minecraft.client.gui.GuiChat;
import net.minecraft.client.gui.GuiTextField;
+import net.minecraft.util.ChatComponentText;
import net.minecraft.util.EnumChatFormatting;
+import net.minecraft.util.IChatComponent;
import org.apache.commons.lang3.StringUtils;
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.LocalCapture;
import java.util.List;
@@ -56,4 +62,20 @@ public class MixinGuiChat {
}
}
}
+
+ @Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;handleComponentHover(Lnet/minecraft/util/IChatComponent;II)V"), locals = LocalCapture.CAPTURE_FAILHARD)
+ public void chatHoverEvent(int mouseX, int mouseY, float partialTicks, CallbackInfo ci, IChatComponent component) {
+ // Only ChatComponentText components can make it to this point
+
+ // Always set the replacement, so if someone is no longer editing the replacement
+ // we get the original component back
+ GuiChatHook.INSTANCE.setReplacement((ChatComponentText) component);
+
+ new ChatHoverEvent((ChatComponentText) component).postAndCatch();
+ }
+
+ @ModifyArg(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/GuiChat;handleComponentHover(Lnet/minecraft/util/IChatComponent;II)V"), index = 0)
+ public IChatComponent replaceWithNewComponent(IChatComponent originalComponent) {
+ return GuiChatHook.INSTANCE.getReplacementAsIChatComponent();
+ }
}