Packets
Packets are the data classes that the Minecraft client and server use to communicate and share information about the game state.
They are responsible for synchronizing nearly every part of the game, including:
- Player movement
- Chat messages
- Entity updates
- Inventory updates
- Combat actions
Listening to packets
You need to mixin into the Connection class to be able to listen for the packets being received and sent, and cancel them if you want to.
Code example
kotlin
@Mixin(Connection.class)
public class ConnectionMixin {
@Inject(method = "channelRead0*", at = @At(value = "INVOKE", target = "Lnet/minecraft/network/Connection;genericsFtw(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketListener;)V"), cancellable = true)
private void onChannelRead(ChannelHandlerContext context, Packet<?> packet, CallbackInfo ci) {
// Do something with the packet being received.
// You can run ci.cancel(); to stop Minecraft from processing the packet.
}
@Inject(method = "sendPacket(Lnet/minecraft/network/protocol/Packet;Lio/netty/channel/ChannelFutureListener;Z)V", at = @At("HEAD"), cancellable = true)
private void onSendPacket(Packet<?> packet, ChannelFutureListener channelFutureListener, boolean bl, CallbackInfo ci) {
// Do something with the packet being sent
// You can run ci.cancel(); to stop Minecraft from sending the packet.
}
}