Skip to main content

BlockEntityRef

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

pub fn kind(self, host: &dyn Host) -> Option<BlockEntityTypeKey>

Side: both. The block entity’s type (BlockEntity.getType).

pub fn position(self, host: &dyn Host) -> Option<[i32; 3]>

Side: both. The block entity’s position.

pub fn level(self, host: &dyn Host) -> Option<LevelRef>

Side: both. The block entity’s level.

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

Side: both. The vanilla lock’s item predicate, if present on a loaded block entity.

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

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

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>

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>

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>

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>

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>

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>

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>

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>

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>

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

§

fn clone(&self) -> BlockEntityRef

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
§

impl Copy for BlockEntityRef

§

impl Debug for BlockEntityRef

§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
§

impl Eq for BlockEntityRef

§

impl Hash for BlockEntityRef

§

fn hash<__H>(&self, state: &mut __H)
where __H: Hasher,

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
§

impl PartialEq for BlockEntityRef

§

fn eq(&self, other: &BlockEntityRef) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
§

impl StructuralPartialEq for BlockEntityRef

§

impl Wire for BlockEntityRef

§

const MIN: usize

Minimum encoded size, used to reject impossible collection lengths.
§

fn put(&self, out: &mut Writer)

Encodes this value, recording failures on the writer.
§

fn put_owned(self, out: &mut Writer)

Consumes owned data when a resource’s ownership must cross the boundary.
§

fn take(input: &mut Reader<'_>) -> Result<BlockEntityRef, WireError>

Decodes one value, leaving any following bytes for the caller.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Put for T
where T: Wire,

§

fn put_to(&self, out: &mut Writer)

Writes it.
§

impl<T> Record for T
where T: Wire,

§

fn encode(&self, out: &mut Writer)

Writes the argument into a hook call.
§

fn apply(&mut self, bytes: &[u8]) -> Result<(), WireError>

Applies one complete reply, refusing malformed or trailing bytes atomically.
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.