Skip to main content

BlockEntity

Trait BlockEntity 

Source
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§

Source

fn base(&self) -> &BlockEntityBase

Returns the common metadata owned by this block entity.

Source

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.

Source

fn save_additional(&self, nbt: &mut NbtCompound)

Saves additional data to NBT.

Called when saving the block entity to disk.

Provided Methods§

Source

fn get_type(&self) -> BlockEntityTypeRef

Returns the type of this block entity.

Source

fn get_block_pos(&self) -> BlockPos

Returns the position of this block entity in the world.

Source

fn get_block_state(&self) -> BlockStateId

Returns the current block state associated with this entity.

Source

fn is_valid_block_state(&self, state: BlockStateId) -> bool

Returns whether this entity’s registered type accepts state.

Mirrors Vanilla BlockEntity.isValidBlockState.

Source

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.

Source

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.

Source

fn on_clear_removed(&self)

Called after this entity transitions from removed back to active.

Storage locks are not held during this callback.

Source

fn set_changed(&self)

Called when the block entity’s data changes.

Marks the containing chunk as dirty so changes are persisted to disk.

Source

fn get_level(&self) -> Option<Arc<World>>

Gets the world reference if still valid.

Block entities receive a Weak<World> at construction time.

Source

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.

Source

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 entity
  • state - The block state being removed
Source

fn save_custom_only(&self) -> NbtCompound

Saves only entity-specific data, excluding vanilla type and position metadata.

Source

fn save_with_full_metadata(&self) -> NbtCompound

Saves command-visible data together with vanilla block-entity metadata.

Source

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.

Source

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.

Source

fn container_ref(&self) -> Option<ContainerRef>

Returns the independently lockable container capability owned by this entity.

Source

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".

Implementors§