From 9d86718a8e670a6330e0d8f485bba06adbaf71d4 Mon Sep 17 00:00:00 2001 From: LemonCaramel Date: Wed, 14 Aug 2024 15:11:43 +0900 Subject: [PATCH] do not use ModifyArgs fixes #18 --- .../chat/mixin/MixinSignEditScreen.java | 28 ++++++++++--------- .../asm/synthetic/args/ChatModDummy.java | 7 ----- 2 files changed, 15 insertions(+), 20 deletions(-) delete mode 100644 forge/src/main/java/org/spongepowered/asm/synthetic/args/ChatModDummy.java diff --git a/common/src/main/java/moe/caramel/chat/mixin/MixinSignEditScreen.java b/common/src/main/java/moe/caramel/chat/mixin/MixinSignEditScreen.java index 3159861..831c820 100644 --- a/common/src/main/java/moe/caramel/chat/mixin/MixinSignEditScreen.java +++ b/common/src/main/java/moe/caramel/chat/mixin/MixinSignEditScreen.java @@ -1,9 +1,13 @@ package moe.caramel.chat.mixin; +import com.llamalad7.mixinextras.injector.wrapoperation.Operation; +import com.llamalad7.mixinextras.injector.wrapoperation.WrapOperation; import moe.caramel.chat.controller.ScreenController; import moe.caramel.chat.wrapper.AbstractIMEWrapper; import moe.caramel.chat.wrapper.WrapperSignEditScreen; import net.minecraft.ChatFormatting; +import net.minecraft.client.gui.Font; +import net.minecraft.client.gui.GuiGraphics; import net.minecraft.client.gui.font.TextFieldHelper; import net.minecraft.client.gui.screens.inventory.AbstractSignEditScreen; import net.minecraft.world.level.block.entity.SignBlockEntity; @@ -14,11 +18,9 @@ import org.spongepowered.asm.mixin.Unique; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.ModifyArgs; import org.spongepowered.asm.mixin.injection.Redirect; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.invoke.arg.Args; import java.util.function.Consumer; /** @@ -76,7 +78,7 @@ private boolean helperKeyPressed(final TextFieldHelper helper, final int key) { return result; } - @ModifyArgs( + @WrapOperation( method = "renderSignText", at = @At( value = "INVOKE", @@ -84,28 +86,28 @@ private boolean helperKeyPressed(final TextFieldHelper helper, final int key) { ordinal = 0 ) ) - private void renderCaret(final Args args) { + private int renderCaret(final GuiGraphics instance, final Font font, final String text, final int x, final int y, final int color, final boolean dropShadow, final Operation original) { // Check IME Status - final String original = args.get(1); - if (original.isEmpty() || caramelChat$wrapper.getStatus() == AbstractIMEWrapper.InputStatus.NONE) { - return; + if (text.isEmpty() || caramelChat$wrapper.getStatus() == AbstractIMEWrapper.InputStatus.NONE) { + return original.call(instance, font, text, x, y, color, dropShadow); } // Line Check (stupid way...) final int lineHeight = this.sign.getTextLineHeight(); final int centerHeight = (4 * lineHeight / 2); - final int line = (((int) args.get(3) + centerHeight) / lineHeight); + final int line = ((y + centerHeight) / lineHeight); if (line != this.line) { - return; + return original.call(instance, font, text, x, y, color, dropShadow); } // Render Caret final int firstEndPos = caramelChat$wrapper.getFirstEndPos(); final int secondStartPos = caramelChat$wrapper.getSecondStartPos(); - final String first = original.substring(0, firstEndPos); - final String input = original.substring(firstEndPos, secondStartPos); - final String second = original.substring(secondStartPos); - args.set(1, first + ChatFormatting.UNDERLINE + input + ChatFormatting.RESET + second); // OMG.. + final String first = text.substring(0, firstEndPos); + final String input = text.substring(firstEndPos, secondStartPos); + final String second = text.substring(secondStartPos); + final String result = (first + ChatFormatting.UNDERLINE + input + ChatFormatting.RESET + second); // OMG.. + return original.call(instance, font, result, x, y, color, dropShadow); } } diff --git a/forge/src/main/java/org/spongepowered/asm/synthetic/args/ChatModDummy.java b/forge/src/main/java/org/spongepowered/asm/synthetic/args/ChatModDummy.java deleted file mode 100644 index 459d107..0000000 --- a/forge/src/main/java/org/spongepowered/asm/synthetic/args/ChatModDummy.java +++ /dev/null @@ -1,7 +0,0 @@ -package org.spongepowered.asm.synthetic.args; - -/** - * Fix Forge Bug... - * @see here - */ -class ChatModDummy { }