mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
[Perf] KeyBinding
This commit is contained in:
1 parent
38662f534e
commit
0c3af1e5ab
7 files changed
+29
-14
No files matched your search
@@ -1,6 +1,7 @@
|
||||
package cn.xiaozhou233.orangex.module;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.module.value.KeybindValue;
|
||||
import cn.xiaozhou233.orangex.module.value.Value;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
@@ -17,7 +18,7 @@ public abstract class Module {
|
||||
|
||||
protected final String name;
|
||||
@Setter
|
||||
protected int keyBind = -1;
|
||||
protected KeybindValue keyBind = new KeybindValue("Bind", "KeyBinding", 0);
|
||||
protected final ModuleCategory category;
|
||||
protected boolean enabled = false;
|
||||
@Getter
|
||||
@@ -30,7 +31,7 @@ public abstract class Module {
|
||||
|
||||
public Module(String name, ModuleCategory category, int defaultKey) {
|
||||
this(name, category);
|
||||
this.keyBind = defaultKey;
|
||||
this.keyBind.setKey(defaultKey);
|
||||
}
|
||||
|
||||
protected void onEnable() {
|
||||
|
||||
@@ -35,7 +35,7 @@ public class ModuleManager {
|
||||
@Subscribe
|
||||
public void onKey(EventKey event) {
|
||||
for (Module module : modules) {
|
||||
if (module.getKeyBind() == event.getKey()) {
|
||||
if (module.getKeyBind().getValue() == event.getKey()) {
|
||||
module.toggle();
|
||||
System.out.println("[ModuleManager] Toggled module: " + module.getName());
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import cn.xiaozhou233.orangex.event.impl.EventTick;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import cn.xiaozhou233.orangex.module.value.BooleanValue;
|
||||
import cn.xiaozhou233.orangex.module.value.KeybindValue;
|
||||
import cn.xiaozhou233.orangex.module.value.NumberValue;
|
||||
import net.minecraft.client.settings.KeyBinding;
|
||||
import net.minecraft.util.MovingObjectPosition;
|
||||
@@ -31,10 +32,12 @@ public class AutoClicker extends Module {
|
||||
private double currentTicksPerClick = 0.0;
|
||||
|
||||
public AutoClicker() {
|
||||
super("AutoClicker", ModuleCategory.COMBAT, Keyboard.KEY_F);
|
||||
super("AutoClicker", ModuleCategory.COMBAT);
|
||||
addValue(cps);
|
||||
addValue(jitter);
|
||||
addValue(ignoreBlock);
|
||||
|
||||
addValue(keyBind);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
@@ -45,15 +48,13 @@ public class AutoClicker extends Module {
|
||||
return;
|
||||
}
|
||||
|
||||
// Determine what we're looking at
|
||||
MovingObjectPosition target = mc.objectMouseOver;
|
||||
|
||||
// Target is a block
|
||||
if (target != null && target.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK) {
|
||||
// Auto mine: keep holding left click
|
||||
KeyBinding.setKeyBindState(mc.gameSettings.keyBindAttack.getKeyCode(), true);
|
||||
KeyBinding.onTick(mc.gameSettings.keyBindAttack.getKeyCode());
|
||||
|
||||
// Reset click logic so it doesn't click once then stop
|
||||
tickCounter = 0;
|
||||
clicking = false;
|
||||
currentTicksPerClick = 0;
|
||||
@@ -67,7 +68,6 @@ public class AutoClicker extends Module {
|
||||
return;
|
||||
}
|
||||
|
||||
// Normal auto clicker behavior (entities / air)
|
||||
if (currentTicksPerClick <= 0) {
|
||||
recalcDelay();
|
||||
}
|
||||
|
||||
@@ -32,6 +32,8 @@ public class Test extends Module{
|
||||
|
||||
// Number Examples
|
||||
addValue(new NumberValue("Example Number", "Example", 0.0, 0, 100, 0.1));
|
||||
|
||||
addValue(keyBind);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
@@ -9,7 +9,9 @@ public class ClickGUI extends Module {
|
||||
|
||||
public ClickGUI() {
|
||||
super("ClickGUI", ModuleCategory.RENDER);
|
||||
setKeyBind(Keyboard.KEY_RSHIFT);
|
||||
keyBind.setKey(Keyboard.KEY_RSHIFT);
|
||||
|
||||
addValue(keyBind);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -28,9 +28,10 @@ public class HUD extends Module {
|
||||
public HUD() {
|
||||
super("HUD", ModuleCategory.RENDER);
|
||||
|
||||
// TODO: Release 时移除
|
||||
keyBind = 41;
|
||||
// TODO: Remove this when config is implemented
|
||||
setEnabled(true);
|
||||
|
||||
addValue(keyBind);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
|
||||
+12
-3
@@ -6,6 +6,7 @@ import cn.xiaozhou233.orangex.ui.clickgui.component.ValueComponent;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.render.GuiRenderUtils;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.settings.GameSettings;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class KeybindComponent extends ValueComponent {
|
||||
|
||||
@@ -31,6 +32,8 @@ public class KeybindComponent extends ValueComponent {
|
||||
GuiRenderUtils.drawRect(ax, ay, width, height, bgColor);
|
||||
|
||||
String keyName = listening ? "Press a key..." : GameSettings.getKeyDisplayString(value.getValue());
|
||||
if (keyName==GameSettings.getKeyDisplayString(Keyboard.KEY_DELETE))
|
||||
keyName = "None";
|
||||
GuiRenderUtils.drawString(value.getName() + ": " + keyName, ax + 6, ay + 4, 0xFFFFFFFF);
|
||||
GuiRenderUtils.disableBlend();
|
||||
}
|
||||
@@ -48,19 +51,25 @@ public class KeybindComponent extends ValueComponent {
|
||||
public void keyTyped(char typedChar, int keyCode) {
|
||||
if (!listening) return;
|
||||
|
||||
System.out.println("KeyTyped triggered: " + keyCode); // 用来测试
|
||||
|
||||
// ESC
|
||||
if (keyCode == 1) {
|
||||
listening = false;
|
||||
return;
|
||||
}
|
||||
|
||||
// DELETE
|
||||
if (keyCode == Keyboard.KEY_DELETE) {
|
||||
value.setValue(Keyboard.KEY_NONE);
|
||||
listening = false;
|
||||
applyValue();
|
||||
return;
|
||||
}
|
||||
|
||||
value.setKey(keyCode);
|
||||
listening = false;
|
||||
applyValue();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void applyValue() {
|
||||
// no-op
|
||||
|
||||
Reference in new issue
Block a user