Package net.minecraft.network.syncher
Class SynchedEntityData
java.lang.Object
net.minecraft.network.syncher.SynchedEntityData
Keeps data in sync from server to client for an entity.
A maximum of 254 parameters per entity class can be registered. The system then ensures that these values are updated on the client whenever they change on the server.
Use
defineId(java.lang.Class<? extends net.minecraft.network.syncher.SyncedDataHolder>, net.minecraft.network.syncher.EntityDataSerializer<T>) to register a piece of data for your entity class.
Use SynchedEntityData.Builder.define(net.minecraft.network.syncher.EntityDataAccessor<T>, T) during Entity#defineSynchedData to set the default value for a given parameter.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classstatic classstatic final record -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final SyncedDataHolder(package private) static final ClassTreeIdRegistryprivate booleanprivate final SynchedEntityData.DataItem<?>[]private static final org.slf4j.Loggerprivate static final intprivate static final StackWalker -
Constructor Summary
ConstructorsConstructorDescriptionSynchedEntityData(SyncedDataHolder entity, SynchedEntityData.DataItem<?>[] itemsById) -
Method Summary
Modifier and TypeMethodDescriptionprivate <T> voidassignValue(SynchedEntityData.DataItem<T> target, SynchedEntityData.DataValue<?> entry) voidassignValues(List<SynchedEntityData.DataValue<?>> entries) Updates the data using the given entries.static <T> EntityDataAccessor<T> defineId(Class<? extends SyncedDataHolder> clazz, EntityDataSerializer<T> serializer) Register a piece of data to be kept in sync for an entity class.<T> Tget(EntityDataAccessor<T> key) Get the value of the given key for this entity.private <T> SynchedEntityData.DataItem<T> getItem(EntityDataAccessor<T> key) @Nullable List<SynchedEntityData.DataValue<?>> booleanisDirty()@Nullable List<SynchedEntityData.DataValue<?>> <T> voidset(EntityDataAccessor<T> key, T value) Set the value of the given key for this entity.<T> voidset(EntityDataAccessor<T> key, T value, boolean force)
-
Field Details
-
LOGGER
private static final org.slf4j.Logger LOGGER -
MAX_ID_VALUE
private static final int MAX_ID_VALUE- See Also:
-
ID_REGISTRY
-
entity
-
itemsById
-
isDirty
private boolean isDirty -
STACK_WALKER
-
-
Constructor Details
-
SynchedEntityData
SynchedEntityData(SyncedDataHolder entity, SynchedEntityData.DataItem<?>[] itemsById)
-
-
Method Details
-
defineId
public static <T> EntityDataAccessor<T> defineId(Class<? extends SyncedDataHolder> clazz, EntityDataSerializer<T> serializer) Register a piece of data to be kept in sync for an entity class. This method must be called during a static initializer of an entity class and the first parameter of this method must be that entity class. -
getItem
-
get
Get the value of the given key for this entity. -
set
Set the value of the given key for this entity. -
set
-
isDirty
public boolean isDirty() -
packDirty
-
getNonDefaultValues
-
assignValues
Updates the data using the given entries. Used on the client when the update packet is received. -
assignValue
private <T> void assignValue(SynchedEntityData.DataItem<T> target, SynchedEntityData.DataValue<?> entry)
-