Minecraft Modding: Intercepting Vanilla Packets

Background


As you hopefully are aware, Minecraft is implemented as a server and client(s) even in single-player mode. In order to synchronize the game on both "sides" there are networking packets sent. For your own mods you can make custom packets (see Custom Packet Tutorial); however, there may be cases where you wish to detect, filter or modify the vanilla packets.

Here is some information from diesieben07 on how you can intercept vanilla packets:


  • Use ClientConnectedToServerEvent or ServerConnectionFromClientEvent depending on which side you care about.
  • From that event you have access to the NetworkManager, then through the channel() method the netty-channel and then finally the ChannelPipeline using the pipeline() method.
  • You can now insert your own ChannelHandler into the pipeline. To see how the vanilla pipeline is structured, look at e.g. NetworkManager.provideLanClient, NetworkManager#provideLocalClient, NetworkSystem#addLanEndpoint and NetworkSystem#addLocalEndpoint.


1 comment: