Interface AttachmentSyncHandler<T>
Sync is handled automatically in the following cases:
- A client is receiving initial data for this attachment holder.
- An attachment is default-created through
IAttachmentHolder.getData(AttachmentType). - An attachment is updated through
IAttachmentHolder.setData(AttachmentType, Object). - An attachment is removed through
IAttachmentHolder.removeData(AttachmentType).
For other cases such as modifications to mutable synced attachments,
IAttachmentHolder.syncData(AttachmentType) can be called to trigger syncing.
-
Method Summary
Modifier and TypeMethodDescriptionread(IAttachmentHolder holder, RegistryFriendlyByteBuf buf, T previousValue) Reads attachment data on the client side.default booleansendToPlayer(IAttachmentHolder holder, ServerPlayer to) Decides whether data should be sent to some player that can see the holder.voidwrite(RegistryFriendlyByteBuf buf, T attachment, boolean initialSync) Writes attachment data to a buffer.
-
Method Details
-
sendToPlayer
Decides whether data should be sent to some player that can see the holder.By default, all players that can see the holder are sent the data. A typical use case for this method is to only send player-specific data to that player.
The returned value should be consistent for a given holder and player.
- Parameters:
holder- the holder for the attachment, can be cast if the subtype is knownto- the player that might receive the data- Returns:
trueto send data to the player,falseotherwise
-
write
Writes attachment data to a buffer.If
initialSyncistrue, the data should be written in full because the client does not have any previous data.If
initialSyncisfalse, the client already received a previous version of the data. In this case, this method is only called once for the attachment, and the resulting data is broadcast to all relevant players.If nothing is written to the buffer, nothing is sent to the client at all, and
read(net.neoforged.neoforge.attachment.IAttachmentHolder, net.minecraft.network.RegistryFriendlyByteBuf, T)will not be called on the client side. -
read
Reads attachment data on the client side.- Parameters:
holder- the attachment holder, can be cast if the subtype is knownpreviousValue- the previous value of the attachment, ornullif there was no previous value- Returns:
- the new value of the attachment, or
nullif the attachment should be removed
-