Skip to main content

BlockEntityDrawContext

Trait BlockEntityDrawContext 

pub trait BlockEntityDrawContext {
Show 22 methods // Provided methods fn push(&mut self) { ... } fn pop(&mut self) { ... } fn translate(&mut self, by: [f32; 3]) { ... } fn rotate_about(&mut self, axis: [f32; 3], degrees: f32, pivot: [f32; 3]) { ... } fn scale(&mut self, by: [f32; 3]) { ... } fn keep(&mut self) { ... } fn partial(&self) -> f32 { ... } fn game_time(&self) -> i64 { ... } fn light(&self) -> u32 { ... } fn set_light(&mut self, light: u32) { ... } fn quad( &mut self, sprite: &str, corners: [[f32; 3]; 4], uv: [f32; 4], tint: u32, ) -> bool { ... } fn cube( &mut self, from: [f32; 3], to: [f32; 3], faces: [Option<CubeFace<'_>>; 6], tint: u32, ) -> bool { ... } fn block(&mut self, block: BlockKey, properties: &[(&str, &str)]) -> bool { ... } fn item( &mut self, stack: &ItemStack, display: ItemDisplayContext, owner_yaw: Option<f32>, seed: i32, ) -> bool { ... } fn spin( &mut self, axis: [f32; 3], pivot: [f32; 3], degrees_per_tick: f32, phase: f32, ) { ... } fn still(&mut self) { ... } fn model(&mut self, model: ModelRef, tint: u32) -> Result<(), ModelError> { ... } fn terrain_model( &mut self, model: ModelRef, options: TerrainModelOptions<'_>, ) -> Result<(), TerrainModelError> { ... } fn text( &mut self, text: &Text, at: [f32; 2], color: u32, glowing: bool, outline: u32, ) -> Result<f32, TextFormError> { ... } fn text_width(&self, text: &str) -> f32 { ... } fn model_part(&mut self, part: &ModelPart, sprite: &str, tint: u32) -> bool { ... } fn fluid_box( &mut self, stack: &FluidStack, bounds: [f32; 6], options: FluidBoxOptions, ) -> Result<(), FluidBoxError> { ... }
}
Expand description

What a block entity, mob or player submit hook draws with, in blocks under a pose stack (PoseStack): one per hook call.

Provided Methods§

fn push(&mut self)

PoseStack.pushPose: pop comes back to the pose as it is now.

fn pop(&mut self)

PoseStack.popPose; the block’s own pose is never popped.

fn translate(&mut self, by: [f32; 3])

Moves what is drawn next by by, in blocks.

fn rotate_about(&mut self, axis: [f32; 3], degrees: f32, pivot: [f32; 3])

Turns what is drawn next by degrees about axis (counterclockwise seen from the axis’ positive end, as Axis.rotationDegrees) through pivot, in blocks from the pose’s origin: [0.5; 3] is the block’s centre.

fn scale(&mut self, by: [f32; 3])

Scales what is drawn next by by about the pose’s origin.

fn keep(&mut self)

Keeps what this call drew, with neither native_block_entity_submit nor native_block_entity_render_bounding_box called until its state, block entity, light or resource packs change. Parts marked with spin keep turning from the game time; other geometry stays as submitted. Do not bake frame-dependent values into kept vertices: item glint and time-dependent item models stop where they were, and neighboring blocks do not invalidate the cache.

fn partial(&self) -> f32

The frame’s partial tick, 0 to 1 (BlockEntityRenderState).

fn game_time(&self) -> i64

The level’s game time, for animations.

fn light(&self) -> u32

The light the helpers draw with: the block’s own (LevelRenderer.getLightCoords), 16 times sky light in bits 0..8 and 16 times block light in bits 8..16.

fn set_light(&mut self, light: u32)

Lights what is drawn next with light (as native_draw_light reads it).

fn quad( &mut self, sprite: &str, corners: [[f32; 3]; 4], uv: [f32; 4], tint: u32, ) -> bool

Draws a quad with corners in blocks under draw’s pose, in a model face’s order (top left, bottom left, bottom right, top right as seen from its front), textured with the uv rectangle (u0, v0, u1, v1 in texels of 16 per side) of sprite (mymod:entity/screen, mymod:block/casing, block/stone) times the 0xRRGGBB tint (0xFFFFFF for none). False for an unknown sprite.

