Skip to content

Commit

Permalink
Rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
De6ris committed Mar 17, 2024
1 parent b133713 commit a7fe898
Show file tree
Hide file tree
Showing 14 changed files with 253 additions and 201 deletions.
6 changes: 5 additions & 1 deletion src/com/github/Debris/oh_my_mite_client/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@

public class Config {
public static final FieldReference<Integer> ATTACK_INTERVAL = new FieldReference<>(500);
public static final FieldReference<Float> 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("飞行速度"));
}
95 changes: 95 additions & 0 deletions src/com/github/Debris/oh_my_mite_client/config/FeatureToggle.java
Original file line number Diff line number Diff line change
@@ -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<FeatureToggle> 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");
}

}

This file was deleted.

60 changes: 39 additions & 21 deletions src/com/github/Debris/oh_my_mite_client/config/OMMCGuiControls.java
Original file line number Diff line number Diff line change
@@ -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() {
Expand All @@ -30,16 +29,16 @@ 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")));
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) {
for (int i = 0; i < FeatureToggle.values().length; ++i) {
((GuiButton) this.buttonList.get(i)).drawButton = this.isKeybindButtonVisible(i);
}
}
Expand All @@ -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 {
Expand All @@ -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 {
Expand All @@ -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;
}
Expand All @@ -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);
}
}

114 changes: 0 additions & 114 deletions src/com/github/Debris/oh_my_mite_client/config/OMMCOptions.java

This file was deleted.

Loading

0 comments on commit a7fe898

Please sign in to comment.