Enum all_is_cubes::block::Block [−][src]
#[non_exhaustive]
pub enum Block {
Indirect(URef<BlockDef>),
Atom(BlockAttributes, Rgba),
Recur {
attributes: BlockAttributes,
offset: GridPoint,
resolution: u8,
space: URef<Space>,
},
Rotated(GridRotation, Box<Block>),
}
Expand description
A Block
is something that can exist in the grid of a Space
; it occupies one unit
cube of space and has a specified appearance and behavior.
In general, when a block appears multiple times from an in-game perspective, that may
or may not be the the same copy; Block
s are “by value”. However, some blocks are
defined by reference to shared mutable data, in which case changes to that data should
take effect everywhere a Block
having that same reference occurs.
To obtain the concrete appearance and behavior of a block, use Block::evaluate
to
obtain an EvaluatedBlock
value, preferably with caching.
Variants (Non-exhaustive)
This enum is marked as non-exhaustive
A block whose definition is stored in a Universe
.
Atom(BlockAttributes, Rgba)
A block that is a single-colored unit cube. (It may still be be transparent or non-solid to physics.)
Tuple Fields of Atom
0: BlockAttributes
1: Rgba
A block that is composed of smaller blocks, defined by the referenced Space
.
Fields of Recur
attributes: BlockAttributes
offset: GridPoint
Which portion of the space will be used, specified by the most negative corner.
resolution: u8
The side length of the cubical volume of sub-blocks (voxels) used for this block.
space: URef<Space>
Rotated(GridRotation, Box<Block>)
Identical to another block, but with rotated coordinates.
Specifically, the given rotation specifies how the contained block’s coordinate system is rotated into this block’s.
Tuple Fields of Rotated
0: GridRotation
1: Box<Block>
Implementations
Returns a new BlockBuilder
which may be used to construct a Block
value
from various inputs with convenient syntax.
Rotates this block by the specified rotation.
Compared to direct use of the Block::Rotated
variant, this will:
- Avoid constructing chains of
Block::Rotated(Block::Rotated(...))
. - Not rotate blocks that should never appear rotated (including atom blocks).
use all_is_cubes::block::{AIR, Block};
use all_is_cubes::content::make_some_voxel_blocks;
use all_is_cubes::math::{Face::*, GridRotation};
use all_is_cubes::universe::Universe;
let mut universe = Universe::new();
let [block] = make_some_voxel_blocks(&mut universe);
let clockwise = GridRotation::CLOCKWISE;
// Basic rotation
let rotated = block.clone().rotate(clockwise);
assert_eq!(rotated, Block::Rotated(clockwise, Box::new(block.clone())));
// Multiple rotations are combined
let double = rotated.clone().rotate(clockwise);
assert_eq!(double, Block::Rotated(clockwise * clockwise, Box::new(block.clone())));
// AIR is never rotated
assert_eq!(AIR, AIR.rotate(clockwise));
Standardizes any characteristics of this block which may be presumed to be specific to its usage in its current location, so that it can be used elsewhere or compared with others. Currently, this means removing rotation, but in the there may be additional or customizable changes (hence the abstract name).
use all_is_cubes::block::Block;
use all_is_cubes::content::make_some_voxel_blocks;
use all_is_cubes::math::{Face::*, GridRotation};
use all_is_cubes::universe::Universe;
let mut universe = Universe::new();
let [block] = make_some_voxel_blocks(&mut universe);
let clockwise = GridRotation::from_basis([PZ, PY, NX]);
let rotated = block.clone().rotate(clockwise);
assert_ne!(&block, &rotated);
assert_eq!(block, rotated.clone().unspecialize());
assert_eq!(block, rotated.clone().unspecialize().unspecialize());
Converts this Block
into a “flattened” and snapshotted form which contains all
information needed for rendering and physics, and does not require URef
access
to other objects.
pub fn listen(
&self,
listener: impl Listener<BlockChange> + Send + Sync + 'static
) -> Result<(), EvalBlockError>
pub fn listen(
&self,
listener: impl Listener<BlockChange> + Send + Sync + 'static
) -> Result<(), EvalBlockError>
Registers a listener for mutations of any data sources which may affect this
block’s Block::evaluate
result.
Note that this does not listen for mutations of the Block
value itself —
which would be impossible since it is an enum and all its fields
are public. In contrast, BlockDef
does perform such tracking.
This may fail under the same conditions as Block::evaluate
; it returns the
same error type so that callers which both evaluate and listen don’t need to
handle this separately.
Trait Implementations
Allows implicitly converting BlockBuilder
to the block it would build.
Performs the conversion.
Convert a color to a block with default attributes.
Convert a color to a block with default attributes.
Returns a corresponding VoxelBrush
, the most general form of blocky drawing.
Returns the range of Z coordinates that the blocks painted by this color value occupy. Read more
Auto Trait Implementations
impl RefUnwindSafe for Block
impl UnwindSafe for Block
Blanket Implementations
Mutably borrows from an owned value. Read more
Casts the value.
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self> where
Self: Binary,
Causes self
to use its Binary
implementation when Debug
-formatted.
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self> where
Self: Display,
Causes self
to use its Display
implementation when
Debug
-formatted. Read more
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self> where
Self: LowerExp,
Causes self
to use its LowerExp
implementation when
Debug
-formatted. Read more
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self> where
Self: LowerHex,
Causes self
to use its LowerHex
implementation when
Debug
-formatted. Read more
Causes self
to use its Octal
implementation when Debug
-formatted.
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self> where
Self: Pointer,
Causes self
to use its Pointer
implementation when
Debug
-formatted. Read more
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self> where
Self: UpperExp,
Causes self
to use its UpperExp
implementation when
Debug
-formatted. Read more
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self> where
Self: UpperHex,
Causes self
to use its UpperHex
implementation when
Debug
-formatted. Read more
Casts the value.
impl<T> Pipe for T where
T: ?Sized,
impl<T> Pipe for T where
T: ?Sized,
Pipes by value. This is generally the method you want to use. Read more
Borrows self
and passes that borrow into the pipe function. Read more
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R where
R: 'a,
Mutably borrows self
and passes that borrow into the pipe function. Read more
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R where
Self: Borrow<B>,
B: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.borrow()
into the pipe function. Read more
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R where
Self: BorrowMut<B>,
B: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.borrow_mut()
into the pipe
function. Read more
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R where
Self: AsRef<U>,
U: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.as_ref()
into the pipe function.
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R where
Self: AsMut<U>,
U: 'a + ?Sized,
R: 'a,
Mutably borrows self
, then passes self.as_mut()
into the pipe
function. Read more
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R where
Self: Deref<Target = T>,
T: 'a + ?Sized,
R: 'a,
Borrows self
, then passes self.deref()
into the pipe function.
Casts the value.
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Immutable access to the Borrow<B>
of a value. Read more
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Mutable access to the BorrowMut<B>
of a value. Read more
Immutable access to the AsRef<R>
view of a value. Read more
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Mutable access to the AsMut<R>
view of a value. Read more
Immutable access to the Deref::Target
of a value. Read more
Mutable access to the Deref::Target
of a value. Read more
Calls .tap()
only in debug builds, and is erased in release builds.
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
Calls .tap_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self where
Self: Borrow<B>,
B: ?Sized,
Calls .tap_borrow()
only in debug builds, and is erased in release
builds. Read more
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self where
Self: BorrowMut<B>,
B: ?Sized,
Calls .tap_borrow_mut()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self where
Self: AsRef<R>,
R: ?Sized,
Calls .tap_ref()
only in debug builds, and is erased in release
builds. Read more
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self where
Self: AsMut<R>,
R: ?Sized,
Calls .tap_ref_mut()
only in debug builds, and is erased in release
builds. Read more
Casts the value.
pub fn vzip(self) -> V
Casts the value.