diff --git a/changeLogs/v1.0.md b/changeLogs/v1.0.md new file mode 100644 index 0000000..df947ef --- /dev/null +++ b/changeLogs/v1.0.md @@ -0,0 +1,22 @@ +# v1.0 + +### 进入游戏, 设置, OMMC按键设置, 即可查看菜单. + +--- + + +## 新功能 + +* 自动前进 +* 自动向左 +* 自动后退 +* 自动向后 +* 自动跳跃 +* 自动潜行 +* 自动攻击 +* 长按右键 +* 自动合成(开发中) +* 渲染实体(开发中) +* 快速飞行 +* 复制tp坐标 +* 切换游戏模式 \ No newline at end of file diff --git a/changeLogs/v1.1.md b/changeLogs/v1.1.md new file mode 100644 index 0000000..e385a63 --- /dev/null +++ b/changeLogs/v1.1.md @@ -0,0 +1,25 @@ +# v1.1 + +### 进入游戏, 设置, OMMC按键设置, 即可查看菜单. + +### 配置文件目录在 "configs/OMMCTweaks.json"(用于储存按键绑定) + +### 以及 "configs/OhMyMiteClient.json"(用于配置数值) + +--- + +## 通知 + +本模组将迁移至FML3.0.0, 这可能是FML2.0.0的最后一个版本 + +## 新功能 + +* 自动合成 +* 禁止渲染生物 + +## 更改 + +* 为*快速飞行*支持了升降速度 +* *渲染实体*功能开发完毕, 改名为*禁止渲染生物* +* 重构了配置系统, 现在退出游戏时会保留按键功能开启情况 +* 现在原版按键设置界面中, 如果与OMMC按键冲突也会标红了 \ No newline at end of file diff --git a/src/com/github/Debris/oh_my_mite_client/OhMyMiteClient.java b/src/com/github/Debris/oh_my_mite_client/OhMyMiteClient.java index 5c888b7..aac9e6f 100644 --- a/src/com/github/Debris/oh_my_mite_client/OhMyMiteClient.java +++ b/src/com/github/Debris/oh_my_mite_client/OhMyMiteClient.java @@ -1,6 +1,6 @@ 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.config.FishConfig; import com.github.Debris.oh_my_mite_client.mixins.MixinMarker; import net.xiaoyu233.fml.AbstractMod; import net.xiaoyu233.fml.classloading.Mod; @@ -17,7 +17,7 @@ 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")); + private static final ConfigRegistry CONFIG_REGISTRY = new ConfigRegistry(FishConfig.ROOT, new File(MOD_ID + ".json")); @Override diff --git a/src/com/github/Debris/oh_my_mite_client/config/ConfigUtils.java b/src/com/github/Debris/oh_my_mite_client/config/ConfigUtils.java new file mode 100644 index 0000000..ca114aa --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/config/ConfigUtils.java @@ -0,0 +1,28 @@ +package com.github.Debris.oh_my_mite_client.config; + +import com.google.gson.JsonObject; + +import java.util.List; + +public class ConfigUtils { + public static void readConfigBase(JsonObject root, String category, List options) { + JsonObject obj = JsonUtils.getNestedObject(root, category, false); + + if (obj != null) { + for (IConfigBase option : options) { + String name = option.getName(); + + if (obj.has(name)) { + option.setValueFromJsonElement(obj.get(name)); + } + } + } + } + + public static void writeConfigBase(JsonObject root, String category, List options) { + JsonObject obj = JsonUtils.getNestedObject(root, category, true); + for (TweakToggle option : options) { + obj.add(option.getName(), option.getAsJsonElement()); + } + } +} 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 deleted file mode 100644 index 82f5e65..0000000 --- a/src/com/github/Debris/oh_my_mite_client/config/FeatureToggle.java +++ /dev/null @@ -1,95 +0,0 @@ -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/Config.java b/src/com/github/Debris/oh_my_mite_client/config/FishConfig.java similarity index 52% rename from src/com/github/Debris/oh_my_mite_client/config/Config.java rename to src/com/github/Debris/oh_my_mite_client/config/FishConfig.java index 30cca3b..c2e53e0 100644 --- a/src/com/github/Debris/oh_my_mite_client/config/Config.java +++ b/src/com/github/Debris/oh_my_mite_client/config/FishConfig.java @@ -4,13 +4,15 @@ import net.xiaoyu233.fml.config.ConfigEntry; import net.xiaoyu233.fml.util.FieldReference; -public class Config { +public class FishConfig { public static final FieldReference ATTACK_INTERVAL = new FieldReference<>(500); - public static final FieldReference FLYING_SPEED = new FieldReference<>(0.99F); + public static final FieldReference FLYING_SPEED_LEVEL = new FieldReference<>(0.99F); + public static final FieldReference FLYING_SPEED_VERTICAL = new FieldReference<>(0.99F); public static int gameMode = 0; - public static final ConfigCategory ROOT = ConfigCategory.of("NoClickCD") + public static final ConfigCategory ROOT = ConfigCategory.of("OMMC") .addEntry(ConfigEntry.of("auto_attack_interval", ATTACK_INTERVAL).withComment("自动攻击间隔, 单位毫秒")) - .addEntry(ConfigEntry.of("flying_speed", FLYING_SPEED).withComment("飞行速度")); + .addEntry(ConfigEntry.of("flying_speed_level", FLYING_SPEED_LEVEL).withComment("水平飞行速度")) + .addEntry(ConfigEntry.of("flying_speed_vertical", FLYING_SPEED_LEVEL).withComment("竖直飞行速度")); } diff --git a/src/com/github/Debris/oh_my_mite_client/config/IConfigBase.java b/src/com/github/Debris/oh_my_mite_client/config/IConfigBase.java new file mode 100644 index 0000000..477eaef --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/config/IConfigBase.java @@ -0,0 +1,9 @@ +package com.github.Debris.oh_my_mite_client.config; + +import com.google.gson.JsonElement; + +public interface IConfigBase { + String getName(); + void setValueFromJsonElement(JsonElement element); + JsonElement getAsJsonElement(); +} diff --git a/src/com/github/Debris/oh_my_mite_client/config/JsonUtils.java b/src/com/github/Debris/oh_my_mite_client/config/JsonUtils.java new file mode 100644 index 0000000..68b0a90 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/config/JsonUtils.java @@ -0,0 +1,269 @@ +package com.github.Debris.oh_my_mite_client.config; + +import com.google.gson.*; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import java.io.File; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.util.Map; + +public class JsonUtils { + public static final Gson GSON = new GsonBuilder().setPrettyPrinting().create(); + + @Nullable + public static JsonObject getNestedObject(JsonObject parent, String key, boolean create) { + if (!parent.has(key) || !parent.get(key).isJsonObject()) { + if (!create) { + return null; + } + JsonObject obj = new JsonObject(); + parent.add(key, obj); + return obj; + } else { + return parent.get(key).getAsJsonObject(); + } + } + + public static boolean hasBoolean(JsonObject obj, String name) { + JsonElement el = obj.get(name); + + if (el != null && el.isJsonPrimitive()) { + try { + el.getAsBoolean(); + return true; + } catch (Exception ignore) { + } + } + + return false; + } + + public static boolean hasInteger(JsonObject obj, String name) { + JsonElement el = obj.get(name); + + if (el != null && el.isJsonPrimitive()) { + try { + el.getAsInt(); + return true; + } catch (Exception ignore) { + } + } + + return false; + } + + public static boolean hasLong(JsonObject obj, String name) { + JsonElement el = obj.get(name); + + if (el != null && el.isJsonPrimitive()) { + try { + el.getAsLong(); + return true; + } catch (Exception ignore) { + } + } + + return false; + } + + public static boolean hasFloat(JsonObject obj, String name) { + JsonElement el = obj.get(name); + + if (el != null && el.isJsonPrimitive()) { + try { + el.getAsFloat(); + return true; + } catch (Exception ignore) { + } + } + + return false; + } + + public static boolean hasDouble(JsonObject obj, String name) { + JsonElement el = obj.get(name); + + if (el != null && el.isJsonPrimitive()) { + try { + el.getAsDouble(); + return true; + } catch (Exception ignore) { + } + } + + return false; + } + + public static boolean hasString(JsonObject obj, String name) { + JsonElement el = obj.get(name); + + if (el != null && el.isJsonPrimitive()) { + try { + el.getAsString(); + return true; + } catch (Exception ignore) { + } + } + + return false; + } + + public static boolean hasObject(JsonObject obj, String name) { + JsonElement el = obj.get(name); + return el != null && el.isJsonObject(); + } + + public static boolean hasArray(JsonObject obj, String name) { + JsonElement el = obj.get(name); + return el != null && el.isJsonArray(); + } + + public static boolean getBooleanOrDefault(JsonObject obj, String name, boolean defaultValue) { + if (obj.has(name) && obj.get(name).isJsonPrimitive()) { + try { + return obj.get(name).getAsBoolean(); + } catch (Exception ignore) { + } + } + + return defaultValue; + } + + public static int getIntegerOrDefault(JsonObject obj, String name, int defaultValue) { + if (obj.has(name) && obj.get(name).isJsonPrimitive()) { + try { + return obj.get(name).getAsInt(); + } catch (Exception ignore) { + } + } + + return defaultValue; + } + + public static long getLongOrDefault(JsonObject obj, String name, long defaultValue) { + if (obj.has(name) && obj.get(name).isJsonPrimitive()) { + try { + return obj.get(name).getAsLong(); + } catch (Exception ignore) { + } + } + + return defaultValue; + } + + public static float getFloatOrDefault(JsonObject obj, String name, float defaultValue) { + if (obj.has(name) && obj.get(name).isJsonPrimitive()) { + try { + return obj.get(name).getAsFloat(); + } catch (Exception ignore) { + } + } + + return defaultValue; + } + + public static double getDoubleOrDefault(JsonObject obj, String name, double defaultValue) { + if (obj.has(name) && obj.get(name).isJsonPrimitive()) { + try { + return obj.get(name).getAsDouble(); + } catch (Exception ignore) { + } + } + + return defaultValue; + } + + public static String getStringOrDefault(JsonObject obj, String name, String defaultValue) { + if (obj.has(name) && obj.get(name).isJsonPrimitive()) { + try { + return obj.get(name).getAsString(); + } catch (Exception ignore) { + } + } + + return defaultValue; + } + + public static boolean getBoolean(JsonObject obj, String name) { + return getBooleanOrDefault(obj, name, false); + } + + public static int getInteger(JsonObject obj, String name) { + return getIntegerOrDefault(obj, name, 0); + } + + public static long getLong(JsonObject obj, String name) { + return getLongOrDefault(obj, name, 0); + } + + public static float getFloat(JsonObject obj, String name) { + return getFloatOrDefault(obj, name, 0); + } + + public static double getDouble(JsonObject obj, String name) { + return getDoubleOrDefault(obj, name, 0); + } + + @Nullable + public static String getString(JsonObject obj, String name) { + return getStringOrDefault(obj, name, null); + } + + @Nonnull + public static JsonObject deepCopy(@Nonnull JsonObject jsonObject) { + JsonObject result = new JsonObject(); + + for (Map.Entry entry : jsonObject.entrySet()) { + result.add(entry.getKey(), deepCopy(entry.getValue())); + } + + return result; + } + + @Nonnull + public static JsonArray deepCopy(@Nonnull JsonArray jsonArray) { + JsonArray result = new JsonArray(); + + for (JsonElement e : jsonArray) { + result.add(deepCopy(e)); + } + + return result; + } + + @Nonnull + public static JsonElement deepCopy(@Nonnull JsonElement jsonElement) { + if (jsonElement.isJsonPrimitive() || jsonElement.isJsonNull()) { + return jsonElement; // these are immutable anyway + } else if (jsonElement.isJsonObject()) { + return deepCopy(jsonElement.getAsJsonObject()); + } else if (jsonElement.isJsonArray()) { + return deepCopy(jsonElement.getAsJsonArray()); + } else { + throw new UnsupportedOperationException("Unsupported element: " + jsonElement); + } + } + + @Nullable + public static JsonElement parseJsonFile(File file) { + if (file != null && file.exists() && file.isFile() && file.canRead()) { + try (InputStreamReader reader = new InputStreamReader(Files.newInputStream(file.toPath()), StandardCharsets.UTF_8)) { + return new JsonParser().parse(reader); + } catch (Exception ignored) { + } + } + return null; + } + + public static void writeJsonToFile(JsonObject root, File file) { + try (OutputStreamWriter writer = new OutputStreamWriter(Files.newOutputStream(file.toPath()), StandardCharsets.UTF_8)) { + writer.write(GSON.toJson(root)); + } catch (Exception ignored) { + } + } +} + 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 deleted file mode 100644 index 8327a29..0000000 --- a/src/com/github/Debris/oh_my_mite_client/config/KeyBindingBoolean.java +++ /dev/null @@ -1,21 +0,0 @@ -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 index 94b843a..8508ac9 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 @@ -29,8 +29,8 @@ private int getKeybindButtonPosY(int index) { @Override public void initGui() { - 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)); + for (int var2 = 0; var2 < TweakToggle.VALUES.size(); ++var2) { + this.buttonList.add(new GuiSmallButton(var2, this.getKeybindButtonPosX(var2), this.getKeybindButtonPosY(var2), 70, 20, TweakToggle.VALUES.get(var2).getKeybind().keyDescription)); } this.setKeybindButtonVisibilities(); this.buttonList.add(new GuiButton(201, this.width / 2 - 100, this.height / 6 + 168 - 24, I18n.getString("gui.nextPage"))); @@ -38,7 +38,7 @@ public void initGui() { } private void setKeybindButtonVisibilities() { - for (int i = 0; i < FeatureToggle.values().length; ++i) { + for (int i = 0; i < TweakToggle.VALUES.size(); ++i) { ((GuiButton) this.buttonList.get(i)).drawButton = this.isKeybindButtonVisible(i); } } @@ -48,14 +48,14 @@ private boolean isKeybindButtonVisible(int index) { } protected void actionPerformed(GuiButton par1GuiButton) { - for (int var2 = 0; var2 < FeatureToggle.values().length; ++var2) { - ((GuiButton) this.buttonList.get(var2)).displayString = FeatureToggle.values()[var2].getKeybind().keyDescription; + for (int var2 = 0; var2 < TweakToggle.VALUES.size(); ++var2) { + ((GuiButton) this.buttonList.get(var2)).displayString = TweakToggle.VALUES.get(var2).getKeybind().keyDescription; } if (par1GuiButton.id == 200) { this.mc.displayGuiScreen(this.parentScreen); } else if (par1GuiButton.id == 201) { - if (++this.page_index > (FeatureToggle.values().length - 1) / 10) { + if (++this.page_index > (TweakToggle.VALUES.size() - 1) / 10) { this.page_index = 0; } @@ -93,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 < FeatureToggle.values().length) { + while (var5 < TweakToggle.VALUES.size()) { if (!this.isKeybindButtonVisible(var5)) { ++var5; } else { boolean var6 = false; - for (int var7 = 0; var7 < FeatureToggle.values().length; ++var7) { - if (var7 != var5 && FeatureToggle.values()[var5].getKeybind().keyCode == FeatureToggle.values()[var7].getKeybind().keyCode) { + for (int var7 = 0; var7 < TweakToggle.VALUES.size(); ++var7) { + if (var7 != var5 && TweakToggle.VALUES.get(var5).getKeybind().keyCode == TweakToggle.VALUES.get(var7).getKeybind().keyCode) { var6 = true; break; } } for (int var7 = 0; var7 < this.mc.gameSettings.keyBindings.length; ++var7) { - if (FeatureToggle.values()[var5].getKeybind().keyCode == this.mc.gameSettings.keyBindings[var7].keyCode) { + if (TweakToggle.VALUES.get(var5).getKeybind().keyCode == this.mc.gameSettings.keyBindings[var7].keyCode) { var6 = true; break; } @@ -130,12 +130,12 @@ public void drawScreen(int par1, int par2, float par3) { } public void setKeyBinding(int par1, int par2) { - FeatureToggle.values()[par1].getKeybind().keyCode = par2; - FeatureToggle.saveOptions(); + TweakToggle.VALUES.get(par1).getKeybind().keyCode = par2; + TweakToggle.save(); } public String getOptionDisplayString(int par1) { - int var2 = FeatureToggle.values()[par1].getKeybind().keyCode; + int var2 = TweakToggle.VALUES.get(par1).getKeybind().keyCode; return getKeyDisplayString(var2); } @@ -144,7 +144,7 @@ public static String getKeyDisplayString(int par0) { } public String getKeyBindingDescription(int par1) { - return I18n.getString(FeatureToggle.values()[par1].getKeybind().keyDescription); + return I18n.getString(TweakToggle.VALUES.get(par1).getKeybind().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 index ab76088..81b77ea 100644 --- a/src/com/github/Debris/oh_my_mite_client/config/TriggerHandler.java +++ b/src/com/github/Debris/oh_my_mite_client/config/TriggerHandler.java @@ -15,17 +15,18 @@ public static TriggerHandler getInstance() { return INSTANCE; } - public void handle(FeatureToggle featureToggle, Minecraft minecraft) { - switch (featureToggle) { + public void handle(TweakToggle tweakToggle, Minecraft minecraft) { + switch (tweakToggle) { 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); + minecraft.thePlayer.addChatMessage("tp命令已复制到剪贴板"); return; } case Tweak_ToggleMode: { - int mode = Config.gameMode ^= 1; + int mode = FishConfig.gameMode ^= 1; minecraft.openChat(new GuiChat("/gamemode " + mode)); return; } diff --git a/src/com/github/Debris/oh_my_mite_client/config/TweakToggle.java b/src/com/github/Debris/oh_my_mite_client/config/TweakToggle.java new file mode 100644 index 0000000..b854c61 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/config/TweakToggle.java @@ -0,0 +1,113 @@ +package com.github.Debris.oh_my_mite_client.config; + +import com.google.common.collect.ImmutableList; +import com.google.gson.*; +import net.minecraft.KeyBinding; +import org.lwjgl.input.Keyboard; + +import java.io.*; + +public enum TweakToggle implements IConfigBase { + Tweak_AutoForward("自动前进", 200, false), + Tweak_AutoLeft("自动向左", 203, false), + Tweak_AutoBack("自动后退", 208, false), + Tweak_AutoRight("自动向右", 205, false), + Tweak_AutoJump("自动跳跃", 35, false),//H + Tweak_AutoSneak("自动潜行", 54, false),//RShift + Tweak_AutoAttack("自动攻击", 36, false),//J + Tweak_HoldUse("长按右键", 22, false),//U + Tweak_AutoCraft("自动合成(开发中)", 13, false),//= TODO + Tweak_RenderLivings("禁止渲染生物", 64, false),//F6 + 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 String name; + private final KeyBinding keybind; + private boolean valueBoolean; + private final boolean isTrigger; + + TweakToggle(String name, int defaultKey) { + this.name = name; + this.keybind = new KeyBinding(name, defaultKey); + this.isTrigger = true; + this.valueBoolean = false; + } + + TweakToggle(String name, int defaultKey, boolean defaultValueBoolean) { + this.name = name; + this.keybind = new KeyBinding(name, defaultKey); + this.isTrigger = false; + this.valueBoolean = defaultValueBoolean; + } + + @Override + public String getName() { + return this.name; + } + + public KeyBinding getKeybind() { + return this.keybind; + } + + public boolean getBooleanValue() { + return this.valueBoolean; + } + + public JsonElement getAsJsonElement() { + JsonObject obj = new JsonObject(); + obj.add("enabled", new JsonPrimitive(this.valueBoolean)); + if (this.keybind.keyCode < 0) { + this.keybind.keyCode = 0; + } + obj.add("hotkey", new JsonPrimitive(Keyboard.getKeyName(this.keybind.keyCode))); + return obj; + } + + @Override + public void setValueFromJsonElement(JsonElement element) { + JsonObject obj = element.getAsJsonObject(); + if (JsonUtils.hasBoolean(obj, "enabled")) { + this.valueBoolean = obj.get("enabled").getAsBoolean(); + } + if (JsonUtils.hasString(obj, "hotkey")) { + this.keybind.keyCode = Keyboard.getKeyIndex(obj.get("hotkey").getAsString()); + } + } + + public boolean isTrigger() { + return this.isTrigger; + } + + public void invert() { + this.valueBoolean = !this.valueBoolean; + } + + public static void save() { + JsonObject configRoot = new JsonObject(); + ConfigUtils.writeConfigBase(configRoot, "FeatureToggles", VALUES); + JsonUtils.writeJsonToFile(configRoot, optionsFile); + } + + public static void load() { + if (!optionsFile.exists()) { + return; + } + JsonElement jsonElement = JsonUtils.parseJsonFile(optionsFile); + if (jsonElement != null && jsonElement.isJsonObject()) { + JsonObject obj = jsonElement.getAsJsonObject(); + ConfigUtils.readConfigBase(obj, "FeatureToggles", VALUES); + } + KeyBinding.resetKeyBindingArrayAndHash(); + } + + + public static void setPath(File parent) { + optionsFile = new File(parent, "configs/OMMCTweaks.json"); + } + +} diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/ClientPlayerMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/ClientPlayerMixin.java new file mode 100644 index 0000000..3d07407 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/ClientPlayerMixin.java @@ -0,0 +1,35 @@ +package com.github.Debris.oh_my_mite_client.mixins; + +import com.github.Debris.oh_my_mite_client.config.FishConfig; +import com.github.Debris.oh_my_mite_client.config.TweakToggle; +import net.minecraft.AbstractClientPlayer; +import net.minecraft.ClientPlayer; +import net.minecraft.MovementInput; +import net.minecraft.World; +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(ClientPlayer.class) +public abstract class ClientPlayerMixin extends AbstractClientPlayer { + @Shadow + public MovementInput movementInput; + + public ClientPlayerMixin(World par1World, String par2Str) { + super(par1World, par2Str); + } + + @Inject(method = "onLivingUpdate", at = @At("TAIL")) + private void inject(CallbackInfo ci) { + if (this.capabilities.isFlying && TweakToggle.Tweak_FastFlying.getBooleanValue()) { + if (this.movementInput.sneak) { + this.motionY -= FishConfig.FLYING_SPEED_VERTICAL.get(); + } + if (this.movementInput.jump) { + this.motionY += FishConfig.FLYING_SPEED_VERTICAL.get(); + } + } + } +} diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGameSettingsMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/GameSettingsMixin.java similarity index 60% rename from src/com/github/Debris/oh_my_mite_client/mixins/OMMCGameSettingsMixin.java rename to src/com/github/Debris/oh_my_mite_client/mixins/GameSettingsMixin.java index dbf41bd..4086963 100644 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCGameSettingsMixin.java +++ b/src/com/github/Debris/oh_my_mite_client/mixins/GameSettingsMixin.java @@ -1,6 +1,6 @@ package com.github.Debris.oh_my_mite_client.mixins; -import com.github.Debris.oh_my_mite_client.config.FeatureToggle; +import com.github.Debris.oh_my_mite_client.config.TweakToggle; import net.minecraft.GameSettings; import net.minecraft.Minecraft; import org.spongepowered.asm.mixin.Mixin; @@ -11,11 +11,10 @@ import java.io.File; @Mixin(GameSettings.class) -public class OMMCGameSettingsMixin { +public class GameSettingsMixin { @Inject(method = "(Lnet/minecraft/Minecraft;Ljava/io/File;)V", at = @At("TAIL")) - private void loadOMMCOptions(Minecraft par1Minecraft, File par2File, CallbackInfo ci) { - FeatureToggle.setPath(par2File); - FeatureToggle.loadOptions(); - FeatureToggle.saveOptions(); + private void loadConfig(Minecraft par1Minecraft, File par2File, CallbackInfo ci) { + TweakToggle.setPath(par2File); + TweakToggle.load(); } } diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMinecraftMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/MinecraftMixin.java similarity index 76% rename from src/com/github/Debris/oh_my_mite_client/mixins/OMMCMinecraftMixin.java rename to src/com/github/Debris/oh_my_mite_client/mixins/MinecraftMixin.java index b6c7924..3d9a8db 100644 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMinecraftMixin.java +++ b/src/com/github/Debris/oh_my_mite_client/mixins/MinecraftMixin.java @@ -1,7 +1,7 @@ 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 com.github.Debris.oh_my_mite_client.config.FishConfig; +import com.github.Debris.oh_my_mite_client.config.TweakToggle; import com.github.Debris.oh_my_mite_client.config.TriggerHandler; import net.minecraft.EntityClientPlayerMP; import net.minecraft.Minecraft; @@ -14,7 +14,7 @@ import static net.minecraft.Minecraft.getSystemTime; @Mixin(Minecraft.class) -public abstract class OMMCMinecraftMixin { +public abstract class MinecraftMixin { @Shadow protected abstract void clickMouse(int button); @@ -28,7 +28,7 @@ public static Minecraft getMinecraft() { @Inject(method = "runTick", at = @At("TAIL")) private void inject(CallbackInfo ci) { - for (FeatureToggle value : FeatureToggle.values()) { + for (TweakToggle value : TweakToggle.VALUES) { if (value.isTrigger()) { if (value.getKeybind().isPressed()) { TriggerHandler.getInstance().handle(value, getMinecraft()); @@ -36,6 +36,7 @@ private void inject(CallbackInfo ci) { } else { if (value.getKeybind().isPressed()) { value.invert(); + TweakToggle.save(); String message = String.format("功能 %s 已切换为: %s", value.getKeybind().keyDescription, value.getBooleanValue() ? "开" : "关"); this.thePlayer.addChatMessage(message); } @@ -43,11 +44,11 @@ private void inject(CallbackInfo ci) { } - if (FeatureToggle.Tweak_AutoAttack.getBooleanValue() && - (getSystemTime() % Config.ATTACK_INTERVAL.get()) <= 50) { + if (TweakToggle.Tweak_AutoAttack.getBooleanValue() && + (getSystemTime() % FishConfig.ATTACK_INTERVAL.get()) <= 50) { this.clickMouse(0); } - if (FeatureToggle.Tweak_HoldUse.getBooleanValue()) { + if (TweakToggle.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/MovementMixin.java similarity index 60% rename from src/com/github/Debris/oh_my_mite_client/mixins/OMMCMovementMixin.java rename to src/com/github/Debris/oh_my_mite_client/mixins/MovementMixin.java index 870f66e..9429fec 100644 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCMovementMixin.java +++ b/src/com/github/Debris/oh_my_mite_client/mixins/MovementMixin.java @@ -1,6 +1,6 @@ package com.github.Debris.oh_my_mite_client.mixins; -import com.github.Debris.oh_my_mite_client.config.FeatureToggle; +import com.github.Debris.oh_my_mite_client.config.TweakToggle; import net.minecraft.MovementInput; import net.minecraft.MovementInputFromOptions; import org.spongepowered.asm.mixin.Mixin; @@ -9,25 +9,25 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(MovementInputFromOptions.class) -public abstract class OMMCMovementMixin extends MovementInput { +public abstract class MovementMixin extends MovementInput { @Inject(method = "updatePlayerMoveState", at = @At("TAIL")) private void inject(CallbackInfo ci) { - if (FeatureToggle.Tweak_AutoForward.getBooleanValue()) { + if (TweakToggle.Tweak_AutoForward.getBooleanValue()) { this.moveForward = 1.0F; } - if (FeatureToggle.Tweak_AutoLeft.getBooleanValue()) { + if (TweakToggle.Tweak_AutoLeft.getBooleanValue()) { this.moveStrafe = 1.0F; } - if (FeatureToggle.Tweak_AutoBack.getBooleanValue()) { + if (TweakToggle.Tweak_AutoBack.getBooleanValue()) { this.moveForward = -1.0F; } - if (FeatureToggle.Tweak_AutoRight.getBooleanValue()) { + if (TweakToggle.Tweak_AutoRight.getBooleanValue()) { this.moveStrafe = -1.0F; } - if (FeatureToggle.Tweak_Autojump.getBooleanValue()) { + if (TweakToggle.Tweak_AutoJump.getBooleanValue()) { this.jump = true; } - if (FeatureToggle.Tweak_AutoSneak.getBooleanValue()) { + if (TweakToggle.Tweak_AutoSneak.getBooleanValue()) { this.sneak = true; } } 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 deleted file mode 100644 index e5c1695..0000000 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCCraftingMixin.java +++ /dev/null @@ -1,15 +0,0 @@ -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) { -//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 deleted file mode 100644 index f790f2d..0000000 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCEntityMixin.java +++ /dev/null @@ -1,19 +0,0 @@ -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/Packet202PlayerAbilitiesMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/Packet202PlayerAbilitiesMixin.java new file mode 100644 index 0000000..c8f72e3 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/Packet202PlayerAbilitiesMixin.java @@ -0,0 +1,20 @@ +package com.github.Debris.oh_my_mite_client.mixins; + +import net.minecraft.Packet202PlayerAbilities; +import net.minecraft.PlayerCapabilities; +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(Packet202PlayerAbilities.class) +public abstract class Packet202PlayerAbilitiesMixin { + @Shadow + public abstract void setFlySpeed(float v); + + @Inject(method = "(Lnet/minecraft/PlayerCapabilities;)V", at = @At("TAIL")) + private void inject(PlayerCapabilities par1, CallbackInfo ci) { + this.setFlySpeed(0.05F); + } +} diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCPlayerAbilitiesMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/PlayerAbilitiesMixin.java similarity index 60% rename from src/com/github/Debris/oh_my_mite_client/mixins/OMMCPlayerAbilitiesMixin.java rename to src/com/github/Debris/oh_my_mite_client/mixins/PlayerAbilitiesMixin.java index e6fb358..6c2c926 100644 --- a/src/com/github/Debris/oh_my_mite_client/mixins/OMMCPlayerAbilitiesMixin.java +++ b/src/com/github/Debris/oh_my_mite_client/mixins/PlayerAbilitiesMixin.java @@ -1,7 +1,7 @@ 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 com.github.Debris.oh_my_mite_client.config.FishConfig; +import com.github.Debris.oh_my_mite_client.config.TweakToggle; import net.minecraft.PlayerCapabilities; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -9,11 +9,10 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; @Mixin(PlayerCapabilities.class) -public class OMMCPlayerAbilitiesMixin { +public class PlayerAbilitiesMixin { @Inject(method = "getFlySpeed", at = @At("HEAD"), cancellable = true) private void inject(CallbackInfoReturnable cir) { - if (FeatureToggle.Tweak_FastFlying.getBooleanValue()) { - cir.setReturnValue(Config.FLYING_SPEED.get()); - } + float overrideSpeed = TweakToggle.Tweak_FastFlying.getBooleanValue() ? FishConfig.FLYING_SPEED_LEVEL.get() : 0.05F; + cir.setReturnValue(overrideSpeed); } } diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/RenderLivingEntityMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/RenderLivingEntityMixin.java new file mode 100644 index 0000000..2ac25ab --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/RenderLivingEntityMixin.java @@ -0,0 +1,19 @@ +package com.github.Debris.oh_my_mite_client.mixins; + +import com.github.Debris.oh_my_mite_client.config.TweakToggle; +import net.minecraft.EntityLivingBase; +import net.minecraft.RendererLivingEntity; +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(RendererLivingEntity.class) +public class RenderLivingEntityMixin { + @Inject(method = "renderModel", at = @At("HEAD"), cancellable = true) + private void inject(EntityLivingBase par1EntityLivingBase, float par2, float par3, float par4, float par5, float par6, float par7, CallbackInfo ci) { + if (TweakToggle.Tweak_RenderLivings.getBooleanValue()) { + ci.cancel(); + } + } +} diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/SlotCraftingMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/SlotCraftingMixin.java new file mode 100644 index 0000000..fedcfd6 --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/SlotCraftingMixin.java @@ -0,0 +1,43 @@ +package com.github.Debris.oh_my_mite_client.mixins; + +import com.github.Debris.oh_my_mite_client.config.TweakToggle; +import com.github.Debris.oh_my_mite_client.util.CraftingHandler; +import net.minecraft.*; +import org.spongepowered.asm.mixin.Final; +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(SlotCrafting.class) +public abstract class SlotCraftingMixin extends Slot { + @Shadow + @Final + private IInventory craftMatrix; + + @Shadow + private EntityPlayer thePlayer; + + public SlotCraftingMixin(IInventory inventory, int slot_index, int display_x, int display_y) { + super(inventory, slot_index, display_x, display_y); + } + + @Inject(method = "onPickupFromSlot", at = @At("TAIL")) + private void inject(EntityPlayer par1EntityPlayer, ItemStack par2ItemStack, CallbackInfo ci) { + if (TweakToggle.Tweak_AutoCraft.getBooleanValue()) { + + for (int slot = 0; slot < this.craftMatrix.getSizeInventory(); ++slot) { + ItemStack var4 = this.craftMatrix.getStackInSlot(slot); + if (var4 != null) { + int supplier_slot = CraftingHandler.getInstance().getSlotSameItem + (var4.getItem(), var4.getItemSubtype(), this.thePlayer.inventory); + if (supplier_slot == -1) continue; + this.thePlayer.inventory.decrStackSize(supplier_slot, 1); + var4.stackSize += 1; + this.getContainer().onCraftMatrixChanged(this.craftMatrix); + } + } + } + } +} diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/gui/GuiControlsMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/gui/GuiControlsMixin.java new file mode 100644 index 0000000..ffbcfcd --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/mixins/gui/GuiControlsMixin.java @@ -0,0 +1,67 @@ +package com.github.Debris.oh_my_mite_client.mixins.gui; + +import com.github.Debris.oh_my_mite_client.config.TweakToggle; +import net.minecraft.*; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; + +@Mixin(GuiControls.class) +public abstract class GuiControlsMixin extends GuiScreen { + @Shadow + private GameSettings options; + @Shadow + protected String screenTitle; + + @Shadow + protected abstract boolean isKeybindButtonVisible(int index); + + @Shadow + private int buttonId; + + @Shadow + protected abstract int getKeybindButtonPosX(int index); + + @Shadow + protected abstract int getKeybindButtonPosY(int index); +// @Overwrite + 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 (true) { + while (var5 < this.options.keyBindings.length) { + if (!this.isKeybindButtonVisible(var5)) { + ++var5; + } else { + boolean var6 = false; + + for (int var7 = 0; var7 < this.options.keyBindings.length; ++var7) { + if (var7 != var5 && this.options.keyBindings[var5].keyCode == this.options.keyBindings[var7].keyCode) { + var6 = true; + break; + } + } + for (TweakToggle value : TweakToggle.VALUES) { + if (value.getKeybind().keyCode == this.options.keyBindings[var5].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.options.getOptionDisplayString(var5); + } else { + ((GuiButton) this.buttonList.get(var5)).displayString = this.options.getOptionDisplayString(var5); + } + + this.drawString(this.fontRenderer, this.options.getKeyBindingDescription(var5), this.getKeybindButtonPosX(var5) + 70 + 6, this.getKeybindButtonPosY(var5) + 7, -1); + ++var5; + } + } + + super.drawScreen(par1, par2, par3); + return; + } + } +} diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiOptionsMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/gui/GuiOptionsMixin.java similarity index 94% rename from src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiOptionsMixin.java rename to src/com/github/Debris/oh_my_mite_client/mixins/gui/GuiOptionsMixin.java index 3870be6..0032c76 100644 --- a/src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiOptionsMixin.java +++ b/src/com/github/Debris/oh_my_mite_client/mixins/gui/GuiOptionsMixin.java @@ -10,7 +10,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; @Mixin(GuiOptions.class) -public abstract class OMMCGuiOptionsMixin extends GuiScreen { +public abstract class GuiOptionsMixin 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按键设置")); diff --git a/src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiControlsMixin.java b/src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiControlsMixin.java deleted file mode 100644 index 1523eda..0000000 --- a/src/com/github/Debris/oh_my_mite_client/mixins/gui/OMMCGuiControlsMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.github.Debris.oh_my_mite_client.mixins.gui; - -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/util/CraftingHandler.java b/src/com/github/Debris/oh_my_mite_client/util/CraftingHandler.java new file mode 100644 index 0000000..3d566df --- /dev/null +++ b/src/com/github/Debris/oh_my_mite_client/util/CraftingHandler.java @@ -0,0 +1,31 @@ +package com.github.Debris.oh_my_mite_client.util; + +import net.minecraft.*; + +public class CraftingHandler { + + private static final CraftingHandler INSTANCE = new CraftingHandler(); + + public static CraftingHandler getInstance() { + return INSTANCE; + } + + public int getSlotSameItem(Item item, int item_subtype, InventoryPlayer inventoryPlayer) { + if (item == null) { + return -1; + } else { + int i; + for (i = 0; i < 36; ++i) { + if (getSameItem(item, item_subtype, inventoryPlayer.mainInventory[i])) { + return i; + } + } + } + return -1; + } + + private boolean getSameItem(Item item, int item_subtype, ItemStack item_stack) { + if (item_stack == null) return false; + return item_stack.getItem().equals(item) && item_stack.getItemSubtype() == item_subtype; + } +}