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(); } } }