Skip to main content

BlockRegistry

Struct BlockRegistry 

Source
pub struct BlockRegistry {
    blocks_by_id: Vec<BlockRef>,
    blocks_by_key: FxHashMap<Identifier, usize>,
    tags: FxHashMap<Identifier, Vec<Identifier>>,
    allows_registering: bool,
    pub state_to_block_lookup: Vec<BlockRef>,
    pub state_to_block_id: Vec<usize>,
    pub block_to_base_state: Vec<u16>,
    pub next_state_id: u16,
}

Fields§

§blocks_by_id: Vec<BlockRef>§blocks_by_key: FxHashMap<Identifier, usize>§tags: FxHashMap<Identifier, Vec<Identifier>>§allows_registering: bool§state_to_block_lookup: Vec<BlockRef>§state_to_block_id: Vec<usize>

Maps state IDs to block IDs (parallel to state_to_block_lookup for O(1) lookup)

§block_to_base_state: Vec<u16>

Maps block IDs to their base state ID

§next_state_id: u16

The next state ID to be allocated

Implementations§

Source§

impl BlockRegistry

Source

pub fn new() -> Self

Source

pub fn register(&mut self, block: BlockRef) -> usize

Source

fn try_block_index(&self, block: BlockRef) -> Option<usize>

Source

fn block_index(&self, block: BlockRef) -> usize

Source

pub fn get_base_state_id(&self, block: BlockRef) -> BlockStateId

Source

pub fn get_default_state_id(&self, block: BlockRef) -> BlockStateId

Gets the default state ID for a block (base state + default offset)

Source

pub fn by_state_id(&self, state_id: BlockStateId) -> Option<BlockRef>

Source

pub fn get_properties( &self, id: BlockStateId, ) -> Vec<(&'static str, &'static str)>

Source

pub fn state_id_from_properties( &self, key: &Identifier, properties: &[(&str, &str)], ) -> Option<BlockStateId>

Gets the state ID for a block with the given properties.

Returns None if the block key is unknown or if any property name/value is invalid.

Properties can be provided in any order. Missing properties will use the block’s default values (typically index 0 for each property).

Source

pub fn state_id_from_block_properties( &self, block: BlockRef, properties: &[(&str, &str)], ) -> Option<BlockStateId>

Gets the state ID for a block with the given properties.

Returns None if the block is not registered or if any property name/value is invalid.

Source

pub fn state_id_from_block_defaulted_properties<'a>( &self, block: BlockRef, properties: impl IntoIterator<Item = (&'a str, &'a str)>, ) -> Option<BlockStateId>

Gets the state ID for a block by applying properties over that block’s registered default state.

Returns None if the block is not registered or if any property name/value is invalid.

Source

fn decode_property_indices(block: BlockRef, offset: u16) -> Vec<usize>

Source

fn apply_property_overrides<'a>( block: BlockRef, property_indices: &mut [usize], properties: impl IntoIterator<Item = (&'a str, &'a str)>, ) -> Option<()>

Source

fn encode_property_indices(block: BlockRef, property_indices: &[usize]) -> u16

Source

pub fn get_property<T, P: Property<T>>( &self, id: BlockStateId, property: &P, ) -> T

Source

pub fn try_get_property<T, P: Property<T>>( &self, id: BlockStateId, property: &P, ) -> Option<T>

Gets the value of a property, returning None if the block doesn’t have this property.

Source

pub fn set_property<T, P: Property<T>>( &self, id: BlockStateId, property: &P, value: T, ) -> BlockStateId

Source

pub fn iter(&self) -> impl Iterator<Item = (usize, BlockRef)> + '_

Source§

impl BlockRegistry

Source

fn shape_for_state( &self, state_id: BlockStateId, shape: fn(&Block, u16) -> VoxelShape, ) -> VoxelShape

Source

pub fn get_collision_shape(&self, state_id: BlockStateId) -> VoxelShape

Gets the collision shape for a block state.

For simple blocks this is typically a single full-block box. For complex blocks like fences, this may be multiple boxes.

Source

pub fn get_support_shape(&self, state_id: BlockStateId) -> VoxelShape

Gets the block support shape for a block state.

Vanilla support checks use BlockState.getBlockSupportShape, not collision shape, for isFaceSturdy and multiface side attachment.

Source

pub fn get_outline_shape(&self, state_id: BlockStateId) -> VoxelShape

Gets the outline shape for a block state.

This is the shape shown when the player targets the block. Often the same as collision shape, but can differ (e.g., fences).

Source

pub fn get_occlusion_shape(&self, state_id: BlockStateId) -> VoxelShape

Gets the occlusion shape for a block state.

Vanilla caches this as BlockState.getOcclusionShape() and uses it for isSolidRender, light occlusion, and face occlusion.

Source

pub fn get_interaction_shape(&self, state_id: BlockStateId) -> VoxelShape

Gets the interaction shape for a block state.

Vanilla uses this as an interaction hit override after the primary raycast shape has already hit.

Source

pub fn get_visual_shape(&self, state_id: BlockStateId) -> VoxelShape

Gets the visual shape for a block state.

Vanilla uses this for visual raycasts; it defaults to collision shape but differs for a few blocks such as fences, mud, soul sand, and powder snow.

Source

pub fn get_shapes(&self, state_id: BlockStateId) -> BlockShapes

Gets all static shape channels for a block state.

Source

pub fn copy_matching_properties( &self, source: BlockStateId, target: BlockRef, ) -> BlockStateId

Trait Implementations§

Source§

impl Default for BlockRegistry

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl RegistryExt for BlockRegistry

Source§

type Entry = Block

Source§

fn freeze(&mut self)

Source§

fn by_id(&self, id: usize) -> Option<&'static Block>

Source§

fn by_key(&self, key: &Identifier) -> Option<&'static Block>

Source§

fn id_from_key(&self, key: &Identifier) -> Option<usize>

Source§

fn len(&self) -> usize

Source§

fn is_empty(&self) -> bool

Source§

impl TaggedRegistryExt for BlockRegistry

Source§

fn register_tag(&mut self, tag: Identifier, keys: &[&'static str])

Source§

fn modify_tag( &mut self, tag: &Identifier, f: impl FnOnce(Vec<Identifier>) -> Vec<Identifier>, )

Source§

fn is_in_tag(&self, entry: &Self::Entry, tag: &Identifier) -> bool

Source§

fn get_tag(&self, tag: &Identifier) -> Option<Vec<&'static Self::Entry>>

Source§

fn iter_tag( &self, tag: &Identifier, ) -> impl Iterator<Item = &'static Self::Entry> + '_

Source§

fn tag_keys(&self) -> impl Iterator<Item = &Identifier> + '_

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