Struct BlockEntityRef
pub struct BlockEntityRef { /* private fields */ }Expand description
One block entity in an open level, identified by its lifecycle generation.
Removal, replacement or chunk reload invalidates the handle, even at the same
position. In-place data edits and temporary tick take/put preserve identity.
Stale handles read as None; Result-returning methods report Stale.
Implementations§
§impl BlockEntityRef
impl BlockEntityRef
pub fn kind(self, host: &dyn Host) -> Option<BlockEntityTypeKey>
pub fn kind(self, host: &dyn Host) -> Option<BlockEntityTypeKey>
Side: both.
The block entity’s type (BlockEntity.getType).
pub fn data(self, host: &dyn Host) -> Option<BTreeMap<JavaString, Tag>>
pub fn data(self, host: &dyn Host) -> Option<BTreeMap<JavaString, Tag>>
Side: both.
The data saved without identity or position metadata
(BlockEntity.saveWithoutMetadata).
pub fn lock(self, host: &dyn Host) -> Option<BTreeMap<JavaString, Tag>>
pub fn lock(self, host: &dyn Host) -> Option<BTreeMap<JavaString, Tag>>
Side: both. The vanilla lock’s item predicate, if present on a loaded block entity.
pub fn name(self, host: &dyn Host) -> Option<String>
pub fn name(self, host: &dyn Host) -> Option<String>
Side: server.
The custom name (Nameable.getCustomName) as plain text. None when the block entity
has none or isn’t nameable (chests, barrels, furnaces, hoppers, brewing stands,
banners, beacons, enchanting tables, command blocks…), or for a stale handle or a
client.
pub fn viewers(self, host: &dyn Host) -> Option<Vec<PlayerRef>>
pub fn viewers(self, host: &dyn Host) -> Option<Vec<PlayerRef>>
Side: server.
The players whose open menu holds this block entity’s container (for openers’
containers, ContainerOpenersCounter.getEntitiesWithContainerOpen’s players), from the menus the opener counts read
(tick_mod_container_viewers, ChestBlockEntity$1.isOwnContainer). Guests in
its level, not spectators nor fake players, then the acting player for a menu
their action opened, which the hub records when the action ends. None for a
stale handle or a client.
pub fn data_slots(self, host: &dyn Host) -> Option<Vec<i32>>
pub fn data_slots(self, host: &dyn Host) -> Option<Vec<i32>>
Side: both. A snapshot of a mod block entity’s menu data slots, on the server or in the client’s copy. None for a stale/missing/vanilla entity. Item storage is separate.
pub fn item_slot(
self,
host: &dyn Host,
slot: u32,
) -> Result<Option<ItemStack>, BlockEntityItemError>
pub fn item_slot( self, host: &dyn Host, slot: u32, ) -> Result<Option<ItemStack>, BlockEntityItemError>
Side: both. Read a configured mod holder’s declared internal item slot, without automation policy. Removed, replaced or reloaded holders return BlockEntityItemError::Stale.
pub fn set_lock(
self,
host: &mut dyn ServerHost,
lock: Option<BTreeMap<JavaString, Tag>>,
) -> Result<bool, BlockEntityError>
pub fn set_lock( self, host: &mut dyn ServerHost, lock: Option<BTreeMap<JavaString, Tag>>, ) -> Result<bool, BlockEntityError>
Side: server. Change the lock through the same storage used by container opening and saving.
pub fn merge_data(
self,
host: &mut dyn ServerHost,
data: BTreeMap<JavaString, Tag>,
) -> Result<bool, BlockEntityError>
pub fn merge_data( self, host: &mut dyn ServerHost, data: BTreeMap<JavaString, Tag>, ) -> Result<bool, BlockEntityError>
Side: server.
Merges data into the block entity’s saved data and loads it, as /data merge block
does (BlockDataAccessor.setData: loadWithComponents, setChanged, then
sendBlockUpdated, so comparators re-read it and clients get the update). id, x,
y and z in data are ignored. Ok(true) when data changed; Ok(false) for data
nested too deep, no change, or data the entity cannot load. Stale or unwritable
handles return BlockEntityError::Stale. Inside a transaction an
abort puts the block entity, its name, lock, loot table roll and attachments back.
pub fn replace_data(
self,
host: &mut dyn ServerHost,
data: BTreeMap<JavaString, Tag>,
) -> Result<bool, BlockEntityError>
pub fn replace_data( self, host: &mut dyn ServerHost, data: BTreeMap<JavaString, Tag>, ) -> Result<bool, BlockEntityError>
Side: server.
Replaces the saved payload, retaining identity and position metadata.
Uses the same transactional load and client update path as merge_data.
Ok(false) for unsupported data or no change; Stale for an invalidated handle.
pub fn set_changed(
self,
host: &mut dyn ServerHost,
) -> Result<bool, BlockEntityError>
pub fn set_changed( self, host: &mut dyn ServerHost, ) -> Result<bool, BlockEntityError>
Side: server.
BlockEntity.setChanged: the chunk is saved again and comparators re-read the
container (updateNeighbourForOutputSignal). Inside a transaction it runs once at the
root commit. Returns Stale for an invalidated handle or a level not writable here.
pub fn set_name(
self,
host: &mut dyn ServerHost,
name: Option<&str>,
) -> Result<bool, BlockEntityError>
pub fn set_name( self, host: &mut dyn ServerHost, name: Option<&str>, ) -> Result<bool, BlockEntityError>
Side: server.
Sets the custom name, or clears it with None, as an anvil-renamed item placed with
components sets CustomName. Plain text only. Clients get a block entity update.
Ok(false) for an entity that is not nameable; Stale for an invalidated or
unwritable handle. Inside a transaction an abort puts the name back.
pub fn set_data_slot(
self,
host: &mut dyn ServerHost,
slot: u32,
value: i32,
) -> Result<bool, BlockEntityError>
pub fn set_data_slot( self, host: &mut dyn ServerHost, slot: u32, value: i32, ) -> Result<bool, BlockEntityError>
Side: server. Set a mod block entity’s menu data slot in place, joining the current transaction and its setChanged notice. Ok(false) for a vanilla entity, an invalid slot or no change; Stale for an invalidated or unwritable handle. Does not resize slots.
pub fn set_data_slots(
self,
host: &mut dyn ServerHost,
values: Vec<i32>,
) -> Result<bool, BlockEntityDataError>
pub fn set_data_slots( self, host: &mut dyn ServerHost, values: Vec<i32>, ) -> Result<bool, BlockEntityDataError>
Side: server. Sizes a mod block entity’s menu data explicitly, using the same write target, journal and Changed notice as scalar data-slot writes. Removed, replaced or reloaded holders return BlockEntityDataError::Stale.
pub fn set_item_slot(
self,
host: &mut dyn ServerHost,
tx: &Transaction,
slot: u32,
stack: Option<ItemStack>,
) -> Result<bool, BlockEntityItemError>
pub fn set_item_slot( self, host: &mut dyn ServerHost, tx: &Transaction, slot: u32, stack: Option<ItemStack>, ) -> Result<bool, BlockEntityItemError>
Side: server. Replace internal storage under the existing transaction; external ITEMS routing is separate. Removed, replaced or reloaded holders return BlockEntityItemError::Stale.
Trait Implementations§
§impl Clone for BlockEntityRef
impl Clone for BlockEntityRef
§fn clone(&self) -> BlockEntityRef
fn clone(&self) -> BlockEntityRef
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more