Skip to main content

BlockEntityPart

Trait BlockEntityPart 

pub trait BlockEntityPart: BlockPart {
Show 15 methods // Provided methods fn block_entity( &self, level: LevelSide<'_>, event: &mut BlockEntityEvent<'_>, ) -> Option<BTreeMap<JavaString, Tag>> { ... } fn block_entity_ticks( &self, host: &dyn Host, event: &mut BlockEntityTicksEvent<'_>, ) { ... } fn block_entity_tick( &self, host: &mut dyn ServerHost, event: &mut BlockEntityTickEvent<'_>, ) { ... } fn block_entity_update_tag( &self, event: &mut BlockEntityUpdateTagEvent<'_>, ) -> Option<BTreeMap<JavaString, Tag>> { ... } fn screen( &self, host: &dyn Host, event: &mut ScreenEvent<'_>, ) -> Option<Screen> { ... } fn screen_draw( &self, host: &dyn ClientHost, event: &mut ScreenDrawEvent<'_>, ) { ... } fn screen_click( &self, host: &dyn ClientHost, event: &mut ScreenClickEvent<'_>, ) -> Option<i32> { ... } fn screen_tooltip( &self, host: &dyn ClientHost, event: &mut ScreenTooltipEvent<'_>, ) { ... } fn menu_button( &self, host: &mut dyn ServerHost, event: &mut MenuButtonEvent<'_>, ) { ... } fn block_entity_submit( &self, host: &dyn ClientHost, event: &mut BlockEntitySubmitEvent<'_>, ) { ... } fn block_entity_render_bounding_box( &self, host: &dyn ClientHost, event: &mut BlockEntityRenderBoundingBoxEvent<'_>, ) { ... } fn menu_quick_move( &self, host: &mut dyn ServerHost, event: &mut MenuQuickMoveEvent<'_>, ) -> Flow { ... } fn block_entity_view_distance( &self, host: &dyn ClientHost, event: &mut BlockEntityViewDistanceEvent<'_>, ) { ... } fn pre_remove_side_effects( &self, level: &mut dyn LevelRandomHost, event: &mut PreRemoveSideEffectsEvent<'_>, ) { ... } fn stateful_block_entity( &self, host: &dyn Host, event: &mut StatefulBlockEntityEvent<'_>, ) { ... }
}
Expand description

A block’s part that also answers for its block entity, and for the block like a BlockPart.

Provided Methods§

fn block_entity( &self, level: LevelSide<'_>, event: &mut BlockEntityEvent<'_>, ) -> Option<BTreeMap<JavaString, Tag>>

Initial saved data for a declared block entity (EntityBlock.newBlockEntity), fired inside the write that creates it (LevelChunk.setBlockState), on a server and on a client of one. state is the actual placed state for a block declared through stateful_block_entity; its properties are available through the Host’s state registry. The declaration owns the type id. No answer creates no entity for a state-aware factory; other declared types start with an empty compound. The level is read-only, as newBlockEntity gets no level. Side: both.

Return Some to set entity; the first part returning Some wins.

