Networking with Entities
In addition to regular network messages, there are various other systems provided to handle synchronizing entity data.
In general, the spawning of modded entities is handled seperately, by Forge.
You can add extra data to the spawn packet Forge sends by implementing the following interface.
If your entity has data that is needed on the client, but doesn't change over time, then it can be added to the entity spawn packet using this interface.
readSpawnData() control how the data should be en/decoded to/from the network buffer.
This is the main vanilla system for synchronizing entity data from the server to the client. As such, a number of vanilla examples are available to refer to.
Firstly you need a
EntityDataAccessor<T> for the data you wish to keep synchronized. This should be stored as a static final field in your entity class, obtained by calling
SynchedEntityData.defineId() and passing the entity class and a serializer for that type of data. The available serializer implementations can be found as static constants within the
Entity#defineSynchedData() and call
this.entityData.define(...) for each of your data parameters, passing the parameter and an initial value to use. Remember to always call
You can then get and set these values via your entity's
entityData instance. Changes made will be synchronized to the client automatically.