fn cube( &mut self, from: [f32; 3], to: [f32; 3], faces: [Option<CubeFace<'_>>; 6], tint: u32, ) -> bool

Draws a box from from to to (texels of 16 per block, as a block model’s element) under draw’s pose, with the faces given, by Direction (down, up, north, south, west, east), baked as a model element’s are (FaceBakery), times the 0xRRGGBB tint. A turned box is drawn under a turned pose (BlockEntityDraw::rotate_about). False when a face’s sprite is unknown; that face is left out.

fn block(&mut self, block: BlockKey, properties: &[(&str, &str)]) -> bool

Draws block block’s model (mymod:cog, any block with a model) in the state with properties ([("axis", "x")], the rest default) under draw’s pose, as vanilla’s submitBlockModel draws a block in an entity’s place: a block’s baked model, with its default tints. A moving part that is no block is a standalone model (native_draw_model). False for an unknown block or property.

fn item( &mut self, stack: &ItemStack, display: ItemDisplayContext, owner_yaw: Option<f32>, seed: i32, ) -> bool

Draws stack under draw’s pose as an item is drawn in the world (ItemModelResolver.updateForTopItem and ItemStackRenderState.submit), centred on the pose’s origin, in its model’s display transform: Fixed as a campfire’s or an item frame’s, Ground as a dropped item’s. seed picks among random models (a campfire passes its slot plus its position’s hash). owner_yaw makes the block entity the item’s owner (ItemOwner), at the block’s centre and turned that many degrees (getVisualRotationYInDegrees), as a shelf is: a compass on it points to its target from there. None draws it with no owner, as a campfire does. False for an empty stack or one with no model. The client’s copy of a block entity has no item slots (entity.items is empty there): send the stacks you draw in native_block_entity_update_tag and read them from entity.nbt.

fn spin( &mut self, axis: [f32; 3], pivot: [f32; 3], degrees_per_tick: f32, phase: f32, )

Begin time-based rotation using the surface’s one implementation.

fn still(&mut self)

End time-based rotation for subsequent geometry.

fn model(&mut self, model: ModelRef, tint: u32) -> Result<(), ModelError>

Draws the resolved standalone model under draw’s pose: unturned, from the block’s lower north-west corner, lit by draw.light. Faces with a tint index are multiplied by tint (0xAARRGGBB, the same as crate::WorldQuad::color; 0xFFFFFFFF for none), alpha included. Faces with no tint index stay opaque. A stale generation or absent slot returns an error without appending geometry.

fn terrain_model( &mut self, model: ModelRef, options: TerrainModelOptions<'_>, ) -> Result<(), TerrainModelError>

Draws the resolved standalone model under draw’s pose, as Self::model places it, with the terrain’s own materials: the block sprites (animated, mipmapped as the options set), back faces culled, colour and depth written as opaque terrain, lit by draw.light raised by each quad’s own emission. options picks the material (each quad’s solid, cutout or cutout_mipped, or one for all: cutout discards under alpha 0.1 without mipmaps, cutout-mipped under 0.5 with them), the directional shading (independent of light), one sprite drawn as another with moved UVs, a UV shrink, and a 0xRRGGBB tint on quads with a tint index. What a machine’s belts, shafts and casings draw with. A refusal draws nothing.

fn text( &mut self, text: &Text, at: [f32; 2], color: u32, glowing: bool, outline: u32, ) -> Result<f32, TextFormError>

Draws text under draw’s pose as a sign draws its lines (Font.drawInBatch in a BlockEntityRenderer): in the pose’s x-y plane, one unit a font pixel, y down, its left end at at, facing +z. Scale the pose first as a sign does (draw.scale([1.0 / 64.0, -1.0 / 64.0, 1.0 / 64.0]) for its letters, 8 pixels high). Each span is drawn in its own colour, the others in the 0xRRGGBB color; glowing text is full bright (a glow ink sac’s), the rest lit by draw.light; a nonzero 0xRRGGBB outline rings each glyph, as glowing sign text’s. Returns the width drawn, in font pixels: centre a line by starting it at minus half its width. API @API:draw_text@. Refuses text deeper than 512 component nodes before applying any changes.

fn text_width(&self, text: &str) -> f32

The width of text in font pixels, as draw_text draws it, to centre a line (Font.width).

fn model_part(&mut self, part: &ModelPart, sprite: &str, tint: u32) -> bool

Draws model part part and the parts under it under draw’s pose, as vanilla’s ModelPart.render does: each part moved to its place (in texels, 16 to a block), turned about z, then y, then x, and scaled, its faces textured from sprite (mymod:entity/golem, a content mod’s assets/mymod/textures/entity/golem.png, or vanilla’s entity/zombie/zombie) times the 0xRRGGBB tint. A part that isn’t visible draws nothing, one that skips drawing (skip_draw) only its children. A mob’s model is built in the model’s own frame (+y down, its front towards -z, its feet 24 texels down): in native_mob_submit, draw.scale([1.0, -1.0, -1.0]) then draw.translate([0.0, -1.501, 0.0]) first, as LivingEntityRenderer does. False for an unknown sprite. API @API:model_layers@.

fn fluid_box( &mut self, stack: &FluidStack, bounds: [f32; 6], options: FluidBoxOptions, ) -> Result<(), FluidBoxError>

Draws stack as a still fluid filling bounds ([x0, y0, z0, x1, y1, z1] in blocks under draw’s pose), as a tank’s contents: minecraft:water or minecraft:lava with no components. Each face tiles the fluid’s animated still sprite (block/water_still), one tile per block, cut at whole-block lines and keeping each part’s place in its tile, with no inset of the box. The tint is the stack’s, not the biome’s water colour, unless options.argb replaces it. Sky light stays as draw.light; block light rises to the fluid’s own (15 for lava). No face is shaded by direction. Faces are sorted far to near, alpha blended, culled from behind and write depth, drawn with the block entities before the level’s translucent terrain. A stack of 0 draws nothing and is Ok without checking bounds; a refusal draws nothing.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§