For anyone else looking for this in the future, create mixins for net.minecraft.network.NetworkManager like so:
@Inject(method = "sendPacket(Lnet/minecraft/network/Packet;)V", at = @At("HEAD"), cancellable = true)
private void onSendPacket(Packet<?> packet, CallbackInfo callbackInfo)
{
//System.out.println("Packet Sent: " + packet.toString());
PacketSent event = new PacketSent(packet);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled() && callbackInfo.isCancellable())
{
callbackInfo.cancel();
}
packet = event.packet;
}
@Inject(method = "channelRead0", at = @At("HEAD"), cancellable = true)
private void onChannelRead(ChannelHandlerContext context, Packet<?> packet, CallbackInfo callbackInfo)
{
//System.out.println("Packet Recieved: " + packet.toString());
PacketRecieved event = new PacketRecieved(packet);
MinecraftForge.EVENT_BUS.post(event);
if (event.isCanceled() && callbackInfo.isCancellable())
{
callbackInfo.cancel();
}
packet = event.packet;
}
PacketSent and PacketRecieved are custom events that you can make yourself by making a class that extends Event.