From b133713547a573c61a56dfc106420232f8f65e59 Mon Sep 17 00:00:00 2001 From: De6ris <2838369930@qq.com> Date: Sun, 17 Mar 2024 15:13:10 +0800 Subject: [PATCH] Initial Commit --- .gitignore | 4 + .../oh_my_mite_client/EventListener.java | 17 +++ .../oh_my_mite_client/OhMyMiteClient.java | 57 ++++++++ .../oh_my_mite_client/config/Config.java | 12 ++ .../config/FieldAccessor.java | 7 + .../config/KeyBindingBoolean.java | 21 +++ .../config/OMMCGuiControls.java | 132 ++++++++++++++++++ .../oh_my_mite_client/config/OMMCOptions.java | 114 +++++++++++++++ .../oh_my_mite_client/mixins/MixinMarker.java | 4 + .../mixins/OMMCCraftingMixin.java | 15 ++ .../mixins/OMMCGameSettingsMixin.java | 30 ++++ .../mixins/OMMCGuiControlsMixin.java | 24 ++++ .../mixins/OMMCGuiOptionsMixin.java | 30 ++++ .../mixins/OMMCMinecraftMixin.java | 57 ++++++++ .../mixins/OMMCMovementMixin.java | 39 ++++++ src/mod.json | 3 + 16 files changed, 566 insertions(+) create mode 100644 src/com/github/Debris/oh_my_mite_client/EventListener.java create mode 100644 src/com/github/Debris/oh_my_mite_client/OhMyMiteClient.java create mode 100644 src/com/github/Debris/oh_my_mite_client/config/Config.java create mode 100644 src/com/github/Debris/oh_my_mite_client/config/FieldAccessor.java create mode 100644 src/com/github/Debris/oh_my_mite_client/config/KeyBindingBoolean.java create mode 100644 src/com/github/Debris/oh_my_mite_client/config/OMMCGuiControls.java create mode 100644 src/com/github/Debris/oh_my_mite_client/config/OMMCOptions.java create mode 100644 src/com/github/Debris/oh_my_mite_client/mixins/MixinMarker.java create mode 100644 src/com/github/Debris/oh_my_mite_client/mixins/OMMCCraftingMixin.java create mode 100644 src/com/github/Debris/oh_my_mite_client/mixins/OMMCGameSettingsMixin.java create mode 100644 src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiControlsMixin.java create mode 100644 src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiOptionsMixin.java create mode 100644 src/com/github/Debris/oh_my_mite_client/mixins/OMMCMinecraftMixin.java create mode 100644 src/com/github/Debris/oh_my_mite_client/mixins/OMMCMovementMixin.java create mode 100644 src/mod.json diff --git a/.gitignore b/.gitignore index 524f096..73445bd 100644 --- a/.gitignore +++ b/.gitignore @@ -22,3 +22,7 @@ # virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml hs_err_pid* replay_pid* +*.iml +/.idea +/src/META-INF +/out diff --git a/src/com/github/Debris/oh_my_mite_client/EventListener.java b/src/com/github/Debris/oh_my_mite_client/EventListener.java new file mode 100644 index 0000000..efca6a5 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/EventListener.java @@ -0,0 +1,17 @@ +package com.github.Debris.oh_my_mite_client; + +import com.google.common.eventbus.Subscribe; +import net.xiaoyu233.fml.reload.event.PlayerLoggedInEvent; + +import static com.github.Debris.oh_my_mite_client.OhMyMiteClient.MOD_ID; + +public class EventListener { + public EventListener() { + } + + @Subscribe + public void onPlayerLoggedIn(PlayerLoggedInEvent event) { + String message = String.format("§f[Debris]:§r§b%s 已加载§r", MOD_ID); + event.getPlayer().addChatMessage(message); + } +} diff --git a/src/com/github/Debris/oh_my_mite_client/OhMyMiteClient.java b/src/com/github/Debris/oh_my_mite_client/OhMyMiteClient.java new file mode 100644 index 0000000..5c888b7 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/OhMyMiteClient.java @@ -0,0 +1,57 @@ +package com.github.Debris.oh_my_mite_client; + +import com.github.Debris.oh_my_mite_client.config.Config; +import com.github.Debris.oh_my_mite_client.mixins.MixinMarker; +import net.xiaoyu233.fml.AbstractMod; +import net.xiaoyu233.fml.classloading.Mod; +import net.xiaoyu233.fml.config.ConfigRegistry; +import net.xiaoyu233.fml.config.InjectionConfig; +import net.xiaoyu233.fml.reload.event.MITEEvents; +import org.spongepowered.asm.mixin.MixinEnvironment; + +import javax.annotation.Nonnull; +import java.io.File; + +@Mod({MixinEnvironment.Side.CLIENT}) +public class OhMyMiteClient extends AbstractMod { + + public static final String MOD_ID = "OhMyMiteClient"; + + private static final ConfigRegistry CONFIG_REGISTRY = new ConfigRegistry(Config.ROOT, new File(MOD_ID + ".json")); + + + @Override + public void preInit() { + } + + @Nonnull + @Override + public InjectionConfig getInjectionConfig() { + return InjectionConfig.Builder.of(MOD_ID, MixinMarker.class.getPackage(), MixinEnvironment.Phase.INIT).setRequired().build(); + } + + @Override + public String modId() { + return MOD_ID; + } + + @Override + public int modVerNum() { + return 10; + } + + @Override + public String modVerStr() { + return "v1.0"; + } + + @Override + public void postInit() { + MITEEvents.MITE_EVENT_BUS.register(new EventListener()); + } + + @Override + public ConfigRegistry getConfigRegistry() { + return CONFIG_REGISTRY; + } +} 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 new file mode 100644 index 0000000..888e60f --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/config/Config.java @@ -0,0 +1,12 @@ +package com.github.Debris.oh_my_mite_client.config; + +import net.xiaoyu233.fml.config.ConfigCategory; +import net.xiaoyu233.fml.config.ConfigEntry; +import net.xiaoyu233.fml.util.FieldReference; + +public class Config { + public static final FieldReference ATTACK_INTERVAL = new FieldReference<>(500); + + public static final ConfigCategory ROOT = ConfigCategory.of("NoClickCD") + .addEntry(ConfigEntry.of("auto_attack_interval", ATTACK_INTERVAL).withComment("自动攻击间隔, 单位毫秒")); +} 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 new file mode 100644 index 0000000..7a2175a --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/config/FieldAccessor.java @@ -0,0 +1,7 @@ +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/KeyBindingBoolean.java b/src/com/github/Debris/oh_my_mite_client/config/KeyBindingBoolean.java new file mode 100644 index 0000000..8327a29 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/config/KeyBindingBoolean.java @@ -0,0 +1,21 @@ +package com.github.Debris.oh_my_mite_client.config; + +import net.minecraft.KeyBinding; + +public class KeyBindingBoolean extends KeyBinding { + + private boolean value; + + public KeyBindingBoolean(String s, int i, boolean defaultValue) { + super(s, i); + this.value = defaultValue; + } + + public boolean getBoolean() { + return this.value; + } + + public void invert() { + this.value = !this.value; + } +} 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 new file mode 100644 index 0000000..9b25368 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/config/OMMCGuiControls.java @@ -0,0 +1,132 @@ +package com.github.Debris.oh_my_mite_client.config; + +import net.minecraft.*; + +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) { + this.parentScreen = par1GuiScreen; + this.ommcOptions = par2GameSettings; + } + + private int getLeftBorder() { + return this.width / 2 - 155; + } + + private int getKeybindButtonPosX(int index) { + index %= 10; + return this.getLeftBorder() + index % 2 * 160; + } + + private int getKeybindButtonPosY(int index) { + index %= 10; + return this.height / 6 + 24 * (index / 2) + 6; + } + + @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)); + } + this.setKeybindButtonVisibilities(); + this.buttonList.add(new GuiButton(201, this.width / 2 - 100, this.height / 6 + 168 - 24, I18n.getString("gui.nextPage"))); + this.buttonList.add(new GuiButton(200, this.width / 2 - 100, this.height / 6 + 168, I18n.getString("gui.done"))); + } + + private void setKeybindButtonVisibilities() { + for (int i = 0; i < this.ommcOptions.allKeyBindings.length; ++i) { + ((GuiButton) this.buttonList.get(i)).drawButton = this.isKeybindButtonVisible(i); + } + } + + private boolean isKeybindButtonVisible(int index) { + return index >= this.page_index * 10 && index < (this.page_index + 1) * 10; + } + + 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; + } + + if (par1GuiButton.id == 200) { + this.mc.displayGuiScreen(this.parentScreen); + } else if (par1GuiButton.id == 201) { + if (++this.page_index > (this.ommcOptions.allKeyBindings.length - 1) / 10) { + this.page_index = 0; + } + + this.setKeybindButtonVisibilities(); + } else { + this.buttonId = par1GuiButton.id; + par1GuiButton.displayString = "> " + this.ommcOptions.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); + this.buttonId = -1; + KeyBinding.resetKeyBindingArrayAndHash(); + } else { + super.mouseClicked(par1, par2, 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); + this.buttonId = -1; + KeyBinding.resetKeyBindingArrayAndHash(); + } else { + super.keyTyped(par1, par2); + } + } + + public void drawScreen(int par1, int par2, float par3) { + this.drawDefaultBackground(); + this.drawCenteredString(this.fontRenderer, this.screenTitle, this.width / 2, 20, 16777215); + int var5 = 0; + + while (var5 < this.ommcOptions.allKeyBindings.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) { + 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) { + var6 = true; + break; + } + } + + 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); + } else { + ((GuiButton) this.buttonList.get(var5)).displayString = this.ommcOptions.getOptionDisplayString(var5); + } + + this.drawString(this.fontRenderer, this.ommcOptions.getKeyBindingDescription(var5), this.getKeybindButtonPosX(var5) + 70 + 6, this.getKeybindButtonPosY(var5) + 7, -1); + ++var5; + } + } + + super.drawScreen(par1, par2, par3); + } +} 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 new file mode 100644 index 0000000..b9ee25e --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/config/OMMCOptions.java @@ -0,0 +1,114 @@ +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/mixins/MixinMarker.java b/src/com/github/Debris/oh_my_mite_client/mixins/MixinMarker.java new file mode 100644 index 0000000..fe86c8f --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/MixinMarker.java @@ -0,0 +1,4 @@ +package com.github.Debris.oh_my_mite_client.mixins; + +public class MixinMarker { +} 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 new file mode 100644 index 0000000..9de432f --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCCraftingMixin.java @@ -0,0 +1,15 @@ +package com.github.Debris.oh_my_mite_client.mixins; + +import net.minecraft.MITEContainerCrafting; +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.CallbackInfo; + +@Mixin(MITEContainerCrafting.class) +public class OMMCCraftingMixin { + @Inject(method = "onUpdate", at = @At(value = "INVOKE", target = "Lnet/minecraft/NetClientHandler;addToSendQueue(Lnet/minecraft/Packet;)V")) + private void inject(CallbackInfo ci) { + + } +} 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 new file mode 100644 index 0000000..06b3b48 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGameSettingsMixin.java @@ -0,0 +1,30 @@ +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 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; + +import java.io.File; + +@Mixin(GameSettings.class) +public class OMMCGameSettingsMixin implements FieldAccessor { + + @Unique + OMMCOptions ohMyMiteClient$OMMCOptions; + + @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; + } +} diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiControlsMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiControlsMixin.java new file mode 100644 index 0000000..8310c23 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiControlsMixin.java @@ -0,0 +1,24 @@ +package com.github.Debris.oh_my_mite_client.mixins; + +import net.minecraft.*; +import org.spongepowered.asm.mixin.Mixin; + +@Mixin(GuiControls.class) +public abstract class OMMCGuiControlsMixin extends GuiScreen { +// @Shadow +// private GameSettings options; +// +// @Inject(method = "drawScreen", at = @At(value = "INVOKE", target = "Lnet/minecraft/GuiControls;drawString(Lnet/minecraft/FontRenderer;Ljava/lang/String;III)V"), locals = LocalCapture.CAPTURE_FAILSOFT) +// private void inject(int var5) { +// boolean conflict = false; +// for (int var7 = 0; var7 < ((FieldAccessor) this).OMMCOptionsProvider().allKeyBindings.length; ++var7) { +// if (this.options.keyBindings[var5].keyCode == ((FieldAccessor) this).OMMCOptionsProvider().allKeyBindings[var7].keyCode) { +// conflict = true; +// break; +// } +// } +// if (conflict) { +// ((GuiButton) this.buttonList.get(var5)).displayString = EnumChatFormatting.RED + this.options.getOptionDisplayString(var5); +// } +// } +} diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiOptionsMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiOptionsMixin.java new file mode 100644 index 0000000..beb71b4 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGuiOptionsMixin.java @@ -0,0 +1,30 @@ +package com.github.Debris.oh_my_mite_client.mixins; + +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; +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.CallbackInfo; + +@Mixin(GuiOptions.class) +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")); + } + + @Inject(method = "actionPerformed", at = @At("TAIL")) + 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())); + } + } + } +} 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 new file mode 100644 index 0000000..c63c9b8 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMinecraftMixin.java @@ -0,0 +1,57 @@ +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 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); + + @Shadow + public EntityClientPlayerMP thePlayer; + + @Shadow + public abstract void openChat(GuiChat gui_chat); + + @Inject(method = "runTick", at = @At("TAIL")) + private void inject(CallbackInfo ci) { + for (KeyBindingBoolean key : ((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindingBooleans) { + if (key.isPressed()) key.invert(); + } + 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() && + (getSystemTime() % Config.ATTACK_INTERVAL.get()) <= 50) { + this.clickMouse(0); + } + if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindHoldUse.getBoolean()) { + 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 new file mode 100644 index 0000000..85490d9 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMovementMixin.java @@ -0,0 +1,39 @@ +package com.github.Debris.oh_my_mite_client.mixins; + +import com.github.Debris.oh_my_mite_client.config.FieldAccessor; +import net.minecraft.GameSettings; +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()) { + this.moveForward = 1.0F; + } + if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutoLeft.getBoolean()) { + this.moveStrafe = 1.0F; + } + if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutoBack.getBoolean()) { + this.moveForward = -1.0F; + } + if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutoRight.getBoolean()) { + this.moveStrafe = -1.0F; + } + if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutojump.getBoolean()) { + this.jump = true; + } + if (((FieldAccessor) this.gameSettings).OMMCOptionsProvider().keyBindAutoSneak.getBoolean()) { + this.sneak = true; + } + } +} diff --git a/src/mod.json b/src/mod.json new file mode 100644 index 0000000..f3bde5e --- /dev/null +++ b/src/mod.json @@ -0,0 +1,3 @@ +{ + "mod": "com.github.Debris.oh_my_mite_client.OhMyMiteClient" +}