Skip to main content

Block

Struct Block 

Source
pub struct Block {
    pub key: Identifier,
    pub config: BlockConfig,
    pub properties: &'static [&'static dyn DynProperty],
    pub default_state_offset: u16,
    pub collision_shape: ShapeFn,
    pub support_shape: ShapeFn,
    pub outline_shape: ShapeFn,
    pub occlusion_shape: ShapeFn,
    pub interaction_shape: ShapeFn,
    pub visual_shape: ShapeFn,
    pub id: OnceLock<usize>,
}

Fields§

§key: Identifier§config: BlockConfig§properties: &'static [&'static dyn DynProperty]§default_state_offset: u16§collision_shape: ShapeFn

Function to get collision shape for a state offset

§support_shape: ShapeFn

Function to get block support shape for a state offset

§outline_shape: ShapeFn

Function to get outline shape for a state offset

§occlusion_shape: ShapeFn

Function to get occlusion shape for a state offset

§interaction_shape: ShapeFn

Function to get interaction shape for a state offset

§visual_shape: ShapeFn

Function to get visual shape for a state offset

§id: OnceLock<usize>

Cached registry ID, set during registration for O(1) lookup on hot paths.

Implementations§

Source§

impl Block

Source

pub const fn new( key: Identifier, config: BlockConfig, properties: &'static [&'static dyn DynProperty], ) -> Self

Source

pub const fn with_shapes( self, collision: ShapeFn, support: ShapeFn, outline: ShapeFn, occlusion: ShapeFn, interaction: ShapeFn, visual: ShapeFn, ) -> Self

Sets the shape functions for this block.

Source

pub fn get_collision_shape(&self, offset: u16) -> VoxelShape

Gets the collision shape for a given state offset.

Source

pub fn get_support_shape(&self, offset: u16) -> VoxelShape

Gets the block support shape for a given state offset.

Source

pub fn get_outline_shape(&self, offset: u16) -> VoxelShape

Gets the outline shape for a given state offset.

Source

pub fn get_occlusion_shape(&self, offset: u16) -> VoxelShape

Gets the occlusion shape for a given state offset.

Source

pub fn get_interaction_shape(&self, offset: u16) -> VoxelShape

Gets the interaction shape for a given state offset.

Source

pub fn get_visual_shape(&self, offset: u16) -> VoxelShape

Gets the visual shape for a given state offset.

Source

pub(crate) const fn with_default_state(self, offset: u16) -> Self

Sets the default state offset for this block. The offset is relative to the block’s base state ID.

For easier usage, consider using with_default_state_from_indices or the default_state! macro instead of calculating the offset manually.

§Example
const REPEATER: Block = Block::new("repeater", props, &[...])
    .with_default_state(4);
Source

pub const fn calculate_offset( property_indices: &[usize], property_counts: &[usize], ) -> u16

Const helper to calculate state offset from property indices and counts. Properties are processed in reverse order to match Minecraft’s encoding (last property = inner loop with multiplier 1).

Source

pub fn default_state(&'static self) -> BlockStateId

Source

pub fn has_tag(&'static self, tag: &Identifier) -> bool

Returns true if this block is tagged with the given tag.

Trait Implementations§

Source§

impl Debug for Block

Source§

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

Formats the value using the given formatter. Read more
Source§

impl RegistryEntry for Block

Source§

fn key(&self) -> &Identifier

Source§

fn try_id(&self) -> Option<usize>

Source§

fn id(&self) -> usize

Panics Read more

Auto Trait Implementations§

§

impl !Freeze for Block

§

impl !RefUnwindSafe for Block

§

impl !UnwindSafe for Block

§

impl Send for Block

§

impl Sync for Block

§

impl Unpin for Block

§

impl UnsafeUnpin for Block

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> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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.

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

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more