aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/cc/polyfrost
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/cc/polyfrost')
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/ReceivePacketEvent.java10
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/events/event/SendPacketEvent.java10
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/mixin/NetHandlerPlayClientMixin.java14
-rw-r--r--src/main/java/cc/polyfrost/oneconfig/mixin/NetworkManagerMixin.java23
4 files changed, 56 insertions, 1 deletions
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/ReceivePacketEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/ReceivePacketEvent.java
new file mode 100644
index 0000000..274f7a4
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/ReceivePacketEvent.java
@@ -0,0 +1,10 @@
+package cc.polyfrost.oneconfig.events.event;
+
+import net.minecraft.network.Packet;
+
+public class ReceivePacketEvent extends CancellableEvent {
+ public final Packet<?> packet;
+ public ReceivePacketEvent(Packet<?> packet) {
+ this.packet = packet;
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/events/event/SendPacketEvent.java b/src/main/java/cc/polyfrost/oneconfig/events/event/SendPacketEvent.java
new file mode 100644
index 0000000..f149d59
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/events/event/SendPacketEvent.java
@@ -0,0 +1,10 @@
+package cc.polyfrost.oneconfig.events.event;
+
+import net.minecraft.network.Packet;
+
+public class SendPacketEvent extends CancellableEvent {
+ public final Packet<?> packet;
+ public SendPacketEvent(Packet<?> packet) {
+ this.packet = packet;
+ }
+}
diff --git a/src/main/java/cc/polyfrost/oneconfig/mixin/NetHandlerPlayClientMixin.java b/src/main/java/cc/polyfrost/oneconfig/mixin/NetHandlerPlayClientMixin.java
index c7056d5..5d78531 100644
--- a/src/main/java/cc/polyfrost/oneconfig/mixin/NetHandlerPlayClientMixin.java
+++ b/src/main/java/cc/polyfrost/oneconfig/mixin/NetHandlerPlayClientMixin.java
@@ -2,15 +2,27 @@ package cc.polyfrost.oneconfig.mixin;
import cc.polyfrost.oneconfig.events.EventManager;
import cc.polyfrost.oneconfig.events.event.ChatReceiveEvent;
+import cc.polyfrost.oneconfig.events.event.SendPacketEvent;
import net.minecraft.client.network.NetHandlerPlayClient;
+import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S02PacketChat;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
-@Mixin(NetHandlerPlayClient.class)
+@Mixin(value = NetHandlerPlayClient.class, priority = Integer.MAX_VALUE)
public class NetHandlerPlayClientMixin {
+
+ @Inject(method = "addToSendQueue", at = @At("HEAD"), cancellable = true)
+ private void onSendPacket(Packet<?> p_147297_1_, CallbackInfo ci) {
+ SendPacketEvent event = new SendPacketEvent(p_147297_1_);
+ EventManager.INSTANCE.post(event);
+ if (event.isCancelled) {
+ ci.cancel();
+ }
+ }
+
@Inject(method = "handleChat", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/event/ForgeEventFactory;onClientChat(BLnet/minecraft/util/IChatComponent;)Lnet/minecraft/util/IChatComponent;", remap = false), cancellable = true, remap = true)
private void onClientChat(S02PacketChat packetIn, CallbackInfo ci) {
if (packetIn.getType() == 0) {
diff --git a/src/main/java/cc/polyfrost/oneconfig/mixin/NetworkManagerMixin.java b/src/main/java/cc/polyfrost/oneconfig/mixin/NetworkManagerMixin.java
new file mode 100644
index 0000000..e7a9396
--- /dev/null
+++ b/src/main/java/cc/polyfrost/oneconfig/mixin/NetworkManagerMixin.java
@@ -0,0 +1,23 @@
+package cc.polyfrost.oneconfig.mixin;
+
+import cc.polyfrost.oneconfig.events.EventManager;
+import cc.polyfrost.oneconfig.events.event.ReceivePacketEvent;
+import io.netty.channel.ChannelHandlerContext;
+import net.minecraft.network.NetworkManager;
+import net.minecraft.network.Packet;
+import org.spongepowered.asm.mixin.Mixin;
+import org.spongepowered.asm.mixin.injection.At;
+import org.spongepowered.asm.mixin.injection.Inject;
+import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
+
+@Mixin(value = NetworkManager.class, priority = Integer.MAX_VALUE)
+public class NetworkManagerMixin {
+ @Inject(method = "channelRead0(Lio/netty/channel/ChannelHandlerContext;Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true)
+ private void onReceivePacket(ChannelHandlerContext p_channelRead0_1_, Packet<?> p_channelRead0_2_, CallbackInfo ci) {
+ ReceivePacketEvent event = new ReceivePacketEvent(p_channelRead0_2_);
+ EventManager.INSTANCE.post(event);
+ if (event.isCancelled) {
+ ci.cancel();
+ }
+ }
+}