mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 21:15:53 +08:00
[Feat] ModuleManager
[Feat] ClickGUI Base [Feat] HUD now display modules
This commit is contained in:
1 parent
73bd8ce874
commit
37fcf8867f
9 files changed
+220
-74
No files matched your search
@@ -5,6 +5,8 @@ import cn.xiaozhou233.orangex.module.ModuleManager;
|
||||
import lombok.Getter;
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public class OrangeX {
|
||||
@Getter
|
||||
private static final EventBus eventBus = EventBus.builder()
|
||||
@@ -13,13 +15,16 @@ public class OrangeX {
|
||||
.sendNoSubscriberEvent(false)
|
||||
.sendSubscriberExceptionEvent(false)
|
||||
.installDefaultEventBus();
|
||||
@Getter
|
||||
private static ModuleManager moduleManager = new ModuleManager();
|
||||
@Getter
|
||||
private static String orangexDir = new File(System.getProperty("user.dir") + "/.orangex/").getAbsolutePath();
|
||||
|
||||
public static void start() {
|
||||
System.out.println("OrangeX loading...");
|
||||
|
||||
MixinManager.start();
|
||||
|
||||
ModuleManager.registerAll();
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
|
||||
@@ -1,4 +1,59 @@
|
||||
package cn.xiaozhou233.orangex.module;
|
||||
|
||||
public class Module {
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
|
||||
@Getter
|
||||
public abstract class Module {
|
||||
protected static final Minecraft mc = Minecraft.getMinecraft();
|
||||
protected static final FontRenderer fr = mc.fontRendererObj;
|
||||
|
||||
protected final String name;
|
||||
@Setter
|
||||
protected int keyBind = -1;
|
||||
protected final ModuleCategory category;
|
||||
protected boolean enabled = false;
|
||||
|
||||
public Module(String name, ModuleCategory category) {
|
||||
this.name = name;
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public Module(String name, ModuleCategory category, int defaultKey) {
|
||||
this(name, category);
|
||||
this.keyBind = defaultKey;
|
||||
}
|
||||
|
||||
protected void onEnable() {
|
||||
System.out.println("[OrangeX] Enable " + name);
|
||||
}
|
||||
|
||||
protected void onDisable() {
|
||||
System.out.println("[OrangeX] Disable " + name);
|
||||
}
|
||||
|
||||
public void setEnabled(boolean setEnabled) {
|
||||
if (this.enabled == setEnabled) return;
|
||||
|
||||
this.enabled = setEnabled;
|
||||
|
||||
if (this.enabled) {
|
||||
if (OrangeX.getEventBus().isRegistered(this))
|
||||
return;
|
||||
try { OrangeX.getEventBus().register(this); } catch (Exception ignored) {}
|
||||
onEnable();
|
||||
} else {
|
||||
if (!OrangeX.getEventBus().isRegistered(this))
|
||||
return;
|
||||
try { OrangeX.getEventBus().unregister(this); } catch (Exception ignored) {}
|
||||
onDisable();
|
||||
}
|
||||
}
|
||||
|
||||
public void toggle() {
|
||||
setEnabled(!this.enabled);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package cn.xiaozhou233.orangex.module;
|
||||
|
||||
public enum ModuleCategory {
|
||||
RENDER, MISC
|
||||
}
|
||||
@@ -1,16 +1,60 @@
|
||||
package cn.xiaozhou233.orangex.module;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventKey;
|
||||
import cn.xiaozhou233.orangex.module.impl.misc.Test;
|
||||
import cn.xiaozhou233.orangex.module.impl.render.*;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class ModuleManager {
|
||||
public static void registerAll() {
|
||||
// Render
|
||||
OrangeX.getEventBus().register(new HUD());
|
||||
OrangeX.getEventBus().register(new ClickGUI());
|
||||
// 使用线程安全列表
|
||||
private static final List<Module> modules = new CopyOnWriteArrayList<>();
|
||||
|
||||
// Misc
|
||||
OrangeX.getEventBus().register(new Test());
|
||||
public ModuleManager() {
|
||||
OrangeX.getEventBus().register(this);
|
||||
registerAll();
|
||||
}
|
||||
|
||||
public void registerAll() {
|
||||
register(new ClickGUI());
|
||||
register(new HUD());
|
||||
|
||||
register(new Test());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onKey(EventKey event) {
|
||||
for (Module module : modules) {
|
||||
if (module.getKeyBind() == event.getKey()) {
|
||||
module.toggle();
|
||||
System.out.println("[ModuleManager] Toggled module: " + module.getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void register(Module module) {
|
||||
modules.add(module);
|
||||
System.out.println("[ModuleManager] Registered module: " + module.getName());
|
||||
}
|
||||
|
||||
public Module getModule(String name) {
|
||||
return modules.stream()
|
||||
.filter(m -> m.getName().equalsIgnoreCase(name))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
}
|
||||
|
||||
public List<Module> getModulesByCategory(ModuleCategory category) {
|
||||
return modules.stream()
|
||||
.filter(m -> m.getCategory() == category)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
public List<Module> getAllModules() {
|
||||
return modules;
|
||||
}
|
||||
}
|
||||
@@ -2,9 +2,16 @@ package cn.xiaozhou233.orangex.module.impl.misc;
|
||||
|
||||
import cn.xiaozhou233.orangex.event.impl.EventKey;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventWorldLoad;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
public class Test {
|
||||
public class Test extends Module {
|
||||
public Test() {
|
||||
super("Test", ModuleCategory.MISC);
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onKey(EventKey event) {
|
||||
System.out.println("Key: " + event.getKey());
|
||||
|
||||
@@ -2,17 +2,23 @@ package cn.xiaozhou233.orangex.module.impl.render;
|
||||
|
||||
import cn.xiaozhou233.orangex.event.impl.EventKey;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.ClickGuiScreen;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
public class ClickGUI extends Module {
|
||||
|
||||
@Subscribe
|
||||
public void onKey(EventKey event) {
|
||||
if (event.getKey() == Keyboard.KEY_RSHIFT) {
|
||||
Minecraft.getMinecraft().displayGuiScreen(new ClickGuiScreen());
|
||||
}
|
||||
public ClickGUI() {
|
||||
super("ClickGUI", ModuleCategory.RENDER);
|
||||
setKeyBind(Keyboard.KEY_RSHIFT);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onEnable() {
|
||||
super.onEnable();
|
||||
|
||||
mc.displayGuiScreen(new ClickGuiScreen());
|
||||
|
||||
setEnabled(false);
|
||||
}
|
||||
}
|
||||
@@ -1,102 +1,88 @@
|
||||
package cn.xiaozhou233.orangex.module.impl.render;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
|
||||
import cn.xiaozhou233.orangex.module.Module;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import cn.xiaozhou233.orangex.module.ModuleCategory;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class HUD extends Module {
|
||||
|
||||
private Minecraft mc;
|
||||
private FontRenderer fr;
|
||||
|
||||
private final ArrayList<String> modules = new ArrayList<>();
|
||||
|
||||
private float rainbowTick = 0f;
|
||||
|
||||
// HUD 常量
|
||||
private static final int MARGIN = 6;
|
||||
private static final int PADDING = 2;
|
||||
private static final int MODULE_SPACING = 4;
|
||||
private static final int LOGO_COLOR = 0xFFA500;
|
||||
private static final int BACKGROUND_ALPHA = 0x70; // 112
|
||||
private static final float RAINBOW_CYCLE = 60f;
|
||||
|
||||
public HUD() {
|
||||
modules.add("Juice uwu");
|
||||
modules.add("ExampleA");
|
||||
modules.add("ExampleB");
|
||||
modules.add("ExampleC");
|
||||
modules.add("114514");
|
||||
super("HUD", ModuleCategory.RENDER);
|
||||
|
||||
// TODO: Release 时移除
|
||||
keyBind = 41;
|
||||
setEnabled(true);
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onRender2D(EventRender2D event) {
|
||||
|
||||
// Lazy init, safe in MC thread
|
||||
if (mc == null) {
|
||||
mc = Minecraft.getMinecraft();
|
||||
if (mc == null || mc.fontRendererObj == null) return;
|
||||
fr = mc.fontRendererObj;
|
||||
}
|
||||
|
||||
ScaledResolution sr = new ScaledResolution(mc);
|
||||
float partialTicks = event.getPartialTicks();
|
||||
|
||||
rainbowTick += partialTicks;
|
||||
rainbowTick += event.getPartialTicks();
|
||||
|
||||
renderLogo();
|
||||
renderModuleList(sr, rainbowTick);
|
||||
renderModuleList(sr);
|
||||
}
|
||||
|
||||
private void renderLogo() {
|
||||
fr.drawStringWithShadow(
|
||||
"OrangeX Client",
|
||||
10,
|
||||
10,
|
||||
0xFFA500
|
||||
);
|
||||
fr.drawStringWithShadow("OrangeX Client", MARGIN, MARGIN, LOGO_COLOR);
|
||||
}
|
||||
|
||||
private void renderModuleList(ScaledResolution sr, float baseTick) {
|
||||
int margin = 6;
|
||||
int y = margin;
|
||||
int index = 0;
|
||||
private void renderModuleList(ScaledResolution sr) {
|
||||
List<Module> enabledModules = OrangeX.getModuleManager()
|
||||
.getAllModules()
|
||||
.stream()
|
||||
.filter(Module::isEnabled)
|
||||
.sorted(Comparator.comparingInt((Module m) -> fr.getStringWidth(m.getName())).reversed())
|
||||
.collect(Collectors.toList());
|
||||
|
||||
modules.sort(
|
||||
Comparator.comparingInt(fr::getStringWidth).reversed()
|
||||
);
|
||||
int y = MARGIN;
|
||||
int screenWidth = sr.getScaledWidth();
|
||||
|
||||
for (String module : modules) {
|
||||
int textWidth = fr.getStringWidth(module);
|
||||
int x = sr.getScaledWidth() - textWidth - margin;
|
||||
for (int i = 0; i < enabledModules.size(); i++) {
|
||||
Module module = enabledModules.get(i);
|
||||
int textWidth = fr.getStringWidth(module.getName());
|
||||
int x = screenWidth - textWidth - MARGIN;
|
||||
|
||||
int color = getRainbowColor(baseTick + index * 6f);
|
||||
int color = getRainbowColor(rainbowTick + i * 6f);
|
||||
drawHudString(module.getName(), x, y, color);
|
||||
|
||||
drawHudString(module, x, y, color);
|
||||
|
||||
y += fr.FONT_HEIGHT + 4;
|
||||
index++;
|
||||
y += fr.FONT_HEIGHT + MODULE_SPACING;
|
||||
}
|
||||
}
|
||||
|
||||
private void drawHudString(String text, int x, int y, int color) {
|
||||
int padding = 2;
|
||||
|
||||
int textWidth = fr.getStringWidth(text);
|
||||
Gui.drawRect(
|
||||
x - padding,
|
||||
y - padding,
|
||||
x + fr.getStringWidth(text) + padding,
|
||||
y + fr.FONT_HEIGHT + padding,
|
||||
0x70000000
|
||||
x - PADDING,
|
||||
y - PADDING,
|
||||
x + textWidth + PADDING,
|
||||
y + fr.FONT_HEIGHT + PADDING,
|
||||
(BACKGROUND_ALPHA << 24) | 0x000000
|
||||
);
|
||||
|
||||
fr.drawStringWithShadow(text, x, y, color);
|
||||
}
|
||||
|
||||
private int getRainbowColor(float tick) {
|
||||
float cycle = 60f;
|
||||
float hue = (tick % cycle) / cycle;
|
||||
float hue = (tick % RAINBOW_CYCLE) / RAINBOW_CYCLE;
|
||||
return Color.HSBtoRGB(hue, 0.9f, 1.0f);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,29 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui;
|
||||
|
||||
import cn.xiaozhou233.orangex.ui.clickgui.component.PanelUI;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiScreen;
|
||||
|
||||
import java.awt.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class ClickGuiScreen extends GuiScreen {
|
||||
private PanelUI panel;
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
panel = new PanelUI(10, 10, 100, 150, "Example");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float partialTicks) {
|
||||
drawDefaultBackground();
|
||||
// Background
|
||||
int color = new Color(50, 50, 50, 100).getRGB();
|
||||
Gui.drawRect(0, 0, this.width, this.height, color);
|
||||
|
||||
if (panel != null) {
|
||||
panel.draw();
|
||||
}
|
||||
super.drawScreen(mouseX, mouseY, partialTicks);
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,23 @@
|
||||
package cn.xiaozhou233.orangex.ui.clickgui.component;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import java.awt.*;
|
||||
|
||||
public class PanelUI {
|
||||
private int x, y, width, height;
|
||||
private String title;
|
||||
|
||||
public PanelUI(int x, int y, int width, int height, String title) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.title = title;
|
||||
}
|
||||
|
||||
public void draw() {
|
||||
Gui.drawRect(x, y, x+width, y+height, new Color(32, 32, 32, 204).getRGB());
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user