Feat: Add Events and Update mixin

This commit is contained in:
xiaozhou233 committed 2026-08-19 22:17:09 +08:00
1 parent 68c7e631b7
commit 6eb9ca8240
14 files changed
+147 -5

No files matched your search

@@ -0,0 +1,18 @@
package cn.xiaozhou233.orangex.event;
public class Cancellable extends Event{
private boolean cancelled;
public boolean isCancelled() {
return cancelled;
}
public void setCancelled(boolean cancelled) {
this.cancelled = cancelled;
}
public void cancel() {
this.cancelled = true;
}
}
@@ -0,0 +1,4 @@
package cn.xiaozhou233.orangex.event;
public class Event {
}
@@ -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,13 @@
package cn.xiaozhou233.orangex.event.impl;
import cn.xiaozhou233.orangex.event.Cancellable;
import cn.xiaozhou233.orangex.event.Event;
import lombok.AllArgsConstructor;
import lombok.Getter;
import net.minecraft.network.Packet;
@Getter
@AllArgsConstructor
public class EventPacketSend extends Cancellable {
private Packet packet;
}
@@ -0,0 +1,13 @@
package cn.xiaozhou233.orangex.event.impl;
import cn.xiaozhou233.orangex.event.Event;
import lombok.Getter;
@Getter
public class EventRender2D extends Event {
private float partialTicks;
public EventRender2D(float partialTicks) {
this.partialTicks = partialTicks;
}
}
@@ -0,0 +1,13 @@
package cn.xiaozhou233.orangex.event.impl;
import cn.xiaozhou233.orangex.event.Event;
import lombok.AllArgsConstructor;
import lombok.Getter;
@Getter
@AllArgsConstructor
public class EventRender3D extends Event {
private float partialTicks;
}
@@ -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 EventTimerThread {
}
@@ -0,0 +1,4 @@
package cn.xiaozhou233.orangex.event.impl;
public class EventWorldLoad {
}
@@ -0,0 +1,25 @@
package cn.xiaozhou233.orangex.mixin.impl;
import cn.xiaozhou233.orangex.OrangeX;
import cn.xiaozhou233.orangex.event.impl.EventRender3D;
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.renderer.EntityRenderer;
@Mixin(EntityRenderer.class)
public class MixinEntityRenderer {
@Inject(
method = "renderWorldPass", desc = "(IFJ)V",
target = @Target(
value = "INVOKESTATIC",
target = "net/minecraft/client/renderer/GlStateManager.disableFog()V",
shift = Target.Shift.AFTER
)
)
private void render(@Local(source = "partialTicks", index = 2) float partialTicks) {
OrangeX.getInstance().getEventBus().post(new EventRender3D(partialTicks));
}
}
@@ -1,6 +1,7 @@
package cn.xiaozhou233.orangex.mixin.impl;
import cn.xiaozhou233.orangex.OrangeX;
import cn.xiaozhou233.orangex.event.impl.EventRender2D;
import cn.yapeteam.ymixin.annotations.Inject;
import cn.yapeteam.ymixin.annotations.Local;
import cn.yapeteam.ymixin.annotations.Mixin;
@@ -32,7 +33,7 @@ public class MixinGuiIngame {
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
mc.entityRenderer.setupOverlayRendering();
OrangeX.getInstance().getFontManager().JelloMedium32.drawString("OrangeX", 5, 5, 0xFFA500);
OrangeX.getInstance().getEventBus().post(new EventRender2D(partialTicks));
GlStateManager.enableDepth();
GlStateManager.disableBlend();
@@ -1,6 +1,7 @@
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;
@@ -11,15 +12,16 @@ 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.getInstance().getEventBus().post(new EventLoop());
}
@Inject(method = "runTick", desc = "()V", target = @Target("HEAD"))
public void onTick() {
OrangeX.getInstance().getEventBus().post(new EventTick());
}
@Inject(method = "shutdownMinecraftApplet", desc = "()V", target = @Target("HEAD"))
@@ -37,11 +39,11 @@ public class MixinMinecraft {
)
public void onKey(@Local(source = "key", index = 1) int key) {
if (Minecraft.getMinecraft().currentScreen == null && Keyboard.getEventKeyState())
;
OrangeX.getInstance().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.getInstance().getEventBus().post(new EventWorldLoad());
}
}
@@ -0,0 +1,27 @@
package cn.xiaozhou233.orangex.mixin.impl;
import cn.xiaozhou233.orangex.OrangeX;
import cn.xiaozhou233.orangex.event.impl.EventPacketSend;
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.network.NetHandlerPlayClient;
import net.minecraft.network.Packet;
@Mixin(NetHandlerPlayClient.class)
public class MixinNetHandlerPlayClient {
@Inject(
method = "addToSendQueue",
desc = "(Lnet/minecraft/network/Packet;)V",
target = @Target("HEAD")
)
public void onSendPacket(@Local(source = "packet", index = 1) Packet packet) {
EventPacketSend eventPacketSend = new EventPacketSend(packet);
OrangeX.getInstance().getEventBus().post(eventPacketSend);
if (eventPacketSend.isCancelled()) {
return;
}
}
}