Skip to main content

BlockRegistry

Struct BlockRegistry 

Source
pub struct BlockRegistry {
    blocks_by_id: Vec<BlockRef>,
    blocks_by_key: FxHashMap<Identifier, usize>,
    tags: RegistryTags,
    allows_registering: bool,
    pub state_to_block_lookup: Vec<BlockRef>,
    pub state_to_block_id: Vec<usize>,
    state_ticking_metadata: Vec<BlockStateTickingMetadata>,
    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: RegistryTags§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)

§state_ticking_metadata: Vec<BlockStateTickingMetadata>

Behavior-independent metadata indexed directly by global block-state ID.

§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_ticking_metadata( &self, state_id: BlockStateId, ) -> Option<BlockStateTickingMetadata>

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

pub fn try_set_property_by_name( &self, id: BlockStateId, name: &str, value: &str, ) -> Option<BlockStateId>

Applies one dynamically named property value to an existing state.

Returns None when the state is invalid or the state’s block does not define the named property/value pair. This mirrors Vanilla’s StateHolder.trySetValue path used by parsed command block inputs.

Source

pub fn matching_states( &self, block: BlockRef, filter: &[(&str, &str)], ) -> Vec<BlockStateId>

Returns every state id of block whose properties match all (name, value) pairs in filter. An empty filter yields all states of the block (vanilla’s getStatesOfBlock); a non-empty filter keeps only matching states (vanilla’s BED_HEADS-style predicate).

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

fn property_stride(block: BlockRef, property_index: usize) -> u16

Source

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

Source

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

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

Source

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

Source

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

Source§

impl BlockRegistry

Source

fn block_and_state_offset( &self, state_id: BlockStateId, ) -> Option<(BlockRef, u16)>

Source

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

Source

fn offset_shape_for_state( &self, state_id: BlockStateId, pos: BlockPos, channel: ShapeChannel, shape: fn(&Block, u16) -> VoxelShape, ) -> OffsetVoxelShape

Source

pub fn get_static_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 is_suffocating(&self, state_id: BlockStateId) -> bool

Returns vanilla BlockState.isSuffocating.

Source

pub fn is_static_redstone_conductor(&self, state_id: BlockStateId) -> bool

Returns the extracted static BlockState.isRedstoneConductor value.

Dynamic block behaviors may override this value using the live level and position.

Source

pub fn get_collision_shape_at( &self, state_id: BlockStateId, pos: BlockPos, ) -> OffsetVoxelShape

Source

pub fn get_static_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_support_shape_at( &self, state_id: BlockStateId, pos: BlockPos, ) -> OffsetVoxelShape

Source

pub fn get_static_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_outline_shape_at( &self, state_id: BlockStateId, pos: BlockPos, ) -> OffsetVoxelShape

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_static_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_interaction_shape_at( &self, state_id: BlockStateId, pos: BlockPos, ) -> OffsetVoxelShape

Source

pub fn get_static_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_visual_shape_at( &self, state_id: BlockStateId, pos: BlockPos, ) -> OffsetVoxelShape

Source

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

Gets all static shape channels for a block state.

Source

pub fn get_light_properties( &self, state_id: BlockStateId, ) -> BlockLightProperties

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 DowncastType for BlockRegistry

Source§

const TYPE_KEY: DowncastTypeKey

The process-wide key for this concrete type.
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> Downcast for T
where T: ErasedType + ?Sized,

Source§

fn is<T>(&self) -> bool
where T: DowncastType,

Returns whether the erased value has concrete type T.
Source§

fn downcast_ref<T>(&self) -> Option<&T>
where T: DowncastType,

Returns the erased value as T when its key matches.
Source§

fn downcast_mut<T>(&mut self) -> Option<&mut T>
where T: DowncastType,

Returns the erased value as mutable T when its key matches.
Source§

impl<T> ErasedType for T
where T: DowncastType,

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> IntoShared for T

Source§

fn into_shared(self) -> Arc<Mutex<RawMutex, Self>>

Wraps this value in an Arc<SyncMutex<>>
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<R> StatValueRegistry for R

Source§

fn len(&self) -> usize

Source§

fn value_from_id( &self, id: usize, ) -> Option<&'static dyn StatValueRegistryEntry>

Source§

fn value_from_key( &self, key: &Identifier, ) -> Option<&'static dyn StatValueRegistryEntry>

Source§

fn key_from_id(&self, id: usize) -> Option<&'static Identifier>

Source§

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

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