Enum all_is_cubes::block::Block[][src]

#[non_exhaustive]
pub enum Block {
    Indirect(URef<BlockDef>),
    Atom(BlockAttributesRgba),
    Recur {
        attributes: BlockAttributes,
        offset: GridPoint,
        resolution: u8,
        space: URef<Space>,
    },
    Rotated(GridRotationBox<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; Blocks 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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Indirect(URef<BlockDef>)

A block whose definition is stored in a Universe.

Tuple Fields of Indirect

0: URef<BlockDef>

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: BlockAttributes1: Rgba
Recur

A block that is composed of smaller blocks, defined by the referenced Space.

Fields of Recur

attributes: BlockAttributesoffset: 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(GridRotationBox<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: GridRotation1: 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.

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

Performs the conversion.

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Allows implicitly converting BlockBuilder to the block it would build.

Performs the conversion.

Convert a color to a block with default attributes.

Performs the conversion.

Convert a color to a block with default attributes.

Performs the conversion.

Feeds this value into the given Hasher. Read more

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

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Raw data type. Read more

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

Blanket Implementations

Gets the TypeId of self. Read more

Casts the value.

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Casts the value.

Converts self into T using Into<T>. Read more

Causes self to use its Binary implementation when Debug-formatted.

Causes self to use its Display implementation when Debug-formatted. Read more

Causes self to use its LowerExp implementation when Debug-formatted. Read more

Causes self to use its LowerHex implementation when Debug-formatted. Read more

Causes self to use its Octal implementation when Debug-formatted.

Causes self to use its Pointer implementation when Debug-formatted. Read more

Causes self to use its UpperExp implementation when Debug-formatted. Read more

Causes self to use its UpperHex implementation when Debug-formatted. Read more

Performs the conversion.

Performs the conversion.

Casts the value.

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

Mutably borrows self and passes that borrow into the pipe function. Read more

Borrows self, then passes self.borrow() into the pipe function. Read more

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more

Borrows self, then passes self.as_ref() into the pipe function.

Mutably borrows self, then passes self.as_mut() into the pipe function. Read more

Borrows self, then passes self.deref() into the pipe function.

Mutably borrows self, then passes self.deref_mut() into the pipe function. Read more

Casts the value.

Immutable access to a value. Read more

Mutable access to a value. Read more

Immutable access to the Borrow<B> of a value. Read more

Mutable access to the BorrowMut<B> of a value. Read more

Immutable access to the AsRef<R> view of a value. Read more

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.

Calls .tap_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow() only in debug builds, and is erased in release builds. Read more

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref() only in debug builds, and is erased in release builds. Read more

Calls .tap_ref_mut() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref() only in debug builds, and is erased in release builds. Read more

Calls .tap_deref_mut() only in debug builds, and is erased in release builds. Read more

The resulting type after obtaining ownership.

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

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

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

Attempts to convert self into T using TryInto<T>. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

Casts the value.

Casts the value.