levilamina::block · 方块
方块:用维度加坐标指定的一格。
有两条写入路径,默认用原生的那条
Block::set 走 set_block,也就是 BlockSource::setBlock,接收方块名或完整的 SNBT。Block::set_states 和 Block::set_nbt 走 edit_*,多一个 BlockUpdate,让调用方决定要不要通知相邻方块、要不要同步给客户端。批量填充时两者都关掉,速度能快一个数量级,代价是之后要重新同步。
含水方块要读写液体层
基岩版的含水用的是同一格里的第二个方块:主层是楼梯,液体层是水。Block::name 只看得到主层,所以复制、粘贴含水楼梯会把水全部丢掉:主层完全正确,水没了。要把水一起搬过去,就要读写 Block::extra。
Block
| Rust |
|---|
| pub struct Block {
// private fields
}
|
世界里的一格。
- 实现的 trait:
Debug、Clone、Copy、PartialEq、Eq、Hash、Display
Block::at
| Rust |
|---|
| pub fn at(dim: i32, x: i32, y: i32, z: i32) -> Block
|
- 参数:
- dim :
i32
- x :
i32
- y :
i32
- z :
i32
- 返回值类型:
Block
Block::at_pos
| Rust |
|---|
| pub fn at_pos(dim: i32, pos: PositionI32) -> Block
|
- 参数:
- dim :
i32
- pos :
PositionI32
- 返回值类型:
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>
|
类型名和完整的 SNBT,一次调用拿到两者。
Block::to_nbt
| Rust |
|---|
| pub fn to_nbt(&self) -> Result<NbtValue>
|
把完整的序列化解析成 NBT 树。要原样写回,用 Block::set_nbt,那条路径不经过这一层的解析器。
Block::num
| Rust |
|---|
| pub fn num(&self, prop: i32) -> Result<f64>
|
读取一个 PIER_BPROP_* 数值属性。
Block::text
| Rust |
|---|
| pub fn text(&self, prop: i32) -> Result<String>
|
读取一个 PIER_BSTR_* 字符串属性。
| Rust |
|---|
| pub fn tags(&self) -> Result<Vec<String>>
|
方块的标签。
Block::act
| Rust |
|---|
| pub fn act(&self, action: i32, sarg: &str) -> Result<String>
|
执行一个 PIER_BACT_* 动作。
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>
|
把这一格当作物品,经 Block::asItemInstance 转换。
Block::pop_resource
| Rust |
|---|
| pub fn pop_resource(&self, item: &crate::item::ItemStack) -> Result<()>
|
在这一格掉落一个物品。
- 参数:
- item :
&crate::item::ItemStack
- 返回值类型:
Result<()>
- 对应槽位:
block_action
Block::set
| Rust |
|---|
| pub fn set(&self, spec: &str) -> Result<()>
|
放置一个方块。spec 是 "minecraft:stone" 这样的名字,或者完整的 SNBT。
名字认不出来时调用失败,不会放一个占位方块;放了占位方块的症状,是世界里出现一块来历不明的紫黑格子。
Block::set_nbt
| Rust |
|---|
| pub fn set_nbt(&self, snbt: &str, update: BlockUpdate) -> Result<()>
|
用完整的 NBT 放置一个方块,更新标志由你自己决定。
Block::set_states
| Rust |
|---|
| pub fn set_states(self, name: &str, states: Option<&str>, update: BlockUpdate) -> Result<()>
|
用方块名加上部分状态放置一个方块。
states 为 None 表示所有状态都用默认值。宿主从默认状态里取版本号,调用方不能自己填:版本号错了,方块会按另一套状态含义落地。
| Rust |
|---|
| pub fn extra(&self) -> Result<String>
|
读取液体层。空的液体层读出来是 "minecraft:air",不算错误。
| Rust |
|---|
| pub fn set_extra(&self, spec: &str, update: BlockUpdate) -> Result<()>
|
写入液体层。写入 "minecraft:air" 就是清空。
Block::container
| Rust |
|---|
| pub fn container(&self) -> crate::container::Container
|
这一格的容器,比如箱子或漏斗。它不检查那里是不是真的有容器,因为检查要跨一次 ABI;返回的 crate::container::Container 第一次使用时自然会报告。
- 返回值类型:
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>
|
本地化用的键,并非显示出来的文字。
Block::display_name
| Rust |
|---|
| pub fn display_name(&self) -> Result<String>
|
本地化以后的显示名。
Block::debug_string
| Rust |
|---|
| pub fn debug_string(&self) -> Result<String>
|
引擎自己的调试字符串。格式随版本变化,所以不要拿它做任何判断。
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>
|
自己能产生红石信号,像拉杆或按钮那样。
| Rust |
|---|
| pub fn requires_tool(&self) -> Result<bool>
|
不用正确的工具挖就什么都不掉。
Block::has_block_entity
| Rust |
|---|
| pub fn has_block_entity(&self) -> Result<bool>
|
Block::data
| Rust |
|---|
| pub fn data(&self) -> Result<i32>
|
旧版的数据值。较新的方块请用 Block::states。
Block::variant
| Rust |
|---|
| pub fn variant(&self) -> Result<i32>
|
variant 数据值,含义随实体种类而不同。
Block::block_item_id
| Rust |
|---|
| pub fn block_item_id(&self) -> Result<i32>
|
对应物品的数字 id。
Block::light
| Rust |
|---|
| pub fn light(&self) -> Result<i32>
|
这一格的实际亮度,包括天空光。
Block::light_emission
| Rust |
|---|
| pub fn light_emission(&self) -> Result<i32>
|
这个方块自己发出多少光。
Block::destroy_speed
| Rust |
|---|
| pub fn destroy_speed(&self) -> Result<f64>
|
挖掘硬度;越大越慢。
Block::explosion_resistance
| Rust |
|---|
| pub fn explosion_resistance(&self) -> Result<f64>
|
爆炸抗性。
Block::friction
| Rust |
|---|
| pub fn friction(&self) -> Result<f64>
|
摩擦系数;冰是摩擦很低的一种。
Block::bounciness
| Rust |
|---|
| pub fn bounciness(&self) -> Result<f64>
|
弹性;黏液块的弹性不为零。
Block::burn_odds
| Rust |
|---|
| pub fn burn_odds(&self) -> Result<i32>
|
着火的概率权重。
Block::flame_odds
| Rust |
|---|
| pub fn flame_odds(&self) -> Result<i32>
|
把火蔓延给相邻方块的概率权重。
Block::redstone_signal
| Rust |
|---|
| pub fn redstone_signal(&self) -> Result<i32>
|
这一格输出的红石信号强度,0 到 15。
Block::comparator_signal
| Rust |
|---|
| pub fn comparator_signal(&self) -> Result<i32>
|
比较器从这一格读到的强度;容器按装满的程度计算它。
Block::state
| Rust |
|---|
| pub fn state(&self, name: &str) -> Result<String>
|
读取一个方块状态的值。
Block::states
| Rust |
|---|
| pub fn states(&self) -> Result<NbtValue>
|
所有方块状态。
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>>
|
碰撞箱。
Block::block_entity
| Rust |
|---|
| pub fn block_entity(&self) -> Result<Option<NbtValue>>
|
方块实体的 NBT。这一格没有方块实体时返回 Ok(None)。
Block::set_block_entity
| Rust |
|---|
| pub fn set_block_entity(&self, snbt: &str) -> Result<()>
|
把方块实体的 NBT 写回去,经 BlockActor::load。这一格里必须已经是对应种类的方块。
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,
}
|
一个方块格读回来的内容。
- 实现的 trait:
Debug、Clone、PartialEq、Eq
BlockInfo::is_air
| Rust |
|---|
| pub fn is_air(&self) -> bool
|