mirror of
https://github.com/refactorinqq/SLC-1.8.9.git
synced 2024-11-10 09:01:32 +01:00
Chat Calculator
This commit is contained in:
parent
733f693b71
commit
8933b92951
@ -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);
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user