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>§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: u16The next state ID to be allocated
Implementations§
Source§impl BlockRegistry
impl BlockRegistry
pub fn new() -> Self
pub fn register(&mut self, block: BlockRef) -> usize
fn try_block_index(&self, block: BlockRef) -> Option<usize>
fn block_index(&self, block: BlockRef) -> usize
pub fn get_base_state_id(&self, block: BlockRef) -> BlockStateId
Sourcepub fn get_default_state_id(&self, block: BlockRef) -> BlockStateId
pub fn get_default_state_id(&self, block: BlockRef) -> BlockStateId
Gets the default state ID for a block (base state + default offset)
pub fn by_state_id(&self, state_id: BlockStateId) -> Option<BlockRef>
pub fn get_ticking_metadata( &self, state_id: BlockStateId, ) -> Option<BlockStateTickingMetadata>
pub fn get_properties( &self, id: BlockStateId, ) -> Vec<(&'static str, &'static str)>
Sourcepub fn state_id_from_properties(
&self,
key: &Identifier,
properties: &[(&str, &str)],
) -> Option<BlockStateId>
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).
Sourcepub fn state_id_from_block_properties(
&self,
block: BlockRef,
properties: &[(&str, &str)],
) -> Option<BlockStateId>
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.
Sourcepub fn state_id_from_block_defaulted_properties<'a>(
&self,
block: BlockRef,
properties: impl IntoIterator<Item = (&'a str, &'a str)>,
) -> Option<BlockStateId>
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.
Sourcepub fn try_set_property_by_name(
&self,
id: BlockStateId,
name: &str,
value: &str,
) -> Option<BlockStateId>
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.
Sourcepub fn matching_states(
&self,
block: BlockRef,
filter: &[(&str, &str)],
) -> Vec<BlockStateId>
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).
fn decode_property_indices(block: BlockRef, offset: u16) -> Vec<usize>
fn apply_property_overrides<'a>( block: BlockRef, property_indices: &mut [usize], properties: impl IntoIterator<Item = (&'a str, &'a str)>, ) -> Option<()>
fn encode_property_indices(block: BlockRef, property_indices: &[usize]) -> u16
fn property_stride(block: BlockRef, property_index: usize) -> u16
pub fn get_property<P: Property>( &self, id: BlockStateId, property: &P, ) -> P::Value
Sourcepub fn try_get_property<P: Property>(
&self,
id: BlockStateId,
property: &P,
) -> Option<P::Value>
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.
pub fn set_property<P: Property>( &self, id: BlockStateId, property: &P, value: P::Value, ) -> BlockStateId
pub fn iter(&self) -> impl Iterator<Item = (usize, BlockRef)> + '_
Source§impl BlockRegistry
impl BlockRegistry
fn block_and_state_offset( &self, state_id: BlockStateId, ) -> Option<(BlockRef, u16)>
fn static_shape_for_state( &self, state_id: BlockStateId, shape: fn(&Block, u16) -> VoxelShape, ) -> VoxelShape
fn offset_shape_for_state( &self, state_id: BlockStateId, pos: BlockPos, channel: ShapeChannel, shape: fn(&Block, u16) -> VoxelShape, ) -> OffsetVoxelShape
Sourcepub fn get_static_collision_shape(&self, state_id: BlockStateId) -> VoxelShape
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.
Sourcepub fn is_suffocating(&self, state_id: BlockStateId) -> bool
pub fn is_suffocating(&self, state_id: BlockStateId) -> bool
Returns vanilla BlockState.isSuffocating.
Sourcepub fn is_static_redstone_conductor(&self, state_id: BlockStateId) -> bool
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.
pub fn get_collision_shape_at( &self, state_id: BlockStateId, pos: BlockPos, ) -> OffsetVoxelShape
Sourcepub fn get_static_support_shape(&self, state_id: BlockStateId) -> VoxelShape
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.
pub fn get_support_shape_at( &self, state_id: BlockStateId, pos: BlockPos, ) -> OffsetVoxelShape
Sourcepub fn get_static_outline_shape(&self, state_id: BlockStateId) -> VoxelShape
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).
pub fn get_outline_shape_at( &self, state_id: BlockStateId, pos: BlockPos, ) -> OffsetVoxelShape
Sourcepub fn get_occlusion_shape(&self, state_id: BlockStateId) -> VoxelShape
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.
Sourcepub fn get_static_interaction_shape(&self, state_id: BlockStateId) -> VoxelShape
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.
pub fn get_interaction_shape_at( &self, state_id: BlockStateId, pos: BlockPos, ) -> OffsetVoxelShape
Sourcepub fn get_static_visual_shape(&self, state_id: BlockStateId) -> VoxelShape
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.
pub fn get_visual_shape_at( &self, state_id: BlockStateId, pos: BlockPos, ) -> OffsetVoxelShape
Sourcepub fn get_static_shapes(&self, state_id: BlockStateId) -> BlockShapes
pub fn get_static_shapes(&self, state_id: BlockStateId) -> BlockShapes
Gets all static shape channels for a block state.
pub fn get_light_properties( &self, state_id: BlockStateId, ) -> BlockLightProperties
pub fn copy_matching_properties( &self, source: BlockStateId, target: BlockRef, ) -> BlockStateId
Trait Implementations§
Source§impl Default for BlockRegistry
impl Default for BlockRegistry
Source§impl DowncastType for BlockRegistry
impl DowncastType for BlockRegistry
Source§const TYPE_KEY: DowncastTypeKey
const TYPE_KEY: DowncastTypeKey
Source§impl RegistryExt for BlockRegistry
impl RegistryExt for BlockRegistry
type Entry = Block
fn freeze(&mut self)
fn by_id(&self, id: usize) -> Option<&'static Block>
fn by_key(&self, key: &Identifier) -> Option<&'static Block>
fn id_from_key(&self, key: &Identifier) -> Option<usize>
fn len(&self) -> usize
fn is_empty(&self) -> bool
Source§impl TaggedRegistryExt for BlockRegistry
impl TaggedRegistryExt for BlockRegistry
fn register_tag(&mut self, tag: Identifier, keys: &[&'static str])
fn modify_tag( &mut self, tag: &Identifier, f: impl FnOnce(Vec<Identifier>) -> Vec<Identifier>, )
fn is_in_tag(&self, entry: &Self::Entry, tag: &Identifier) -> bool
fn get_tag(&self, tag: &Identifier) -> Option<Vec<&'static Self::Entry>>
fn iter_tag( &self, tag: &Identifier, ) -> impl Iterator<Item = &'static Self::Entry> + '_
fn tag_keys(&self) -> impl Iterator<Item = &Identifier> + '_
Auto Trait Implementations§
impl !RefUnwindSafe for BlockRegistry
impl !UnwindSafe for BlockRegistry
impl Freeze for BlockRegistry
impl Send for BlockRegistry
impl Sync for BlockRegistry
impl Unpin for BlockRegistry
impl UnsafeUnpin for BlockRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Downcast for Twhere
T: ErasedType + ?Sized,
impl<T> Downcast for Twhere
T: ErasedType + ?Sized,
Source§fn is<T>(&self) -> boolwhere
T: DowncastType,
fn is<T>(&self) -> boolwhere
T: DowncastType,
T.Source§fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastType,
fn downcast_ref<T>(&self) -> Option<&T>where
T: DowncastType,
T when its key matches.Source§fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: DowncastType,
fn downcast_mut<T>(&mut self) -> Option<&mut T>where
T: DowncastType,
T when its key matches.Source§impl<T> ErasedType for Twhere
T: DowncastType,
impl<T> ErasedType for Twhere
T: DowncastType,
fn downcast_type_key(&self) -> DowncastTypeKey
fn downcast_data(&self) -> *const ()
fn downcast_data_mut(&mut self) -> *mut ()
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
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 moreArc<SyncMutex<>>