Struct veloren_common::terrain::block::Block

source ·
pub struct Block {
    kind: BlockKind,
    data: [u8; 3],
}
Expand description

§Format

BBBBBBBB CCCCCCCC AAAAAIII IIIIIIII
  • 0..8 : BlockKind
  • 8..16 : Category
  • 16..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

source

pub const MAX_HEIGHT: f32 = 3f32

source

pub const fn from_raw(kind: BlockKind, data: [u8; 3]) -> Self

source

pub const fn new(kind: BlockKind, color: Rgb<u8>) -> Self

source

pub fn unfilled(kind: BlockKind, sprite: SpriteKind) -> Self

source

pub fn air(sprite: SpriteKind) -> Self

source

pub const fn empty() -> Self

source

pub fn water(sprite: SpriteKind) -> Self

source

pub const fn get_sprite(&self) -> Option<SpriteKind>

source

pub(super) const fn sprite_category_byte(&self) -> u8

source

pub const fn sprite_category(&self) -> Option<Category>

source

pub fn with_attr<A: Attribute>( self, attr: A, ) -> Result<Self, AttributeError<Infallible>>

Build this block with the given sprite attribute set.

source

pub fn set_attr<A: Attribute>( &mut self, attr: A, ) -> Result<(), AttributeError<Infallible>>

Set the given attribute of this block’s sprite.

source

pub fn get_attr<A: Attribute>(&self) -> Result<A, AttributeError<A::Error>>

Get the given attribute of this block’s sprite.

source

pub(super) const fn data(&self) -> [u8; 3]

source

pub(super) const fn with_data(self, data: [u8; 3]) -> Self

source

pub(super) const fn to_be_u32(self) -> u32

source

pub fn get_color(&self) -> Option<Rgb<u8>>

source

pub fn get_ori(&self) -> Option<u8>

source

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.

source

pub fn get_glow(&self) -> Option<u8>

source

pub fn get_max_sunlight(&self) -> (u8, f32)

source

pub fn is_solid(&self) -> bool

source

pub fn valid_collision_dir( &self, entity_aabb: Aabb<f32>, block_aabb: Aabb<f32>, move_dir: Vec3<f32>, ) -> bool

source

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.

source

pub fn collectible_id(&self) -> Option<Option<LootSpec<&'static str>>>

source

pub fn is_collectible(&self) -> bool

source

pub fn is_mountable(&self) -> bool

source

pub fn mount_offset(&self) -> Option<(Vec3<f32>, Vec3<f32>)>

Get the position and direction to mount this block if any.

source

pub fn is_controller(&self) -> bool

source

pub fn is_bonkable(&self) -> bool

source

pub fn is_owned(&self) -> bool

source

pub fn mine_tool(&self) -> Option<ToolKind>

The tool required to mine this block. For blocks that cannot be mined, None is returned.

source

pub fn is_opaque(&self) -> bool

source

pub fn solid_height(&self) -> f32

source

pub fn get_friction(&self) -> f32

Get the friction constant used to calculate surface friction when walking/climbing. Currently has no units.

source

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

source

pub fn with_toggle_light(self, enable: bool) -> Option<Self>

Apply a light toggle to this block, if possible

source

pub fn kind(&self) -> BlockKind

source

pub fn with_data_of(self, other: Block) -> Self

If possible, copy the sprite/color data of the other block.

source

pub fn with_sprite(self, sprite: SpriteKind) -> Self

If this block is a fluid, replace its sprite.

source

pub fn with_ori(self, ori: u8) -> Option<Self>

If this block can have orientation, give it a new orientation.

source

pub fn with_adjacent_type(self, adj: RelativeNeighborPosition) -> Option<Self>

If this block can have adjacent sprites, give it its AdjacentType

source

pub fn into_vacant(self) -> Self

Remove the terrain sprite or solid aspects of a block

source

pub fn from_u32(x: u32) -> Option<Self>

Attempt to convert a u32 to a block

source

pub fn to_u32(self) -> u32

Methods from Deref<Target = BlockKind>§

source

pub fn elim<'a, Elim, Context, S, Type>( &'a self, elim: Elim, context: Context, ) -> (Type, S)
where Elim: Typed<((&'a BlockKind,), Context), Type, S>,

source

pub fn elim_case_pure<'a, Type>(&self, cases: &'a PureCases<Type>) -> &'a Type

source

pub fn elim_case_weak<'a, 'b, Type>( &'a self, cases: &'b ElimWeak<Self, Type>, ) -> &'b Type
where WeakHead<Pure<Type>, Type>: SynthTyped<(), Type>, &'b ElimWeak<Self, Type>: Typed<((&'a BlockKind,), ()), &'b Type, ()>,

source

pub fn is_air(&self) -> bool

source

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

source

pub fn is_liquid(&self) -> bool

source

pub fn liquid_kind(&self) -> Option<LiquidKind>

source

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.

source

pub fn has_color(&self) -> bool

Determine whether the block has an RGB color stored in the attribute fields.

source

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 Clone for Block

source§

fn clone(&self) -> Block

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Block

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<'de> Deserialize<'de> for Block

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl FilledVox for Block

source§

fn default_non_filled() -> Self

source§

fn is_filled(&self) -> bool

source§

fn or(self, other: Self) -> Self

source§

impl Hash for Block

source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
source§

impl PartialEq for Block

source§

fn eq(&self, other: &Block) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Serialize for Block

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
source§

impl Deref for Block

§

type Target = BlockKind

The resulting type after dereferencing.
source§

fn deref(&self) -> &Self::Target

Dereferences the value.
source§

impl Copy for Block

source§

impl Eq for Block

source§

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

impl<T> CallHasher for T
where T: Hash,

§

fn get_hash<H>(&self, hasher: H) -> u64
where H: Hasher,

source§

impl<T> CloneToUninit for T
where T: Clone,

source§

default unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> CloneToUninit for T
where T: Copy,

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
§

impl<C, M> ConvertSaveload<M> for C

§

type Data = C

(De)Serializable data representation for data type
§

type Error = Infallible

Error may occur during serialization or deserialization of component
§

fn convert_into<F>( &self, _: F, ) -> Result<<C as ConvertSaveload<M>>::Data, <C as ConvertSaveload<M>>::Error>
where F: FnMut(Entity) -> Option<M>,

Convert this data type into serializable form (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>
where F: FnMut(M) -> Option<Entity>,

Convert this data from a deserializable form (Data) using entity to marker mapping function
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
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
§

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

§

type Output = T

Should always be Self
source§

impl<Context> SubContext<Context> for Context

source§

fn sub_context(self) -> Context

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

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

§

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<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

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

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

§

impl<T> Event for T
where T: Send + Sync + 'static,

§

impl<T> Resource for T
where T: Any + Send + Sync,

§

impl<T> Storable for T
where T: Send + Sync + 'static,