diff --git a/src/com/github/Debris/oh_my_mite_client/config/Config.java b/src/com/github/Debris/oh_my_mite_client/config/Config.java index 888e60f..30cca3b 100644 --- a/src/com/github/Debris/oh_my_mite_client/config/Config.java +++ b/src/com/github/Debris/oh_my_mite_client/config/Config.java @@ -6,7 +6,11 @@ public class Config { public static final FieldReference ATTACK_INTERVAL = new FieldReference<>(500); + public static final FieldReference FLYING_SPEED = new FieldReference<>(0.99F); + + public static int gameMode = 0; public static final ConfigCategory ROOT = ConfigCategory.of("NoClickCD") - .addEntry(ConfigEntry.of("auto_attack_interval", ATTACK_INTERVAL).withComment("自动攻击间隔, 单位毫秒")); + .addEntry(ConfigEntry.of("auto_attack_interval", ATTACK_INTERVAL).withComment("自动攻击间隔, 单位毫秒")) + .addEntry(ConfigEntry.of("flying_speed", FLYING_SPEED).withComment("飞行速度")); } diff --git a/src/com/github/Debris/oh_my_mite_client/config/FeatureToggle.java b/src/com/github/Debris/oh_my_mite_client/config/FeatureToggle.java new file mode 100644 index 0000000..82f5e65 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/config/FeatureToggle.java @@ -0,0 +1,95 @@ +package com.github.Debris.oh_my_mite_client.config; + +import com.google.common.collect.ImmutableList; +import net.minecraft.KeyBinding; + +import java.io.*; + +public enum FeatureToggle { + Tweak_AutoForward("自动前进", 200, false), + Tweak_AutoLeft("自动向左", 203, false), + Tweak_AutoBack("自动后退", 208, false), + Tweak_AutoRight("自动向右", 205, false), + Tweak_Autojump("自动跳跃", 0, false), + Tweak_AutoSneak("自动潜行", 54, false),//RShift + Tweak_AutoAttack("自动攻击", 36, false),//J + Tweak_HoldUse("长按右键", 22, false),//U + Tweak_AutoCraft("自动合成(开发中)", 13, false),//= TODO + Tweak_RenderEntities("渲染实体(开发中)", 64, false),//F6//TODO + Tweak_FastFlying("快速飞行", 48, false),//B + + + Tweak_CopyTP("复制tp坐标", 47),//V + Tweak_ToggleMode("切换游戏模式", 62),//F4 + ; + public static File optionsFile; + public static final ImmutableList VALUES = ImmutableList.copyOf(values()); + private final KeyBinding keybind; + private boolean valueBoolean; + private final boolean isTrigger; + + FeatureToggle(String description, int defaultKey) { + this.keybind = new KeyBinding(description, defaultKey); + this.isTrigger = true; + this.valueBoolean = false; + } + FeatureToggle(String description, int defaultKey, boolean defaultValueBoolean) { + this.keybind = new KeyBinding(description, defaultKey); + this.isTrigger = false; + this.valueBoolean = defaultValueBoolean; + } + + public KeyBinding getKeybind() { + return this.keybind; + } + public boolean getBooleanValue() { + return this.valueBoolean; + } + public boolean isTrigger() { + return isTrigger; + } + public void invert() { + this.valueBoolean = !this.valueBoolean; + } + + public static void saveOptions() { + PrintWriter var1; + try { + var1 = new PrintWriter(new FileWriter(optionsFile)); + for (int var2 = 0; var2 < values().length; ++var2) { + var1.println("key_" + values()[var2].getKeybind().keyDescription + ":" + values()[var2].getKeybind().keyCode); + } + var1.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static void loadOptions() { + BufferedReader var1; + try { + if (!optionsFile.exists()) { + return; + } + var1 = new BufferedReader(new FileReader(optionsFile)); + String var2; + while ((var2 = var1.readLine()) != null) { + String[] var3 = var2.split(":"); + for (int var4 = 0; var4 < values().length; ++var4) { + if (var3[0].equals("key_" + values()[var4].getKeybind().keyDescription)) { + values()[var4].getKeybind().keyCode = Integer.parseInt(var3[1]); + } + } + } + KeyBinding.resetKeyBindingArrayAndHash(); + var1.close(); + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + public static void setPath(File parent) { + optionsFile = new File(parent, "OMMCoptions.txt"); + } + +} diff --git a/src/com/github/Debris/oh_my_mite_client/config/FieldAccessor.java b/src/com/github/Debris/oh_my_mite_client/config/FieldAccessor.java deleted file mode 100644 index 7a2175a..0000000 --- a/src/com/github/Debris/oh_my_mite_client/config/FieldAccessor.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.github.Debris.oh_my_mite_client.config; - -import com.github.Debris.oh_my_mite_client.config.OMMCOptions; - -public interface FieldAccessor { - OMMCOptions OMMCOptionsProvider(); -} diff --git a/src/com/github/Debris/oh_my_mite_client/config/OMMCGuiControls.java b/src/com/github/Debris/oh_my_mite_client/config/OMMCGuiControls.java index 9b25368..94b843a 100644 --- a/src/com/github/Debris/oh_my_mite_client/config/OMMCGuiControls.java +++ b/src/com/github/Debris/oh_my_mite_client/config/OMMCGuiControls.java @@ -1,17 +1,16 @@ package com.github.Debris.oh_my_mite_client.config; import net.minecraft.*; +import org.lwjgl.input.Keyboard; public class OMMCGuiControls extends GuiScreen { private final GuiScreen parentScreen; protected String screenTitle = "OMMC按键绑定"; - private final OMMCOptions ommcOptions; private int buttonId = -1; private int page_index; - public OMMCGuiControls(GuiScreen par1GuiScreen, OMMCOptions par2GameSettings) { + public OMMCGuiControls(GuiScreen par1GuiScreen) { this.parentScreen = par1GuiScreen; - this.ommcOptions = par2GameSettings; } private int getLeftBorder() { @@ -30,8 +29,8 @@ private int getKeybindButtonPosY(int index) { @Override public void initGui() { - for (int var2 = 0; var2 < this.ommcOptions.allKeyBindings.length; ++var2) { - this.buttonList.add(new GuiSmallButton(var2, this.getKeybindButtonPosX(var2), this.getKeybindButtonPosY(var2), 70, 20, this.ommcOptions.allKeyBindings[var2].keyDescription)); + for (int var2 = 0; var2 < FeatureToggle.values().length; ++var2) { + this.buttonList.add(new GuiSmallButton(var2, this.getKeybindButtonPosX(var2), this.getKeybindButtonPosY(var2), 70, 20, FeatureToggle.values()[var2].getKeybind().keyDescription)); } this.setKeybindButtonVisibilities(); this.buttonList.add(new GuiButton(201, this.width / 2 - 100, this.height / 6 + 168 - 24, I18n.getString("gui.nextPage"))); @@ -39,7 +38,7 @@ public void initGui() { } private void setKeybindButtonVisibilities() { - for (int i = 0; i < this.ommcOptions.allKeyBindings.length; ++i) { + for (int i = 0; i < FeatureToggle.values().length; ++i) { ((GuiButton) this.buttonList.get(i)).drawButton = this.isKeybindButtonVisible(i); } } @@ -49,28 +48,28 @@ private boolean isKeybindButtonVisible(int index) { } protected void actionPerformed(GuiButton par1GuiButton) { - for (int var2 = 0; var2 < this.ommcOptions.allKeyBindings.length; ++var2) { - ((GuiButton) this.buttonList.get(var2)).displayString = this.ommcOptions.allKeyBindings[var2].keyDescription; + for (int var2 = 0; var2 < FeatureToggle.values().length; ++var2) { + ((GuiButton) this.buttonList.get(var2)).displayString = FeatureToggle.values()[var2].getKeybind().keyDescription; } if (par1GuiButton.id == 200) { this.mc.displayGuiScreen(this.parentScreen); } else if (par1GuiButton.id == 201) { - if (++this.page_index > (this.ommcOptions.allKeyBindings.length - 1) / 10) { + if (++this.page_index > (FeatureToggle.values().length - 1) / 10) { this.page_index = 0; } this.setKeybindButtonVisibilities(); } else { this.buttonId = par1GuiButton.id; - par1GuiButton.displayString = "> " + this.ommcOptions.getOptionDisplayString(par1GuiButton.id) + " <"; + par1GuiButton.displayString = "> " + getOptionDisplayString(par1GuiButton.id) + " <"; } } protected void mouseClicked(int par1, int par2, int par3) { if (this.buttonId >= 0) { - this.ommcOptions.setKeyBinding(this.buttonId, -100 + par3); - ((GuiButton) this.buttonList.get(this.buttonId)).displayString = this.ommcOptions.getOptionDisplayString(this.buttonId); + setKeyBinding(this.buttonId, -100 + par3); + ((GuiButton) this.buttonList.get(this.buttonId)).displayString = getOptionDisplayString(this.buttonId); this.buttonId = -1; KeyBinding.resetKeyBindingArrayAndHash(); } else { @@ -80,8 +79,8 @@ protected void mouseClicked(int par1, int par2, int par3) { protected void keyTyped(char par1, int par2) { if (this.buttonId >= 0) { - this.ommcOptions.setKeyBinding(this.buttonId, par2); - ((GuiButton) this.buttonList.get(this.buttonId)).displayString = this.ommcOptions.getOptionDisplayString(this.buttonId); + setKeyBinding(this.buttonId, par2); + ((GuiButton) this.buttonList.get(this.buttonId)).displayString = getOptionDisplayString(this.buttonId); this.buttonId = -1; KeyBinding.resetKeyBindingArrayAndHash(); } else { @@ -94,21 +93,21 @@ public void drawScreen(int par1, int par2, float par3) { this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 20, 16777215); int var5 = 0; - while (var5 < this.ommcOptions.allKeyBindings.length) { + while (var5 < FeatureToggle.values().length) { if (!this.isKeybindButtonVisible(var5)) { ++var5; } else { boolean var6 = false; - for (int var7 = 0; var7 < this.ommcOptions.allKeyBindings.length; ++var7) { - if (var7 != var5 && this.ommcOptions.allKeyBindings[var5].keyCode == this.ommcOptions.allKeyBindings[var7].keyCode) { + for (int var7 = 0; var7 < FeatureToggle.values().length; ++var7) { + if (var7 != var5 && FeatureToggle.values()[var5].getKeybind().keyCode == FeatureToggle.values()[var7].getKeybind().keyCode) { var6 = true; break; } } for (int var7 = 0; var7 < this.mc.gameSettings.keyBindings.length; ++var7) { - if (this.ommcOptions.allKeyBindings[var5].keyCode == this.mc.gameSettings.keyBindings[var7].keyCode) { + if (FeatureToggle.values()[var5].getKeybind().keyCode == this.mc.gameSettings.keyBindings[var7].keyCode) { var6 = true; break; } @@ -117,16 +116,35 @@ public void drawScreen(int par1, int par2, float par3) { if (this.buttonId == var5) { ((GuiButton) this.buttonList.get(var5)).displayString = "" + EnumChatFormatting.WHITE + "> " + EnumChatFormatting.YELLOW + "??? " + EnumChatFormatting.WHITE + "<"; } else if (var6) { - ((GuiButton) this.buttonList.get(var5)).displayString = EnumChatFormatting.RED + this.ommcOptions.getOptionDisplayString(var5); + ((GuiButton) this.buttonList.get(var5)).displayString = EnumChatFormatting.RED + getOptionDisplayString(var5); } else { - ((GuiButton) this.buttonList.get(var5)).displayString = this.ommcOptions.getOptionDisplayString(var5); + ((GuiButton) this.buttonList.get(var5)).displayString = getOptionDisplayString(var5); } - this.drawString(this.fontRenderer, this.ommcOptions.getKeyBindingDescription(var5), this.getKeybindButtonPosX(var5) + 70 + 6, this.getKeybindButtonPosY(var5) + 7, -1); + this.drawString(this.fontRenderer, getKeyBindingDescription(var5), this.getKeybindButtonPosX(var5) + 70 + 6, this.getKeybindButtonPosY(var5) + 7, -1); ++var5; } } super.drawScreen(par1, par2, par3); } + + public void setKeyBinding(int par1, int par2) { + FeatureToggle.values()[par1].getKeybind().keyCode = par2; + FeatureToggle.saveOptions(); + } + + public String getOptionDisplayString(int par1) { + int var2 = FeatureToggle.values()[par1].getKeybind().keyCode; + return getKeyDisplayString(var2); + } + + public static String getKeyDisplayString(int par0) { + return Keyboard.getKeyName(par0); + } + + public String getKeyBindingDescription(int par1) { + return I18n.getString(FeatureToggle.values()[par1].getKeybind().keyDescription); + } } + diff --git a/src/com/github/Debris/oh_my_mite_client/config/OMMCOptions.java b/src/com/github/Debris/oh_my_mite_client/config/OMMCOptions.java deleted file mode 100644 index b9ee25e..0000000 --- a/src/com/github/Debris/oh_my_mite_client/config/OMMCOptions.java +++ /dev/null @@ -1,114 +0,0 @@ -package com.github.Debris.oh_my_mite_client.config; - -import net.minecraft.I18n; -import net.minecraft.KeyBinding; -import org.lwjgl.input.Keyboard; - -import java.io.*; -import java.util.Arrays; -import java.util.stream.Stream; - -public class OMMCOptions { - private final File optionsFile; - public int gameMode = 0; - public KeyBindingBoolean keyBindAutoForward = new KeyBindingBoolean("自动前进", 200, false); - public KeyBindingBoolean keyBindAutoLeft = new KeyBindingBoolean("自动向左", 203, false); - public KeyBindingBoolean keyBindAutoBack = new KeyBindingBoolean("自动后退", 208, false); - public KeyBindingBoolean keyBindAutoRight = new KeyBindingBoolean("自动向右", 205, false); - public KeyBindingBoolean keyBindAutojump = new KeyBindingBoolean("自动跳跃", 0, false); - public KeyBindingBoolean keyBindAutoSneak = new KeyBindingBoolean("自动潜行", 0, false); - public KeyBindingBoolean keyBindAutoAttack = new KeyBindingBoolean("自动攻击", 36, false);//J - public KeyBindingBoolean keyBindHoldUse = new KeyBindingBoolean("长按右键", 22, false);//U - public KeyBindingBoolean keyBindAutoCraft = new KeyBindingBoolean("自动合成", 0, false); - public KeyBinding keyBindCopyTP = new KeyBinding("复制tp坐标", 46);//C - public KeyBinding keyBindToggleMode = new KeyBinding("切换游戏模式", 62);//F4 - - public KeyBindingBoolean[] keyBindingBooleans; - public KeyBinding[] keyBindingTriggers; - public KeyBinding[] allKeyBindings; - - public OMMCOptions(File file) { - this.initKeybindings(); - this.optionsFile = new File(file, "OMMCoptions.txt"); - this.loadOptions(); - } - - public void initKeybindings() { - this.keyBindingBooleans = new KeyBindingBoolean[]{ - keyBindAutoForward, - keyBindAutoLeft, - keyBindAutoBack, - keyBindAutoRight, - keyBindAutojump, - keyBindAutoSneak, - keyBindAutoAttack, - keyBindHoldUse, - keyBindAutoCraft - }; - - this.keyBindingTriggers = new KeyBinding[]{ - keyBindCopyTP, - keyBindToggleMode - }; - - Stream stream1 = Arrays.stream(this.keyBindingBooleans); - Stream stream2 = Arrays.stream(this.keyBindingTriggers); - - this.allKeyBindings = Stream.concat(stream1, stream2).toArray(KeyBinding[]::new); - } - - public void setKeyBinding(int par1, int par2) { - this.allKeyBindings[par1].keyCode = par2; - this.saveOptions(); - } - - public void loadOptions() { - BufferedReader var1; - try { - if (!this.optionsFile.exists()) { - return; - } - var1 = new BufferedReader(new FileReader(this.optionsFile)); - String var2; - while ((var2 = var1.readLine()) != null) { - String[] var3 = var2.split(":"); - for (int var4 = 0; var4 < this.allKeyBindings.length; ++var4) { - if (var3[0].equals("key_" + this.allKeyBindings[var4].keyDescription)) { - this.allKeyBindings[var4].keyCode = Integer.parseInt(var3[1]); - } - } - } - KeyBinding.resetKeyBindingArrayAndHash(); - var1.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - } - - public void saveOptions() { - PrintWriter var1; - try { - var1 = new PrintWriter(new FileWriter(this.optionsFile)); - for (int var2 = 0; var2 < this.allKeyBindings.length; ++var2) { - var1.println("key_" + this.allKeyBindings[var2].keyDescription + ":" + this.allKeyBindings[var2].keyCode); - } - var1.close(); - } catch (IOException e) { - throw new RuntimeException(e); - } - - } - - public String getOptionDisplayString(int par1) { - int var2 = this.allKeyBindings[par1].keyCode; - return getKeyDisplayString(var2); - } - - public static String getKeyDisplayString(int par0) { - return Keyboard.getKeyName(par0); - } - - public String getKeyBindingDescription(int par1) { - return I18n.getString(this.allKeyBindings[par1].keyDescription); - } -} diff --git a/src/com/github/Debris/oh_my_mite_client/config/TriggerHandler.java b/src/com/github/Debris/oh_my_mite_client/config/TriggerHandler.java new file mode 100644 index 0000000..ab76088 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/config/TriggerHandler.java @@ -0,0 +1,36 @@ +package com.github.Debris.oh_my_mite_client.config; + +import net.minecraft.GuiChat; +import net.minecraft.Minecraft; + +import java.awt.*; +import java.awt.datatransfer.Clipboard; +import java.awt.datatransfer.StringSelection; + +public class TriggerHandler { + + private static final TriggerHandler INSTANCE = new TriggerHandler(); + + public static TriggerHandler getInstance() { + return INSTANCE; + } + + public void handle(FeatureToggle featureToggle, Minecraft minecraft) { + switch (featureToggle) { + case Tweak_CopyTP: { + Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); + String content = "/tp " + minecraft.thePlayer.posX + " " + minecraft.thePlayer.posY + " " + minecraft.thePlayer.posZ; + StringSelection selection = new StringSelection(content); + clipboard.setContents(selection, null); + return; + } + case Tweak_ToggleMode: { + int mode = Config.gameMode ^= 1; + minecraft.openChat(new GuiChat("/gamemode " + mode)); + return; + } + default: { + } + } + } +} diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCCraftingMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCCraftingMixin.java index 9de432f..e5c1695 100644 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCCraftingMixin.java +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCCraftingMixin.java @@ -10,6 +10,6 @@ public class OMMCCraftingMixin { @Inject(method = "onUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/NetClientHandler;addToSendQueue(Lnet/minecraft/Packet;)V")) private void inject(CallbackInfo ci) { - +//TODO } } diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCEntityMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCEntityMixin.java new file mode 100644 index 0000000..f790f2d --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCEntityMixin.java @@ -0,0 +1,19 @@ +package com.github.Debris.oh_my_mite_client.mixins; + +import com.github.Debris.oh_my_mite_client.config.FeatureToggle; +import net.minecraft.Entity; +import net.minecraft.EntityPlayer; +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; + +@Mixin(Entity.class) +public class OMMCEntityMixin { + @Inject(method = "isInvisibleToPlayer", at = @At("HEAD"), cancellable = true) + private void overrideInsivible(EntityPlayer par1EntityPlayer, CallbackInfoReturnable cir) { + if (FeatureToggle.Tweak_RenderEntities.getBooleanValue()) { + cir.setReturnValue(true);//TODO + } + } +} diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGameSettingsMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGameSettingsMixin.java index 06b3b48..dbf41bd 100644 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGameSettingsMixin.java +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGameSettingsMixin.java @@ -1,11 +1,9 @@ package com.github.Debris.oh_my_mite_client.mixins; -import com.github.Debris.oh_my_mite_client.config.OMMCOptions; -import com.github.Debris.oh_my_mite_client.config.FieldAccessor; +import com.github.Debris.oh_my_mite_client.config.FeatureToggle; import net.minecraft.GameSettings; import net.minecraft.Minecraft; import org.spongepowered.asm.mixin.Mixin; -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.callback.CallbackInfo; @@ -13,18 +11,11 @@ import java.io.File; @Mixin(GameSettings.class) -public class OMMCGameSettingsMixin implements FieldAccessor { - - @Unique - OMMCOptions ohMyMiteClient$OMMCOptions; - +public class OMMCGameSettingsMixin { @Inject(method = "(Lnet/minecraft/Minecraft;Ljava/io/File;)V", at = @At("TAIL")) private void loadOMMCOptions(Minecraft par1Minecraft, File par2File, CallbackInfo ci) { - this.ohMyMiteClient$OMMCOptions = new OMMCOptions(par2File); - } - - @Override - public OMMCOptions OMMCOptionsProvider() { - return this.ohMyMiteClient$OMMCOptions; + FeatureToggle.setPath(par2File); + FeatureToggle.loadOptions(); + FeatureToggle.saveOptions(); } } diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMinecraftMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMinecraftMixin.java index c63c9b8..b6c7924 100644 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMinecraftMixin.java +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMinecraftMixin.java @@ -1,26 +1,20 @@ package com.github.Debris.oh_my_mite_client.mixins; import com.github.Debris.oh_my_mite_client.config.Config; -import com.github.Debris.oh_my_mite_client.config.KeyBindingBoolean; -import com.github.Debris.oh_my_mite_client.config.FieldAccessor; -import net.minecraft.*; +import com.github.Debris.oh_my_mite_client.config.FeatureToggle; +import com.github.Debris.oh_my_mite_client.config.TriggerHandler; +import net.minecraft.EntityClientPlayerMP; +import net.minecraft.Minecraft; 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.callback.CallbackInfo; -import java.awt.*; -import java.awt.datatransfer.Clipboard; -import java.awt.datatransfer.StringSelection; - import static net.minecraft.Minecraft.getSystemTime; @Mixin(Minecraft.class) public abstract class OMMCMinecraftMixin { - @Shadow - public GameSettings gameSettings; - @Shadow protected abstract void clickMouse(int button); @@ -28,28 +22,32 @@ public abstract class OMMCMinecraftMixin { public EntityClientPlayerMP thePlayer; @Shadow - public abstract void openChat(GuiChat gui_chat); + public static Minecraft getMinecraft() { + return null; + } @Inject(method = "runTick", at = @At("TAIL")) private void inject(CallbackInfo ci) { - for (KeyBindingBoolean key : ((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindingBooleans) { - if (key.isPressed()) key.invert(); + for (FeatureToggle value : FeatureToggle.values()) { + if (value.isTrigger()) { + if (value.getKeybind().isPressed()) { + TriggerHandler.getInstance().handle(value, getMinecraft()); + } + } else { + if (value.getKeybind().isPressed()) { + value.invert(); + String message = String.format("功能 %s 已切换为: %s", value.getKeybind().keyDescription, value.getBooleanValue() ? "开" : "关"); + this.thePlayer.addChatMessage(message); + } + } } - if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindCopyTP.isPressed()) { - Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard(); - String content = "/tp " + thePlayer.posX + " " + thePlayer.posY + " " + thePlayer.posZ; - StringSelection selection = new StringSelection(content); - clipboard.setContents(selection, null); - } - if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindToggleMode.isPressed()) { - int mode = ((FieldAccessor) this.gameSettings).OMMCOptionsProvider().gameMode ^= 1; - this.openChat(new GuiChat("/gamemode " + mode)); - } - if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutoAttack.getBoolean() && + + + if (FeatureToggle.Tweak_AutoAttack.getBooleanValue() && (getSystemTime() % Config.ATTACK_INTERVAL.get()) <= 50) { this.clickMouse(0); } - if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindHoldUse.getBoolean()) { + if (FeatureToggle.Tweak_HoldUse.getBooleanValue()) { this.clickMouse(1); } } diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMovementMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMovementMixin.java index 85490d9..870f66e 100644 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMovementMixin.java +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMovementMixin.java @@ -1,38 +1,33 @@ package com.github.Debris.oh_my_mite_client.mixins; -import com.github.Debris.oh_my_mite_client.config.FieldAccessor; -import net.minecraft.GameSettings; +import com.github.Debris.oh_my_mite_client.config.FeatureToggle; import net.minecraft.MovementInput; import net.minecraft.MovementInputFromOptions; 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.callback.CallbackInfo; @Mixin(MovementInputFromOptions.class) public abstract class OMMCMovementMixin extends MovementInput { - @Shadow - private GameSettings gameSettings; - @Inject(method = "updatePlayerMoveState", at = @At("TAIL")) private void inject(CallbackInfo ci) { - if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutoForward.getBoolean()) { + if (FeatureToggle.Tweak_AutoForward.getBooleanValue()) { this.moveForward = 1.0F; } - if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutoLeft.getBoolean()) { + if (FeatureToggle.Tweak_AutoLeft.getBooleanValue()) { this.moveStrafe = 1.0F; } - if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutoBack.getBoolean()) { + if (FeatureToggle.Tweak_AutoBack.getBooleanValue()) { this.moveForward = -1.0F; } - if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutoRight.getBoolean()) { + if (FeatureToggle.Tweak_AutoRight.getBooleanValue()) { this.moveStrafe = -1.0F; } - if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutojump.getBoolean()) { + if (FeatureToggle.Tweak_Autojump.getBooleanValue()) { this.jump = true; } - if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutoSneak.getBoolean()) { + if (FeatureToggle.Tweak_AutoSneak.getBooleanValue()) { this.sneak = true; } } diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCPlayerAbilitiesMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCPlayerAbilitiesMixin.java new file mode 100644 index 0000000..e6fb358 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCPlayerAbilitiesMixin.java @@ -0,0 +1,19 @@ +package com.github.Debris.oh_my_mite_client.mixins; + +import com.github.Debris.oh_my_mite_client.config.Config; +import com.github.Debris.oh_my_mite_client.config.FeatureToggle; +import net.minecraft.PlayerCapabilities; +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; + +@Mixin(PlayerCapabilities.class) +public class OMMCPlayerAbilitiesMixin { + @Inject(method = "getFlySpeed", at = @At("HEAD"), cancellable = true) + private void inject(CallbackInfoReturnable cir) { + if (FeatureToggle.Tweak_FastFlying.getBooleanValue()) { + cir.setReturnValue(Config.FLYING_SPEED.get()); + } + } +} diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiControlsMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiControlsMixin.java similarity index 94% rename from src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiControlsMixin.java rename to src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiControlsMixin.java index 8310c23..1523eda 100644 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiControlsMixin.java +++ b/src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiControlsMixin.java @@ -1,4 +1,4 @@ -package com.github.Debris.oh_my_mite_client.mixins; +package com.github.Debris.oh_my_mite_client.mixins.gui; import net.minecraft.*; import org.spongepowered.asm.mixin.Mixin; diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiOptionsMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiOptionsMixin.java similarity index 75% rename from src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiOptionsMixin.java rename to src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiOptionsMixin.java index beb71b4..3870be6 100644 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiOptionsMixin.java +++ b/src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiOptionsMixin.java @@ -1,7 +1,6 @@ -package com.github.Debris.oh_my_mite_client.mixins; +package com.github.Debris.oh_my_mite_client.mixins.gui; import com.github.Debris.oh_my_mite_client.config.OMMCGuiControls; -import com.github.Debris.oh_my_mite_client.config.FieldAccessor; import net.minecraft.GuiButton; import net.minecraft.GuiOptions; import net.minecraft.GuiScreen; @@ -14,7 +13,7 @@ public abstract class OMMCGuiOptionsMixin extends GuiScreen { @Inject(method = "initGui", at = @At("TAIL")) private void registerButton(CallbackInfo ci) { - this.buttonList.add(new GuiButton(111, this.width / 2 + 2, this.height / 6 + 72 - 6, 150, 20, "OMMC")); + this.buttonList.add(new GuiButton(111, this.width / 2 + 2, this.height / 6 + 72 - 6, 150, 20, "OMMC按键设置")); } @Inject(method = "actionPerformed", at = @At("TAIL")) @@ -22,8 +21,7 @@ private void onClick(GuiButton par1GuiButton, CallbackInfo ci) { if (par1GuiButton.enabled) { if (par1GuiButton.id == 111) { this.mc.gameSettings.saveOptions(); - ((FieldAccessor) this.mc.gameSettings).OMMCOptionsProvider().saveOptions(); - this.mc.displayGuiScreen(new OMMCGuiControls(this, ((FieldAccessor) this.mc.gameSettings).OMMCOptionsProvider())); + this.mc.displayGuiScreen(new OMMCGuiControls(this)); } } }