mirror of
https://github.com/xiaozhou233/OrangeX-Client.git
synced 2026-12-05 13:05:52 +08:00
[Feat] EventPacketSend
This commit is contained in:
1 parent
3d55afcca2
commit
9f5ac18d79
4 files changed
+60
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,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;
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package cn.xiaozhou233.orangex.mixin;
|
||||
import cn.xiaozhou233.orangex.mixin.impl.MixinEntityRenderer;
|
||||
import cn.xiaozhou233.orangex.mixin.impl.MixinGuiIngame;
|
||||
import cn.xiaozhou233.orangex.mixin.impl.MixinMinecraft;
|
||||
import cn.xiaozhou233.orangex.mixin.impl.MixinNetHandlerPlayClient;
|
||||
import cn.xiaozhou233.orangex.utils.JuiceLoaderFacade;
|
||||
import cn.yapeteam.ymixin.Transformer;
|
||||
import cn.yapeteam.ymixin.YMixin;
|
||||
@@ -44,6 +45,7 @@ public final class MixinManager {
|
||||
transformer.addMixin(MixinGuiIngame.class);
|
||||
transformer.addMixin(MixinMinecraft.class);
|
||||
transformer.addMixin(MixinEntityRenderer.class);
|
||||
transformer.addMixin(MixinNetHandlerPlayClient.class);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException("Failed to add mixin", e);
|
||||
}
|
||||
|
||||
+27
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user