mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
[Feat] Add Event Key/Loop/Tick/WorldLoad
[Test] output key value and WorldLoad
This commit is contained in:
1 parent
ab3bb91800
commit
58dd1572f2
9 files changed
+98
-1
No files matched your search
@@ -7,7 +7,7 @@ import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
public class OrangeX {
|
||||
@Getter
|
||||
public static final EventBus eventBus = EventBus.builder()
|
||||
private static final EventBus eventBus = EventBus.builder()
|
||||
.logNoSubscriberMessages(false)
|
||||
.logSubscriberExceptions(false)
|
||||
.sendNoSubscriberEvent(false)
|
||||
@@ -21,4 +21,8 @@ public class OrangeX {
|
||||
|
||||
ModuleManager.registerAll();
|
||||
}
|
||||
|
||||
public static void stop() {
|
||||
System.out.println("OrangeX stopping...");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
@Getter
|
||||
@AllArgsConstructor
|
||||
public class EventKey {
|
||||
private final int key;
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
public class EventLoop {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
public class EventTick {
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
package cn.xiaozhou233.orangex.event.impl;
|
||||
|
||||
public class EventWorldLoad {
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.xiaozhou233.orangex.mixin;
|
||||
|
||||
import cn.xiaozhou233.orangex.mixin.impl.MixinGuiIngame;
|
||||
import cn.xiaozhou233.orangex.mixin.impl.MixinMinecraft;
|
||||
import cn.xiaozhou233.orangex.utils.JuiceLoaderFacade;
|
||||
import cn.yapeteam.ymixin.Transformer;
|
||||
import cn.yapeteam.ymixin.YMixin;
|
||||
@@ -42,6 +43,7 @@ public final class MixinManager {
|
||||
Transformer transformer = new Transformer();
|
||||
try {
|
||||
transformer.addMixin(MixinGuiIngame.class);
|
||||
transformer.addMixin(MixinMinecraft.class);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to add mixin", e);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
package cn.xiaozhou233.orangex.mixin.impl;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.event.impl.*;
|
||||
import cn.yapeteam.ymixin.annotations.Inject;
|
||||
import cn.yapeteam.ymixin.annotations.Local;
|
||||
import cn.yapeteam.ymixin.annotations.Mixin;
|
||||
import cn.yapeteam.ymixin.annotations.Target;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
@Mixin(Minecraft.class)
|
||||
public class MixinMinecraft {
|
||||
int i = 0;
|
||||
|
||||
@Inject(method = "runGameLoop", desc = "()V", target = @Target("HEAD"))
|
||||
private void onLoop() {
|
||||
OrangeX.getEventBus().post(new EventLoop());
|
||||
}
|
||||
|
||||
@Inject(method = "runTick", desc = "()V", target = @Target("HEAD"))
|
||||
public void onTick() {
|
||||
OrangeX.getEventBus().post(new EventTick());
|
||||
}
|
||||
|
||||
@Inject(method = "shutdownMinecraftApplet", desc = "()V", target = @Target("HEAD"))
|
||||
public void onShutdown() {
|
||||
OrangeX.stop();
|
||||
}
|
||||
|
||||
@Inject(
|
||||
method = "runTick", desc = "()V",
|
||||
target = @Target(
|
||||
value = "INVOKESTATIC",
|
||||
target = "org/lwjgl/input/Keyboard.getEventKeyState()Z",
|
||||
shift = Target.Shift.AFTER
|
||||
)
|
||||
)
|
||||
public void onKey(@Local(source = "key", index = 1) int key) {
|
||||
if (Minecraft.getMinecraft().currentScreen == null && Keyboard.getEventKeyState())
|
||||
OrangeX.getEventBus().post(new EventKey(key));
|
||||
}
|
||||
|
||||
@Inject(method = "loadWorld", desc = "(Lnet/minecraft/client/multiplayer/WorldClient;Ljava/lang/String;)V", target = @Target("HEAD"))
|
||||
public void onLoadWorld() {
|
||||
OrangeX.getEventBus().post(new EventWorldLoad());
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,12 @@
|
||||
package cn.xiaozhou233.orangex.module;
|
||||
|
||||
import cn.xiaozhou233.orangex.OrangeX;
|
||||
import cn.xiaozhou233.orangex.module.impl.misc.Test;
|
||||
import cn.xiaozhou233.orangex.module.impl.render.HUD;
|
||||
|
||||
public class ModuleManager {
|
||||
public static void registerAll() {
|
||||
OrangeX.getEventBus().register(new HUD());
|
||||
OrangeX.getEventBus().register(new Test());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package cn.xiaozhou233.orangex.module.impl.misc;
|
||||
|
||||
import cn.xiaozhou233.orangex.event.impl.EventKey;
|
||||
import cn.xiaozhou233.orangex.event.impl.EventWorldLoad;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
|
||||
public class Test {
|
||||
@Subscribe
|
||||
public void onKey(EventKey event) {
|
||||
System.out.println("Key: " + event.getKey());
|
||||
}
|
||||
|
||||
@Subscribe
|
||||
public void onWorldLoad(EventWorldLoad event) {
|
||||
System.out.println("World loaded");
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user