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>§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: 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_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.
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
pub fn get_property<T, P: Property<T>>( &self, id: BlockStateId, property: &P, ) -> T
Sourcepub fn try_get_property<T, P: Property<T>>(
&self,
id: BlockStateId,
property: &P,
) -> Option<T>
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.
pub fn set_property<T, P: Property<T>>( &self, id: BlockStateId, property: &P, value: T, ) -> BlockStateId
pub fn iter(&self) -> impl Iterator<Item = (usize, BlockRef)> + '_
Source§impl BlockRegistry
impl BlockRegistry
fn shape_for_state( &self, state_id: BlockStateId, shape: fn(&Block, u16) -> VoxelShape, ) -> VoxelShape
Sourcepub fn get_collision_shape(&self, state_id: BlockStateId) -> VoxelShape
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.
Sourcepub fn get_support_shape(&self, state_id: BlockStateId) -> VoxelShape
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.
Sourcepub fn get_outline_shape(&self, state_id: BlockStateId) -> VoxelShape
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).
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_interaction_shape(&self, state_id: BlockStateId) -> VoxelShape
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.
Sourcepub fn get_visual_shape(&self, state_id: BlockStateId) -> VoxelShape
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.
Sourcepub fn get_shapes(&self, state_id: BlockStateId) -> BlockShapes
pub fn get_shapes(&self, state_id: BlockStateId) -> BlockShapes
Gets all static shape channels for a block state.