世界与方块
常用函数的方块位置可写成 [x, y, z],也可写成三个独立的数字。数字相对于当前脚本原点,普通 /script run 和应用命令的原点为 [0, 0, 0]。许多函数也接受带位置的方块句柄。
方块与坐标
mc.world 下的函数 | 结果 |
|---|---|
block(pos) | 取得该位置的方块句柄。通过 String(handle) 获取方块 ID。 |
block("minecraft:oak_log[axis=x]") | 取得没有世界位置的方块状态,可传给 set 或用于读取属性。 |
block_state(block[, property]) | 省略属性时返回所有状态属性组成的对象。指定属性时返回属性值,属性不存在时返回 null。 |
block_data(block) | 方块实体数据的 NBT 句柄,缺少数据时返回 null。 |
pos(blockOrEntity) | 返回带位置的方块或实体的坐标。 |
pos_offset(pos, direction[, distance]) | 返回沿指定方向偏移后的坐标,默认偏移一格。 |
set(pos, block[, properties][, nbt]) | 放置方块状态,属性可用对象传入,例如 {axis: "x"}。返回放置的方块句柄,没有改动时返回 false。 |
without_updates(callback) | 启用 Carpet 的方块更新抑制执行回调,并返回结果。 |
function placeTestLog() {
const target = [0, 64, 0];
mc.world.set(target, "minecraft:oak_log", {axis: "x"});
return mc.world.block_state(target, "axis");
}
标签、扫描与判断
mc.world 下的函数 | 结果 |
|---|---|
block_list([tag]) | 列出所有方块 ID 或指定方块标签的成员。标签 ID 不带 #,例如 "minecraft:wool"。 |
block_tags([block][, tag]) | 列出已注册的标签或某个方块所在的标签。同时提供方块和标签时检查其成员关系。 |
scan(center, range[, upperRange], callback) | 遍历中心周围的区域,统计回调返回真值的次数。范围是包含三轴距离的数组,包含边界。 |
volume(from, to, callback) | 遍历两角之间的长方体,包含边界,统计回调返回真值的次数。 |
air(pos)、solid(pos)、liquid(pos) | 检查方块是否为空气、固体或液体。 |
loaded(pos)、loaded_status(pos) | 检查区块是否加载,或读取其数字状态。 |
top(type, pos) | 读取该列的高度图,可用类型包括 "surface"、"motion"、"terrain" 和 "ocean_floor"。 |
weather() | 返回 "clear"、"rain" 或 "thunder"。 |
在 scan 和 volume 的回调里,_ 表示正在访问的方块,_x、_y、_z 表示这个方块的坐标。
const airCount = mc.world.scan([0, 64, 0], [2, 1, 2],
() => mc.world.air(_));
console.log(airCount);
其他相关函数
| 用途 | 函数 |
|---|---|
| 方块行为与光照 | flammable、transparent、suffocates、blocks_movement、emitted_light、block_light、sky_light、light、effective_light、see_sky、brightness、hardness、blast_resistance、power、block_sound、map_colour |
| 位置与遍历 | neighbours、rect、diamond |
| 修改和模拟 | destroy、harvest、place_item、update、ticks_randomly、block_tick、random_tick、create_explosion |
| 生物群系、兴趣点和区块 | biome、set_biome、poi、set_poi、in_slime_chunk、is_chunk_generated、generation_status、chunk_tickets、add_chunk_ticket、inhabited_time、spawn_potential |
| 结构和噪声查询 | structures、structure_references、structure_eligibility、sample_noise |