Struct veloren_common::terrain::block::Block
source · pub struct Block {
kind: BlockKind,
data: [u8; 3],
}
Expand description
§Format
BBBBBBBB CCCCCCCC AAAAAIII IIIIIIII
0..8
: BlockKind8..16
: Category16..N
: Attributes (many fields)N..32
: Sprite ID
N
is per-category. You can match on the category byte to find the length
of the ID field.
Attributes are also per-category. Each category specifies its own list of attribute fields.
Why is the sprite ID at the end? Simply put, it makes masking faster and
easier, which is important because extracting the SpriteKind
is a more
commonly performed operation than extracting attributes.
Fields§
§kind: BlockKind
§data: [u8; 3]
Implementations§
source§impl Block
impl Block
pub const MAX_HEIGHT: f32 = 3f32
pub const fn from_raw(kind: BlockKind, data: [u8; 3]) -> Self
pub const fn new(kind: BlockKind, color: Rgb<u8>) -> Self
pub fn unfilled(kind: BlockKind, sprite: SpriteKind) -> Self
pub fn air(sprite: SpriteKind) -> Self
pub const fn empty() -> Self
pub fn water(sprite: SpriteKind) -> Self
pub const fn get_sprite(&self) -> Option<SpriteKind>
pub(super) const fn sprite_category_byte(&self) -> u8
pub const fn sprite_category(&self) -> Option<Category>
sourcepub fn with_attr<A: Attribute>(
self,
attr: A,
) -> Result<Self, AttributeError<Infallible>>
pub fn with_attr<A: Attribute>( self, attr: A, ) -> Result<Self, AttributeError<Infallible>>
Build this block with the given sprite attribute set.
sourcepub fn set_attr<A: Attribute>(
&mut self,
attr: A,
) -> Result<(), AttributeError<Infallible>>
pub fn set_attr<A: Attribute>( &mut self, attr: A, ) -> Result<(), AttributeError<Infallible>>
Set the given attribute of this block’s sprite.
sourcepub fn get_attr<A: Attribute>(&self) -> Result<A, AttributeError<A::Error>>
pub fn get_attr<A: Attribute>(&self) -> Result<A, AttributeError<A::Error>>
Get the given attribute of this block’s sprite.
pub(super) const fn data(&self) -> [u8; 3]
pub(super) const fn with_data(self, data: [u8; 3]) -> Self
pub(super) const fn to_be_u32(self) -> u32
pub fn get_color(&self) -> Option<Rgb<u8>>
pub fn get_ori(&self) -> Option<u8>
sourcepub fn get_rtsim_resource(&self) -> Option<ChunkResource>
pub fn get_rtsim_resource(&self) -> Option<ChunkResource>
Returns the rtsim resource, if any, that this block corresponds to. If you want the scarcity of a block to change with rtsim’s resource depletion tracking, you can do so by editing this function.
pub fn get_glow(&self) -> Option<u8>
pub fn get_max_sunlight(&self) -> (u8, f32)
pub fn is_solid(&self) -> bool
pub fn valid_collision_dir( &self, entity_aabb: Aabb<f32>, block_aabb: Aabb<f32>, move_dir: Vec3<f32>, ) -> bool
sourcepub fn explode_power(&self) -> Option<f32>
pub fn explode_power(&self) -> Option<f32>
Can this block be exploded? If so, what ‘power’ is required to do so? Note that we don’t really define what ‘power’ is. Consider the units arbitrary and only important when compared to one-another.
pub fn collectible_id(&self) -> Option<Option<LootSpec<&'static str>>>
pub fn is_collectible(&self) -> bool
pub fn is_mountable(&self) -> bool
sourcepub fn mount_offset(&self) -> Option<(Vec3<f32>, Vec3<f32>)>
pub fn mount_offset(&self) -> Option<(Vec3<f32>, Vec3<f32>)>
Get the position and direction to mount this block if any.
pub fn is_controller(&self) -> bool
pub fn is_bonkable(&self) -> bool
pub fn is_owned(&self) -> bool
sourcepub fn mine_tool(&self) -> Option<ToolKind>
pub fn mine_tool(&self) -> Option<ToolKind>
The tool required to mine this block. For blocks that cannot be mined,
None
is returned.
pub fn is_opaque(&self) -> bool
pub fn solid_height(&self) -> f32
sourcepub fn get_friction(&self) -> f32
pub fn get_friction(&self) -> f32
Get the friction constant used to calculate surface friction when walking/climbing. Currently has no units.
sourcepub fn get_traction(&self) -> f32
pub fn get_traction(&self) -> f32
Get the traction permitted by this block as a proportion of the friction applied.
1.0 = default, 0.0 = completely inhibits movement, > 1.0 = potential for infinite acceleration (in a vacuum).
sourcepub fn with_toggle_light(self, enable: bool) -> Option<Self>
pub fn with_toggle_light(self, enable: bool) -> Option<Self>
Apply a light toggle to this block, if possible
pub fn kind(&self) -> BlockKind
sourcepub fn with_data_of(self, other: Block) -> Self
pub fn with_data_of(self, other: Block) -> Self
If possible, copy the sprite/color data of the other block.
sourcepub fn with_sprite(self, sprite: SpriteKind) -> Self
pub fn with_sprite(self, sprite: SpriteKind) -> Self
If this block is a fluid, replace its sprite.
sourcepub fn with_ori(self, ori: u8) -> Option<Self>
pub fn with_ori(self, ori: u8) -> Option<Self>
If this block can have orientation, give it a new orientation.
sourcepub fn with_adjacent_type(self, adj: RelativeNeighborPosition) -> Option<Self>
pub fn with_adjacent_type(self, adj: RelativeNeighborPosition) -> Option<Self>
If this block can have adjacent sprites, give it its AdjacentType
sourcepub fn into_vacant(self) -> Self
pub fn into_vacant(self) -> Self
Remove the terrain sprite or solid aspects of a block
pub fn to_u32(self) -> u32
Methods from Deref<Target = BlockKind>§
pub fn elim<'a, Elim, Context, S, Type>( &'a self, elim: Elim, context: Context, ) -> (Type, S)
pub fn elim_case_pure<'a, Type>(&self, cases: &'a PureCases<Type>) -> &'a Type
pub fn elim_case_weak<'a, 'b, Type>( &'a self, cases: &'b ElimWeak<Self, Type>, ) -> &'b Type
pub fn is_air(&self) -> bool
sourcepub fn is_fluid(&self) -> bool
pub fn is_fluid(&self) -> bool
Determine whether the block kind is a gas or a liquid. This does not consider any sprites that may occupy the block (the definition of fluid is ‘a substance that deforms to fit containers’)
pub fn is_liquid(&self) -> bool
pub fn liquid_kind(&self) -> Option<LiquidKind>
sourcepub fn is_filled(&self) -> bool
pub fn is_filled(&self) -> bool
Determine whether the block is filled (i.e: fully solid). Right now, this is the opposite of being a fluid.
sourcepub fn has_color(&self) -> bool
pub fn has_color(&self) -> bool
Determine whether the block has an RGB color stored in the attribute fields.
sourcepub fn is_terrain(&self) -> bool
pub fn is_terrain(&self) -> bool
Determine whether the block is ‘terrain-like’. This definition is arbitrary, but includes things like rocks, soils, sands, grass, and other blocks that might be expected to the landscape. Plant matter and snow are not included.
Trait Implementations§
source§impl<'de> Deserialize<'de> for Block
impl<'de> Deserialize<'de> for Block
source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
source§impl PartialEq for Block
impl PartialEq for Block
impl Copy for Block
impl Eq for Block
impl StructuralPartialEq for Block
Auto Trait Implementations§
impl Freeze for Block
impl RefUnwindSafe for Block
impl Send for Block
impl Sync for Block
impl Unpin for Block
impl UnwindSafe for Block
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)source§impl<T> CloneToUninit for Twhere
T: Copy,
impl<T> CloneToUninit for Twhere
T: Copy,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)§impl<C, M> ConvertSaveload<M> for C
impl<C, M> ConvertSaveload<M> for C
§type Error = Infallible
type Error = Infallible
§fn convert_into<F>(
&self,
_: F,
) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
fn convert_into<F>( &self, _: F, ) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
Data
) using
entity to marker mapping function§fn convert_from<F>(
data: <C as ConvertSaveload<M>>::Data,
_: F,
) -> Result<C, <C as ConvertSaveload<M>>::Error>
fn convert_from<F>( data: <C as ConvertSaveload<M>>::Data, _: F, ) -> Result<C, <C as ConvertSaveload<M>>::Error>
Data
) using
entity to marker mapping function§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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 more