Changes

Update to 1.17
Line 19: Line 19:  
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.
 
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 <code><nowiki>DataParameter<T></nowiki></code> for the data you wish to keep synchronized. This should be stored as a static final field in your entity class, obtained by calling <code><nowiki>EntityDataManager.createKey()</nowiki></code> 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 <code><nowiki>DataSerializers</nowiki></code> class.
+
Firstly you need a <code><nowiki>EntityDataAccessor<T></nowiki></code> for the data you wish to keep synchronized. This should be stored as a static final field in your entity class, obtained by calling <code><nowiki>SynchedEntityData.defineId()</nowiki></code> 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 <code><nowiki>EntityDataSerializers</nowiki></code> class.
    
{{Colored box|title=Alert|content=You should '''only''' create data parameters for your own entities, ''within that entity's class''. Adding parameters to entities you do not control can cause the IDs used to send that data over the network to become desynchronized, causing difficult to debug crashes.}}
 
{{Colored box|title=Alert|content=You should '''only''' create data parameters for your own entities, ''within that entity's class''. Adding parameters to entities you do not control can cause the IDs used to send that data over the network to become desynchronized, causing difficult to debug crashes.}}
      −
Then, override <code><nowiki>registerData()</nowiki></code> and call <code><nowiki>this.dataManager.register()</nowiki></code> for each of your data parameters, passing the parameter and an initial value to use. Remember to always call <code><nowiki>super.registerData()</nowiki></code> first!
+
Then, override <code><nowiki>Entity#defineSynchedData()</nowiki></code> and call <code><nowiki>this.entityData.define(...)</nowiki></code> for each of your data parameters, passing the parameter and an initial value to use. Remember to always call <code><nowiki>super.defineSynchedData()</nowiki></code> first!
   −
You can then get and set these values via your entity's <code><nowiki>dataManager</nowiki></code> instance. Changes made will be synchronized to the client automatically.
+
You can then get and set these values via your entity's <code><nowiki>entityData</nowiki></code> instance. Changes made will be synchronized to the client automatically.