pub trait BlockEntity:
ErasedType
+ Send
+ Sync {
Show 20 methods
// Required methods
fn base(&self) -> &BlockEntityBase;
fn load_additional(&self, nbt: &BorrowedNbtCompound<'_>);
fn save_additional(&self, nbt: &mut NbtCompound);
// Provided methods
fn get_type(&self) -> BlockEntityTypeRef { ... }
fn get_block_pos(&self) -> BlockPos { ... }
fn get_block_state(&self) -> BlockStateId { ... }
fn is_valid_block_state(&self, state: BlockStateId) -> bool { ... }
fn on_block_state_changed(&self, _state: BlockStateId) { ... }
fn on_set_removed(&self) { ... }
fn on_clear_removed(&self) { ... }
fn set_changed(&self) { ... }
fn get_level(&self) -> Option<Arc<World>> { ... }
fn trigger_event(&self, _param_a: i32, _param_b: i32) -> bool { ... }
fn pre_remove_side_effects(&self, pos: BlockPos, state: BlockStateId) { ... }
fn save_custom_only(&self) -> NbtCompound { ... }
fn save_with_full_metadata(&self) -> NbtCompound { ... }
fn get_update_tag(&self) -> Option<NbtCompound> { ... }
fn tick(&self, world: &Arc<World>) { ... }
fn container_ref(&self) -> Option<ContainerRef> { ... }
fn game_event_listener(&self) -> Option<SharedGameEventListener> { ... }
}Expand description
Trait for all block entities.
Block entities are attached to specific blocks in the world and provide
additional data storage beyond what block states can hold. Concrete
implementations must claim a unique steel_utils::DowncastTypeKey through
steel_utils::DowncastType.
Required Methods§
Sourcefn base(&self) -> &BlockEntityBase
fn base(&self) -> &BlockEntityBase
Returns the common metadata owned by this block entity.
Sourcefn load_additional(&self, nbt: &BorrowedNbtCompound<'_>)
fn load_additional(&self, nbt: &BorrowedNbtCompound<'_>)
Loads additional data from NBT.
Called when loading the block entity from disk or receiving initial chunk data from the server.
Sourcefn save_additional(&self, nbt: &mut NbtCompound)
fn save_additional(&self, nbt: &mut NbtCompound)
Saves additional data to NBT.
Called when saving the block entity to disk.
Provided Methods§
Sourcefn get_block_pos(&self) -> BlockPos
fn get_block_pos(&self) -> BlockPos
Returns the position of this block entity in the world.
Sourcefn get_block_state(&self) -> BlockStateId
fn get_block_state(&self) -> BlockStateId
Returns the current block state associated with this entity.
Sourcefn is_valid_block_state(&self, state: BlockStateId) -> bool
fn is_valid_block_state(&self, state: BlockStateId) -> bool
Returns whether this entity’s registered type accepts state.
Mirrors Vanilla BlockEntity.isValidBlockState.
Sourcefn on_block_state_changed(&self, _state: BlockStateId)
fn on_block_state_changed(&self, _state: BlockStateId)
Called after the cached block state changes.
Storage and section locks are not held during this callback. This is Steel’s staged
equivalent of Vanilla block entities overriding setBlockState; implementations should
derive any cached fields from state here.
Sourcefn on_set_removed(&self)
fn on_set_removed(&self)
Called after each invocation that marks this entity removed.
Storage locks are not held during this callback. This mirrors Vanilla overrides of
setRemoved, which run even if the entity was already marked removed.
Sourcefn on_clear_removed(&self)
fn on_clear_removed(&self)
Called after this entity transitions from removed back to active.
Storage locks are not held during this callback.
Sourcefn set_changed(&self)
fn set_changed(&self)
Called when the block entity’s data changes.
Marks the containing chunk as dirty so changes are persisted to disk.
Sourcefn get_level(&self) -> Option<Arc<World>>
fn get_level(&self) -> Option<Arc<World>>
Gets the world reference if still valid.
Block entities receive a Weak<World> at construction time.
Sourcefn trigger_event(&self, _param_a: i32, _param_b: i32) -> bool
fn trigger_event(&self, _param_a: i32, _param_b: i32) -> bool
Handles a block event delegated by the owning block behavior.
Mirrors Vanilla BlockEntity.triggerEvent.
Sourcefn pre_remove_side_effects(&self, pos: BlockPos, state: BlockStateId)
fn pre_remove_side_effects(&self, pos: BlockPos, state: BlockStateId)
Called before the block entity is removed to handle side effects.
For example, containers should drop their contents here.
§Arguments
pos- The position of the block entitystate- The block state being removed
Sourcefn save_custom_only(&self) -> NbtCompound
fn save_custom_only(&self) -> NbtCompound
Saves only entity-specific data, excluding vanilla type and position metadata.
Sourcefn save_with_full_metadata(&self) -> NbtCompound
fn save_with_full_metadata(&self) -> NbtCompound
Saves command-visible data together with vanilla block-entity metadata.
Sourcefn get_update_tag(&self) -> Option<NbtCompound>
fn get_update_tag(&self) -> Option<NbtCompound>
Returns the NBT data to send to clients for initial sync.
This is included in the chunk data packet when the chunk is first sent.
Return None if no client sync is needed.
Sourcefn tick(&self, world: &Arc<World>)
fn tick(&self, world: &Arc<World>)
Called every game tick for ticking block entities.
The live block behavior selects this callback through its block-entity ticker, matching Vanilla’s state-owned ticker selection.
Sourcefn container_ref(&self) -> Option<ContainerRef>
fn container_ref(&self) -> Option<ContainerRef>
Returns the independently lockable container capability owned by this entity.
Sourcefn game_event_listener(&self) -> Option<SharedGameEventListener>
fn game_event_listener(&self) -> Option<SharedGameEventListener>
Returns this entity’s fixed game-event listener, if it provides one.
Mirrors Vanilla GameEventListener.Provider.getListener. The owning block behavior keeps
final selection authority through BlockBehavior::get_game_event_listener.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".