levilamina::block
Blocks: a cell addressed by a dimension plus a coordinate.
There are two write paths, and the native one is the default
Block::set goes through set_block, meaning BlockSource::setBlock, and takes a name or
full SNBT. Block::set_states and Block::set_nbt go through edit_* and add a
BlockUpdate letting the caller decide whether to notify neighbors and synchronize the
client. Turning both off during a bulk fill is an order of magnitude faster, at the cost of
resynchronizing afterwards.
A waterlogged block needs the liquid layer
Waterlogging in Bedrock is not a block state but a second block in the same cell: the main layer
is the stair and the liquid layer is the water. Block::name sees only the main layer, so
copying and pasting a waterlogged stair loses the water entirely: the main layer is exact and
the water is gone. Moving the water with it means reading and writing Block::extra.
Block
| Rust |
|---|
| pub struct Block {
// private fields
}
|
One cell in the world.
- Implements:
Debug, Clone, Copy, PartialEq, Eq, Hash, Display
Block::at
| Rust |
|---|
| pub fn at(dim: i32, x: i32, y: i32, z: i32) -> Block
|
- Parameters:
- dim :
i32
- x :
i32
- y :
i32
- z :
i32
- Return type:
Block
Block::at_pos
| Rust |
|---|
| pub fn at_pos(dim: i32, pos: PositionI32) -> Block
|
- Parameters:
- dim :
i32
- pos :
PositionI32
- Return type:
Block
Block::dimension
| Rust |
|---|
| pub fn dimension(&self) -> i32
|
Block::position
| Rust |
|---|
| pub fn position(&self) -> PositionI32
|
Block::read
| Rust |
|---|
| pub fn read(&self) -> Result<BlockInfo>
|
The type name and the full SNBT, both from one call.
- Return type:
Result<BlockInfo>
- Slots:
get_block
Block::to_nbt
| Rust |
|---|
| pub fn to_nbt(&self) -> Result<NbtValue>
|
Parses the full serialization into an NBT tree. Writing it back unchanged uses
Block::set_nbt, a path that does not go through the parser of this layer.
Block::num
| Rust |
|---|
| pub fn num(&self, prop: i32) -> Result<f64>
|
Reads a PIER_BPROP_* numeric property.
Block::text
| Rust |
|---|
| pub fn text(&self, prop: i32) -> Result<String>
|
Reads a PIER_BSTR_* string property.
| Rust |
|---|
| pub fn tags(&self) -> Result<Vec<String>>
|
The block tags.
Block::act
| Rust |
|---|
| pub fn act(&self, action: i32, sarg: &str) -> Result<String>
|
Runs a PIER_BACT_* action.
Block::has_tag
| Rust |
|---|
| pub fn has_tag(&self, tag: &str) -> Result<bool>
|
Block::as_item
| Rust |
|---|
| pub fn as_item(&self) -> Result<crate::item::ItemStack>
|
Treats this cell as an item, through Block::asItemInstance.
- Return type:
Result<crate::item::ItemStack>
- Slots:
block_action
Block::pop_resource
| Rust |
|---|
| pub fn pop_resource(&self, item: &crate::item::ItemStack) -> Result<()>
|
Drops one item at this cell.
- Parameters:
- item :
&crate::item::ItemStack
- Return type:
Result<()>
- Slots:
block_action
Block::set
| Rust |
|---|
| pub fn set(&self, spec: &str) -> Result<()>
|
Places a block. spec is a name such as "minecraft:stone", or full SNBT.
An unrecognized name fails and no placeholder block is put down, whose symptom would
be a patch of purple-and-black in the world with no visible origin.
- Parameters:
- Return type:
Result<()>
- Slots:
set_block
Block::set_nbt
| Rust |
|---|
| pub fn set_nbt(&self, snbt: &str, update: BlockUpdate) -> Result<()>
|
Places a block from full NBT, deciding the update flags yourself.
- Parameters:
- snbt :
&str
- update :
BlockUpdate
- Return type:
Result<()>
- Slots:
edit_set_block_nbt
Block::set_states
| Rust |
|---|
| pub fn set_states(self, name: &str, states: Option<&str>, update: BlockUpdate) -> Result<()>
|
Places a block by name plus a subset of its states.
A states of None means every state at its default. The host takes the version
number from the default states and a caller must not fill it in: a wrong version number
lands the block under a different set of state meanings.
- Parameters:
- name :
&str
- states :
Option<&str>
- update :
BlockUpdate
- Return type:
Result<()>
- Slots:
edit_set_block_states
| Rust |
|---|
| pub fn extra(&self) -> Result<String>
|
Reads the liquid layer. An empty one reads back as "minecraft:air" and is not an
error.
| Rust |
|---|
| pub fn set_extra(&self, spec: &str, update: BlockUpdate) -> Result<()>
|
Writes the liquid layer. Writing "minecraft:air" clears it.
- Parameters:
- spec :
&str
- update :
BlockUpdate
- Return type:
Result<()>
- Slots:
set_extra_block
Block::container
| Rust |
|---|
| pub fn container(&self) -> crate::container::Container
|
The container at this cell, a chest or a hopper. It does not check whether one is
really there, since checking would cross the ABI once, and the returned
crate::container::Container reports it naturally the first time it is used.
- Return type:
crate::container::Container
Block::name
| Rust |
|---|
| pub fn name(&self) -> Result<String>
|
Block::snbt
| Rust |
|---|
| pub fn snbt(&self) -> Result<String>
|
Block::description_id
| Rust |
|---|
| pub fn description_id(&self) -> Result<String>
|
The localization key, not the text that is displayed.
Block::display_name
| Rust |
|---|
| pub fn display_name(&self) -> Result<String>
|
The localized display name.
Block::debug_string
| Rust |
|---|
| pub fn debug_string(&self) -> Result<String>
|
The engine's own debug string. Its format follows the version, so no decision rests on
it.
Block::is_air
| Rust |
|---|
| pub fn is_air(&self) -> Result<bool>
|
Block::is_solid
| Rust |
|---|
| pub fn is_solid(&self) -> Result<bool>
|
Block::is_container
| Rust |
|---|
| pub fn is_container(&self) -> Result<bool>
|
Block::is_door
| Rust |
|---|
| pub fn is_door(&self) -> Result<bool>
|
Block::is_fence
| Rust |
|---|
| pub fn is_fence(&self) -> Result<bool>
|
Block::is_rail
| Rust |
|---|
| pub fn is_rail(&self) -> Result<bool>
|
Block::is_slab
| Rust |
|---|
| pub fn is_slab(&self) -> Result<bool>
|
Block::is_stair
| Rust |
|---|
| pub fn is_stair(&self) -> Result<bool>
|
Block::is_wall
| Rust |
|---|
| pub fn is_wall(&self) -> Result<bool>
|
Block::is_crop
| Rust |
|---|
| pub fn is_crop(&self) -> Result<bool>
|
Block::is_unbreakable
| Rust |
|---|
| pub fn is_unbreakable(&self) -> Result<bool>
|
Block::is_crafting_block
| Rust |
|---|
| pub fn is_crafting_block(&self) -> Result<bool>
|
Block::is_interactive_block
| Rust |
|---|
| pub fn is_interactive_block(&self) -> Result<bool>
|
Block::is_signal_source
| Rust |
|---|
| pub fn is_signal_source(&self) -> Result<bool>
|
It can produce a redstone signal itself, as a lever or a button does.
| Rust |
|---|
| pub fn requires_tool(&self) -> Result<bool>
|
It drops nothing unless mined with the right tool.
Block::has_block_entity
| Rust |
|---|
| pub fn has_block_entity(&self) -> Result<bool>
|
Block::data
| Rust |
|---|
| pub fn data(&self) -> Result<i32>
|
The legacy data value. A newer block uses Block::states.
Block::variant
| Rust |
|---|
| pub fn variant(&self) -> Result<i32>
|
The variant data value, whose meaning differs per actor kind.
Block::block_item_id
| Rust |
|---|
| pub fn block_item_id(&self) -> Result<i32>
|
The numeric id of the matching item.
Block::light
| Rust |
|---|
| pub fn light(&self) -> Result<i32>
|
The actual brightness of this cell, skylight included.
Block::light_emission
| Rust |
|---|
| pub fn light_emission(&self) -> Result<i32>
|
How much light this block emits itself.
Block::destroy_speed
| Rust |
|---|
| pub fn destroy_speed(&self) -> Result<f64>
|
The mining hardness; larger is slower.
Block::explosion_resistance
| Rust |
|---|
| pub fn explosion_resistance(&self) -> Result<f64>
|
The blast resistance.
Block::friction
| Rust |
|---|
| pub fn friction(&self) -> Result<f64>
|
The friction coefficient; ice is one of the low ones.
Block::bounciness
| Rust |
|---|
| pub fn bounciness(&self) -> Result<f64>
|
The bounciness; a slime block is non-zero.
Block::burn_odds
| Rust |
|---|
| pub fn burn_odds(&self) -> Result<i32>
|
The probability weight of catching fire.
Block::flame_odds
| Rust |
|---|
| pub fn flame_odds(&self) -> Result<i32>
|
The probability weight of spreading fire to a neighbor.
Block::redstone_signal
| Rust |
|---|
| pub fn redstone_signal(&self) -> Result<i32>
|
The redstone signal strength this cell outputs, from 0 to 15.
Block::comparator_signal
| Rust |
|---|
| pub fn comparator_signal(&self) -> Result<i32>
|
The strength a comparator reads from this cell; a container computes it from how full
it is.
Block::state
| Rust |
|---|
| pub fn state(&self, name: &str) -> Result<String>
|
Reads the value of one block state.
Block::states
| Rust |
|---|
| pub fn states(&self) -> Result<NbtValue>
|
Every block state.
Block::set_state
| Rust |
|---|
| pub fn set_state(&self, name: &str, value: &str) -> Result<()>
|
Block::collision_shape
| Rust |
|---|
| pub fn collision_shape(&self) -> Result<Vec<Bounds>>
|
The collision box.
Block::block_entity
| Rust |
|---|
| pub fn block_entity(&self) -> Result<Option<NbtValue>>
|
The NBT of the block entity. A cell with no block entity gives Ok(None).
Block::set_block_entity
| Rust |
|---|
| pub fn set_block_entity(&self, snbt: &str) -> Result<()>
|
Writes the NBT of the block entity back, through BlockActor::load.
The cell already has to hold the matching kind of block.
BlockInfo
| Rust |
|---|
| pub struct BlockInfo {
pub pos: PositionI32,
/// The type name, such as `"minecraft:redstone_wire"`.
pub name: String,
/// The full serialization, `{name, states, version}`.
pub snbt: String,
}
|
What one block cell reads back as.
- Implements:
Debug, Clone, PartialEq, Eq
BlockInfo::is_air
| Rust |
|---|
| pub fn is_air(&self) -> bool
|