BlockEntityStateManager¶
object BlockEntityStateManager
Server-side manager for tracking and syncing block entity state to clients.
This manager:
-
Maintains a registry of block entities by position
-
Tracks which properties have changed on each block entity
-
Sends state packets to players who are observing each block entity
-
Cleans up state when block entities are unloaded
Functions¶
addTrackedPlayer¶
fun addTrackedPlayer(blockEntity: BlockEntity, player: ServerPlayer)
Adds a player to the tracking list for a block entity.
The player will receive state packets when the block entity changes.
Parameters
-
blockEntity: The block entity.
-
player: The player to add.
clear¶
fun clear()
Clears all tracking data.
Useful for cleanup on server shutdown.
getContainer¶
fun getContainer(blockEntity: BlockEntity): BlockEntityStateContainer?
Gets the state container for a block entity, if it exists.
Return
The state container, or null if not registered.
Parameters
- blockEntity: The block entity.
hasTrackedPlayers¶
fun hasTrackedPlayers(blockEntity: BlockEntity): Boolean
Whether anyone is still tracking blockEntity - see unregisterBlockEntity's own caveat.
init¶
fun init()
Registers the server tick listener that drives syncDirtyEntities every tick.
Must be called once during mod init.
registerBlockEntity¶
fun registerBlockEntity(blockEntity: BlockEntity): BlockEntityStateContainer
Registers a block entity for state tracking.
Should be called when a container menu is opened for a block entity.
Return
The state container for this block entity.
Parameters
- blockEntity: The block entity to track.
removeTrackedPlayer¶
fun removeTrackedPlayer(blockEntity: BlockEntity, player: ServerPlayer)
Removes a player from the tracking list for a block entity.
Parameters
-
blockEntity: The block entity.
-
player: The player to remove.
syncDirtyEntities¶
fun syncDirtyEntities(currentTick: Long, networkChannel: (BlockEntityStatePacket, List<ServerPlayer>) -> Unit = DEFAULT_NETWORK_SENDER)
Syncs all dirty block entities to their tracked players.
Should be called once per server tick via a tick event.
Parameters
-
currentTick: The current server tick.
-
networkChannel: The network channel to send packets through.
unregisterBlockEntity¶
fun unregisterBlockEntity(blockEntity: BlockEntity)
Unregisters a block entity from state tracking.
Should be called when a container menu is closed.
Parameters
- blockEntity: The block entity to untrack.