diff --git a/src/main/java/net/silentclient/client/mixin/accessors/GuiChatAccessor.java b/src/main/java/net/silentclient/client/mixin/accessors/GuiChatAccessor.java deleted file mode 100644 index ab1f710..0000000 --- a/src/main/java/net/silentclient/client/mixin/accessors/GuiChatAccessor.java +++ /dev/null @@ -1,8 +0,0 @@ -package net.silentclient.client.mixin.accessors; - -import net.silentclient.client.mixin.wrappers.GuiTextFieldWrapper; - -public interface GuiChatAccessor { - GuiTextFieldWrapper silent$getInputField(); - void silent$setInputField(GuiTextFieldWrapper a); -} diff --git a/src/main/java/net/silentclient/client/mixin/mixins/GuiChatMixin.java b/src/main/java/net/silentclient/client/mixin/mixins/GuiChatMixin.java index 15746ca..a6a447c 100644 --- a/src/main/java/net/silentclient/client/mixin/mixins/GuiChatMixin.java +++ b/src/main/java/net/silentclient/client/mixin/mixins/GuiChatMixin.java @@ -5,9 +5,9 @@ import net.minecraft.client.gui.GuiTextField; import net.silentclient.client.Client; import net.silentclient.client.gui.animation.SimpleAnimation; import net.silentclient.client.gui.clickgui.utils.GlUtils; -import net.silentclient.client.mixin.accessors.GuiChatAccessor; -import net.silentclient.client.mixin.wrappers.GuiTextFieldWrapper; import net.silentclient.client.mods.render.ChatMod; +import net.silentclient.client.utils.calculator.ChatCalculator; +import org.lwjgl.input.Keyboard; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Unique; @@ -16,24 +16,8 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(GuiChat.class) -public class GuiChatMixin implements GuiChatAccessor { - +public class GuiChatMixin { @Shadow protected GuiTextField inputField; - - @Override - public GuiTextFieldWrapper silent$getInputField() { - return new GuiTextFieldWrapper(this.inputField); - } - - @Override - public void silent$setInputField(GuiTextFieldWrapper a) { - if(a == null) { - this.inputField = null; - return; - } - this.inputField = a.getGuiTextField(); - } - @Unique private SimpleAnimation animation = new SimpleAnimation(0.0F); @@ -52,4 +36,11 @@ public class GuiChatMixin implements GuiChatAccessor { GlUtils.stopTranslate(); } } + + @Inject(method = "keyTyped", at = @At("HEAD"), cancellable = true) + public void chatCalculator(char typedChar, int keyCode, CallbackInfo ci) { + if(Keyboard.getEventKey() == 15 && Keyboard.getEventKeyState() && ChatCalculator.runExpression(inputField)) { + ci.cancel(); + } + } } diff --git a/src/main/java/net/silentclient/client/utils/calculator/ChatCalculator.java b/src/main/java/net/silentclient/client/utils/calculator/ChatCalculator.java index 8573c0d..9d53066 100644 --- a/src/main/java/net/silentclient/client/utils/calculator/ChatCalculator.java +++ b/src/main/java/net/silentclient/client/utils/calculator/ChatCalculator.java @@ -1,10 +1,8 @@ package net.silentclient.client.utils.calculator; -import java.text.DecimalFormat; - -import net.minecraft.client.gui.GuiChat; import net.minecraft.client.gui.GuiTextField; -import net.silentclient.client.mixin.accessors.GuiChatAccessor; + +import java.text.DecimalFormat; public class ChatCalculator { private static final DecimalFormat df = new DecimalFormat("#,##0.##"); @@ -13,12 +11,11 @@ public class ChatCalculator { df.applyPattern(format); } - public static boolean runExpression(GuiChat chat) { - return (runExprReplace(chat) || runExprAdd(chat)); + public static boolean runExpression(GuiTextField field) { + return (runExprReplace(field) || runExprAdd(field)); } - private static boolean runExprReplace(GuiChat chat) { - GuiTextField field = ((GuiChatAccessor) chat).silent$getInputField().getGuiTextField(); + private static boolean runExprReplace(GuiTextField field) { String originalText = field.getText(); int cursor = field.getCursorPosition(); try { @@ -34,8 +31,7 @@ public class ChatCalculator { } } - private static boolean runExprAdd(GuiChat chat) { - GuiTextField field = ((GuiChatAccessor) chat).silent$getInputField().getGuiTextField(); + private static boolean runExprAdd(GuiTextField field) { String originalText = field.getText(); int cursor = field.getCursorPosition(); try {