fn block_entity_ticks( &self, host: &dyn Host, event: &mut BlockEntityTicksEvent<'_>, )

Whether block block’s block entity ticks (EntityBlock.getTicker): set ticks when it is yours. Asked for each of the block’s states when a world opens. Set ticks to true to make it tick, and never clear a value an earlier mod or mixin set. Side: server.

fn block_entity_tick( &self, host: &mut dyn ServerHost, event: &mut BlockEntityTickEvent<'_>, )

A server tick of the block entity at pos, in vanilla’s order among the others (Level.tickBlockEntities), when its id is yours: read and change its saved compound nbt, its item slots items (keep their count: as many as its container has, none without one) and the data slots its menu shows (data). It is out of the world during the call (the block entity at pos reads as a Mod with an empty id, and a save leaves it out); if the call removes or replaces it, entity is dropped. Clients, the window’s own in single player included, get what native_block_entity_update_tag gives when its chunk is sent or its block changes. Side: server.

fn block_entity_update_tag( &self, event: &mut BlockEntityUpdateTagEvent<'_>, ) -> Option<BTreeMap<JavaString, Tag>>

What clients get of the block entity at pos when its id is yours (BlockEntity.getUpdateTag): set tag to it, read from entity alone. Asked on the server whenever a chunk holding it is sent and whenever its block changes, on the server thread or, for a saved chunk sent past the view distance (lan::far), another one; a client’s copy of the block entity (made by native_block_entity there) merges it into its nbt. Leave it unset to send no tag of yours. A block change puts the one-shot fields of ModBlockEntityView::set_client_update_fields over it, and sends them alone when it is unset. Side: server.

Return Some to set tag; the first part returning Some wins.

fn screen(&self, host: &dyn Host, event: &mut ScreenEvent<'_>) -> Option<Screen>

A menu opens on this client for block block, a mod’s: set screen when the block is yours, to lay its screen out (native_screen_draw draws it). The server asks it too: a slot it hides is not in the menu there either, so shift-clicks never fill it. Side: both.

Return Some to set screen; the first part returning Some wins.

fn screen_draw(&self, host: &dyn ClientHost, event: &mut ScreenDrawEvent<'_>)

Draw block block‘s screen at origin (its top left, GUI pixels), over a plain panel with its slots’ frames and under the items and labels, from the menu’s data slots data (the block entity’s data on the server): data slots are 16-bit on the wire as in vanilla (a bigger value wraps), and data is empty until the server’s first values arrive, so read it with get. Draw with native_sprite, native_fill and native_text. Side: client.

fn screen_click( &self, host: &dyn ClientHost, event: &mut ScreenClickEvent<'_>, ) -> Option<i32>

A left or right (right) press at at (GUI pixels from the screen’s top left, so outside it too) on block block’s screen, a mod’s, over no slot: set button to a menu button id when it is on one of yours. Horizon sends it to the server (ContainerButtonClick, native_menu_button there) and the press goes no further. Side: client.

Return Some to set button; the first part returning Some wins.

fn screen_tooltip( &self, host: &dyn ClientHost, event: &mut ScreenTooltipEvent<'_>, )

The tooltip at at (as in native_screen_click) on block block’s screen, a mod’s, over no item: push its lines when it is over something of yours. Legacy colour codes (§) work. Side: client.

Every part gets event.lines in order and may add, change or remove lines.

fn menu_button( &self, host: &mut dyn ServerHost, event: &mut MenuButtonEvent<'_>, )

A player pressed a mod container’s button (clickMenuButton), on the server. The block entity is out of the world during the call; mods may change it and the clicking player’s carried stack. Side: server.

fn block_entity_submit( &self, host: &dyn ClientHost, event: &mut BlockEntitySubmitEvent<'_>, )

Draw the mod block entity at pos, of block block (mymod:machine), on this client: once a frame while it is in view (vanilla’s BlockEntityRenderer.submit: within its view distance, 64 blocks unless block_entity_view_distance says otherwise, its chunk faded in, and its bounds, native_block_entity_render_bounding_box, in the frustum), when its id is yours. state is the block’s state (blockEntity.getBlockState(): read its facing with native_block_state_property), entity holds what the server sent (native_block_entity_update_tag). Add geometry with native_draw_quad, native_draw_cube, native_draw_block and native_draw_item under draw’s pose stack, which starts at the block’s lower north-west corner, in blocks; draw also has the partial tick, the game time and the block’s light. Side: client.

fn block_entity_render_bounding_box( &self, host: &dyn ClientHost, event: &mut BlockEntityRenderBoundingBoxEvent<'_>, )

Where the mod block entity at pos draws, for culling (NeoForge’s getRenderBoundingBox): bounds is min x, y, z then max x, y, z, in blocks from the block’s lower north-west corner. It starts as the block with a block of margin around it; widen it when your native_block_entity_submit draws further (a tall shaft, a beam), or set an infinite value for one never culled. Asked once a frame for each within its view distance (block_entity_view_distance) whose chunk is drawn. Side: client.

Every part gets event.bounds in order and may add, change or remove bounds.

fn menu_quick_move( &self, host: &mut dyn ServerHost, event: &mut MenuQuickMoveEvent<'_>, ) -> Flow

A player shift-clicked slot slot of the menu of the mod block entity at pos (AbstractContainerMenu.quickMoveStack, the method a Java menu overrides), on the server, before the game’s own routing: move the stack where your block wants it. slot is the menu’s index: below container_slots it is the block’s own slot (entity.items), from there on the player’s inventory (27 main slots, then the hotbar). stack is a copy of what the slot holds; take what you move out of it (put it in entity.items, or in another block through its ITEMS capability) and set handled: the slot then holds what is left of stack (whatever you wrote to that slot of entity.items), the game’s routing is skipped, and the player’s client gets the menu again. Left unhandled, entity.items goes back to what it held and the game moves the stack as for any container; a later mod sees what an earlier one did to stack.

For a mod container on a vanilla menu type and on a mod menu type, the left or right button, a slot that holds something and that the mod’s screen shows; not for a spectator or a dead player, a menu no longer valid, nor during a drag. Asked once per click, where vanilla asks quickMoveStack again while it keeps moving the same item. The player’s state is swapped in, so host.players().acting_player() names them; entity is out of the world during the call, as in native_menu_button. Side: server.

Return Flow::Cancel to take it: this sets handled, and later parts are skipped.

fn block_entity_view_distance( &self, host: &dyn ClientHost, event: &mut BlockEntityViewDistanceEvent<'_>, )

How far from the camera the mod block entity of block block draws, in blocks (vanilla’s BlockEntityRenderer.getViewDistance): 64 unless a part answers. Set distance for your own block: further for something seen from afar (a beacon-like beam, a large display), nearer for small detail. It is asked once for each mod block, the first time this client draws block entities, and kept: never per frame. A value that isn’t finite and above 0 is ignored. Beyond NeoForge: the renderer’s own method, no event. Side: client.

Every part gets event.distance in order and may add, change or remove distance.

fn pre_remove_side_effects( &self, level: &mut dyn LevelRandomHost, event: &mut PreRemoveSideEffectsEvent<'_>, )

BlockEntity.preRemoveSideEffects of a mod’s block entity: an authoritative server is removing entity from pos, where the block state stood, and its updates may have side effects (not under flag 256, UPDATE_SKIP_BLOCK_ENTITY_SIDEEFFECTS). Put in drops the stacks it held that the game doesn’t: they scatter as Containers.dropItemStack scatters them, after the block entity’s own container. The block entity is still in place, so its attachments read as they were. Answered from inside the level’s write: don’t change the world here. Side: server.

Every part gets event.drops in order and may add, change or remove drops.

fn stateful_block_entity( &self, host: &dyn Host, event: &mut StatefulBlockEntityEvent<'_>, )

Opt a block with a registered block entity type into state-aware creation. Asked once per block when a level’s immutable factory ownership table is built. Set true and never clear an earlier answer. For these blocks, block_entity receives the actual state and no answer creates no entity. Existing entities survive property changes within the same block. Side: both.

Trait Implementations§

§

impl Wire for Box<dyn BlockEntityPart>

§

const MIN: usize = 8

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<Box<dyn BlockEntityPart>, WireError>

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

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§