Zig:世界
函数
world.time
| Zig |
|---|
| pub fn time() core.Error!i64
|
世界时间,单位为 tick。
world.setTime
| Zig |
|---|
| pub fn setTime(t: i64) core.Error!void
|
以原生方式设置世界时间。
world.setWeather
| Zig |
|---|
| pub fn setWeather(weather: types.Weather) core.Error!void
|
world.updateWeather
| Zig |
|---|
| pub fn updateWeather(rain_level: f32, rain_ticks: i32, lightning_level: f32, lightning_ticks: i32) core.Error!void
|
设置雨和雷各自的强度与剩余时长,时长单位为 tick。
- 参数:
- rain_level :
f32
- rain_ticks :
i32
- lightning_level :
f32
- lightning_ticks :
i32
- 返回值类型:
core.Error!void
- 对应槽位:
level_update_weather
world.difficulty
| Zig |
|---|
| pub fn difficulty() core.Error!types.Difficulty
|
world.setDifficulty
| Zig |
|---|
| pub fn setDifficulty(d: types.Difficulty) core.Error!void
|
world.seed
| Zig |
|---|
| pub fn seed() core.Error!i64
|
world.gameRule
| Zig |
|---|
| pub fn gameRule(allocator: Allocator, name: []const u8) core.Error!GameRuleValue
|
读取一条游戏规则。规则名不认识时是 NoAnswer,不会给出某个默认值。
- 参数:
- allocator :
Allocator
- name :
[]const u8
- 返回值类型:
core.Error!GameRuleValue
- 对应槽位:
game_rule_get
world.setGameRule
| Zig |
|---|
| pub fn setGameRule(name: []const u8, value: []const u8) core.Error!void
|
用文本形式写入一条游戏规则,例如 "true" 或 "300"。
- 参数:
- name :
[]const u8
- value :
[]const u8
- 返回值类型:
core.Error!void
- 对应槽位:
game_rule_set
world.defaultSpawn
| Zig |
|---|
| pub fn defaultSpawn() core.Error!Pos3
|
world.setDefaultSpawn
| Zig |
|---|
| pub fn setDefaultSpawn(x: i32, y: i32, z: i32) core.Error!void
|
world.save
| Zig |
|---|
| pub fn save() core.Error!void
|
立即保存到磁盘。
world.sleepStatus
| Zig |
|---|
| pub fn sleepStatus(allocator: Allocator) core.Error!SleepStatus
|
world.biome
| Zig |
|---|
| pub fn biome(allocator: Allocator, dim: i32, x: i32, y: i32, z: i32) core.Error![]u8
|
一个格子处的生物群系名,由调用方持有。
- 参数:
- allocator :
Allocator
- dim :
i32
- x :
i32
- y :
i32
- z :
i32
- 返回值类型:
core.Error![]u8
- 对应槽位:
level_get_biome
world.setBiome
| Zig |
|---|
| pub fn setBiome(dim: i32, from_x: i32, from_z: i32, to_x: i32, to_z: i32, biome_name: []const u8) core.Error!i32
|
逐列设置一个区域的生物群系,并返回设置了多少列。两个角可以按任意顺序给出,不需要 y,因为基岩版按列保存生物群系。返回 0 表示一列也没有设置。
- 参数:
- dim :
i32
- from_x :
i32
- from_z :
i32
- to_x :
i32
- to_z :
i32
- biome_name :
[]const u8
- 返回值类型:
core.Error!i32
- 对应槽位:
level_set_biome
world.villages
| Zig |
|---|
| pub fn villages(allocator: Allocator, dim: i32) core.Error!types.Owned(Village)
|
一个维度里的村庄。
- 参数:
- allocator :
Allocator
- dim :
i32
- 返回值类型:
core.Error!types.Owned(Village)
- 对应槽位:
villages
world.structuresNear
| Zig |
|---|
| pub fn structuresNear(allocator: Allocator, dim: i32, x: i32, y: i32, z: i32, radius: i32) core.Error!types.Owned(Structure)
|
一个半径内、已加载区块里的硬编码生成区域。
- 参数:
- allocator :
Allocator
- dim :
i32
- x :
i32
- y :
i32
- z :
i32
- radius :
i32
- 返回值类型:
core.Error!types.Owned(Structure)
- 对应槽位:
structures_near
world.chunksLoaded
| Zig |
|---|
| pub fn chunksLoaded(dim: i32, min_x: i32, min_z: i32, max_x: i32, max_z: i32) core.Error!bool
|
区域覆盖的每个区块是否都在内存里。
- 参数:
- dim :
i32
- min_x :
i32
- min_z :
i32
- max_x :
i32
- max_z :
i32
- 返回值类型:
core.Error!bool
- 对应槽位:
level_chunks_loaded
world.deleteChunkKeys
| Zig |
|---|
| pub fn deleteChunkKeys(dim: i32, chunk_x: i32, chunk_z: i32) core.Error!i32
|
删除一个区块的全部存档键,引擎会在下次加载它时从生成器重新生成。只有未加载的区块可以这样还原。返回删掉了多少个键。
world.chunkKeys
| Zig |
|---|
| pub fn chunkKeys(allocator: Allocator, dim: i32, chunk_x: i32, chunk_z: i32) core.Error![][]u8
|
列出一个区块的全部存档键,每个键由调用方持有,切片也一样。
- 参数:
- allocator :
Allocator
- dim :
i32
- chunk_x :
i32
- chunk_z :
i32
- 返回值类型:
core.Error![][]u8
- 对应槽位:
level_chunk_keys
world.deleteKey
| Zig |
|---|
| pub fn deleteKey(key: []const u8) core.Error!void
|
逐字节删除一个存档键。内容不会被解释。
world.findPath
| Zig |
|---|
| pub fn findPath(allocator: Allocator, who: props.Entity, x: i32, y: i32, z: i32) core.Error![]u8
|
为一个实体计算前往目标格子的路径,结果是宿主的 SNBT {nodes, reached}。目前所有宿主都返回 NotProvided:寻路没有实现。
- 参数:
- allocator :
Allocator
- who :
props.Entity
- x :
i32
- y :
i32
- z :
i32
- 返回值类型:
core.Error![]u8
- 对应槽位:
level_find_path
world.getBlock
| Zig |
|---|
| pub fn getBlock(allocator: Allocator, dim: i32, x: i32, y: i32, z: i32) core.Error!types.Owned(BlockInfo)
|
读取一个方块。名字和 SNBT 属于结果里的 arena。
- 参数:
- allocator :
Allocator
- dim :
i32
- x :
i32
- y :
i32
- z :
i32
- 返回值类型:
core.Error!types.Owned(BlockInfo)
- 对应槽位:
get_block
world.setBlock
| Zig |
|---|
| pub fn setBlock(dim: i32, x: i32, y: i32, z: i32, spec: []const u8) core.Error!void
|
用默认的更新标志以原生方式放置一个方块。spec 是裸名字(例如 "minecraft:stone")或完整的 SNBT。名字不认识时会失败,而不是放一个占位方块。
- 参数:
- dim :
i32
- x :
i32
- y :
i32
- z :
i32
- spec :
[]const u8
- 返回值类型:
core.Error!void
- 对应槽位:
set_block
| Zig |
|---|
| pub fn getExtraBlock(allocator: Allocator, dim: i32, x: i32, y: i32, z: i32) core.Error![]u8
|
以方块名的形式读取一个格子的液体层;空的液体层得到空气。
- 参数:
- allocator :
Allocator
- dim :
i32
- x :
i32
- y :
i32
- z :
i32
- 返回值类型:
core.Error![]u8
- 对应槽位:
get_extra_block
| Zig |
|---|
| pub fn setExtraBlock(dim: i32, x: i32, y: i32, z: i32, spec: []const u8, update: BlockUpdate) core.Error!void
|
写入一个格子的液体层;写 "minecraft:air" 可清除它。
- 参数:
- dim :
i32
- x :
i32
- y :
i32
- z :
i32
- spec :
[]const u8
- update :
BlockUpdate
- 返回值类型:
core.Error!void
- 对应槽位:
set_extra_block
world.setBlockNbt
| Zig |
|---|
| pub fn setBlockNbt(dim: i32, x: i32, y: i32, z: i32, snbt: []const u8, update: BlockUpdate) core.Error!void
|
用序列化的 NBT 写入一个方块,格式就是 getBlock 产生的那种。
- 参数:
- dim :
i32
- x :
i32
- y :
i32
- z :
i32
- snbt :
[]const u8
- update :
BlockUpdate
- 返回值类型:
core.Error!void
- 对应槽位:
edit_set_block_nbt
world.setBlockStates
| Zig |
|---|
| pub fn setBlockStates(dim: i32, x: i32, y: i32, z: i32, name: []const u8, states_snbt: []const u8, update: BlockUpdate) core.Error!void
|
用一个名字加可选的部分状态写入一个方块。states_snbt 为空表示每个状态都取默认值。
- 参数:
- dim :
i32
- x :
i32
- y :
i32
- z :
i32
- name :
[]const u8
- states_snbt :
[]const u8
- update :
BlockUpdate
- 返回值类型:
core.Error!void
- 对应槽位:
edit_set_block_states
world.setBlockEntity
| Zig |
|---|
| pub fn setBlockEntity(dim: i32, x: i32, y: i32, z: i32, snbt: []const u8) core.Error!void
|
把一个方块实体的 NBT 写回去。该格子里必须已经是对应的方块。
world.scan
| Zig |
|---|
| pub fn scan(allocator: Allocator, dim: i32, bounds: Bounds) core.Error!Scan
|
扫描一个区域,把每个方块和每个实体收集到内存里。
- 参数:
- allocator :
Allocator
- dim :
i32
- bounds :
Bounds
- 返回值类型:
core.Error!Scan
- 对应槽位:
scan_region
world.scanIndexed
| Zig |
|---|
| pub fn scanIndexed(allocator: Allocator, dim: i32, bounds: Bounds) core.Error!IndexedScan
|
把一个区域的方块扫描成调色板加格子。每种不同的方块状态只序列化一次,所以一百万个石头格子只花一次 SNBT 的代价,而不是一百万次。
- 参数:
- allocator :
Allocator
- dim :
i32
- bounds :
Bounds
- 返回值类型:
core.Error!IndexedScan
- 对应槽位:
scan_region_indexed
world.fillRegion
| Zig |
|---|
| pub fn fillRegion(dim: i32, bounds: Bounds, spec: []const u8, update: BlockUpdate) core.Error!u64
|
用同一种方块填满一个盒子,并返回写入了多少格。spec 是裸名字或完整的 SNBT,整个盒子只解析一次。
- 参数:
- dim :
i32
- bounds :
Bounds
- spec :
[]const u8
- update :
BlockUpdate
- 返回值类型:
core.Error!u64
- 对应槽位:
edit_fill_region
world.setBlocks
| Zig |
|---|
| pub fn setBlocks(allocator: Allocator, dim: i32, palette: []const []const u8, cells: []const BlockCell, update: BlockUpdate) core.Error!u64
|
一次调用写入许多格子,并返回写入了多少个。palette 的每一项是一个方块规格,只解析一次;索引超出范围、或方块没有解析出来的格子会被跳过。
- 参数:
- allocator :
Allocator
- dim :
i32
- palette :
[]const []const u8
- cells :
[]const BlockCell
- update :
BlockUpdate
- 返回值类型:
core.Error!u64
- 对应槽位:
edit_set_blocks
world.spawnMob
| Zig |
|---|
| pub fn spawnMob(dim: i32, type_name: []const u8, x: f64, y: f64, z: f64) core.Error!props.Entity
|
生成一只生物并返回它。
- 参数:
- dim :
i32
- type_name :
[]const u8
- x :
f64
- y :
f64
- z :
f64
- 返回值类型:
core.Error!props.Entity
- 对应槽位:
spawn_mob
world.spawnEntityNbt
| Zig |
|---|
| pub fn spawnEntityNbt(dim: i32, snbt: []const u8, pos: ?types.Vec3) core.Error!props.Entity
|
用完整的 NBT 生成一个实体,是 Entity.snapshot 的逆操作。pos 会覆盖 Pos 标签。目前所有宿主都返回 NotProvided:让已加载实体获得新唯一 id 的引擎辅助函数无法访问。
- 参数:
- dim :
i32
- snbt :
[]const u8
- pos :
?types.Vec3
- 返回值类型:
core.Error!props.Entity
- 对应槽位:
edit_spawn_entity_nbt
world.explode
| Zig |
|---|
| pub fn explode(dim: i32, x: f64, y: f64, z: f64, options: ExplodeOptions) core.Error!void
|
在一个点引爆。
- 参数:
- dim :
i32
- x :
f64
- y :
f64
- z :
f64
- options :
ExplodeOptions
- 返回值类型:
core.Error!void
- 对应槽位:
explode
world.spawnParticle
| Zig |
|---|
| pub fn spawnParticle(dim: i32, effect: []const u8, x: f64, y: f64, z: f64) core.Error!void
|
整个维度都能看到的粒子。只给一个人看用 spawnParticleFor。
- 参数:
- dim :
i32
- effect :
[]const u8
- x :
f64
- y :
f64
- z :
f64
- 返回值类型:
core.Error!void
- 对应槽位:
spawn_particle
world.spawnParticleFor
| Zig |
|---|
| pub fn spawnParticleFor(player: props.Player, dim: i32, effect: []const u8, x: f64, y: f64, z: f64) core.Error!void
|
只给一名玩家看到的粒子。
- 参数:
- player :
props.Player
- dim :
i32
- effect :
[]const u8
- x :
f64
- y :
f64
- z :
f64
- 返回值类型:
core.Error!void
- 对应槽位:
spawn_particle_for
world.playerPosition
| Zig |
|---|
| pub fn playerPosition(name: []const u8) core.Error!types.PlayerPosition
|
按名字查找一名已连接玩家的脚下位置和所在维度。
world.weatherValue
| Zig |
|---|
| pub fn weatherValue(dim: i32, prop: i32) core.Error!f64
|
按 PIER_WPROP_* 键读取一个维度的一项天气值。
world.rainLevel
| Zig |
|---|
| pub fn rainLevel(dim: i32) core.Error!f64
|
一个维度的降雨强度,0 表示无雨,1 表示满雨。
world.targetRainLevel
| Zig |
|---|
| pub fn targetRainLevel(dim: i32) core.Error!f64
|
world.lightningLevel
| Zig |
|---|
| pub fn lightningLevel(dim: i32) core.Error!f64
|
一个维度的雷暴强度,0 表示无雷暴,1 表示雷暴。
world.targetLightningLevel
| Zig |
|---|
| pub fn targetLightningLevel(dim: i32) core.Error!f64
|
world.fogLevel
| Zig |
|---|
| pub fn fogLevel(dim: i32) core.Error!f64
|
world.skyFlashTime
| Zig |
|---|
| pub fn skyFlashTime(dim: i32) core.Error!f64
|
声明
world.Pos3
| Zig |
|---|
| pub const Pos3 = types.Pos3;
|
world.Bounds
| Zig |
|---|
| pub const Bounds = types.Bounds;
|
world.BlockUpdate
| Zig |
|---|
| pub const BlockUpdate = types.BlockUpdate;
|
world.Scan
| Zig |
|---|
| pub const Scan = struct {
arena: std.heap.ArenaAllocator,
blocks: []const BlockInfo,
entities: []const EntityInfo,
// ...
};
|
一次扫描的结果:区域里的每个方块,以及其中的每个实体。
world.Scan.deinit
| Zig |
|---|
| pub fn deinit(self: *Scan) void
|
world.Scan.nonAirCount
| Zig |
|---|
| pub fn nonAirCount(self: *const Scan) usize
|
不是空气的格子数,按方块名判断。
world.IndexedScan
| Zig |
|---|
| pub const IndexedScan = struct {
arena: std.heap.ArenaAllocator,
palette: []const PaletteEntry,
cells: []const BlockCell,
// ...
};
|
一次 scanIndexed 的结果:每种不同的方块状态一份,以及每个位置一个指向调色板的索引。
world.IndexedScan.deinit
| Zig |
|---|
| pub fn deinit(self: *IndexedScan) void
|
world.IndexedScan.blockOf
| Zig |
|---|
| pub fn blockOf(self: *const IndexedScan, cell: BlockCell) ?PaletteEntry
|
一个格子对应的调色板条目;索引不在调色板里时为 null。
world.GameRuleValue
| Zig |
|---|
| pub const GameRuleValue = union(enum) {
boolean: bool,
int: i64,
float: f64,
// ...
};
|
一条游戏规则的值。
world.SleepStatus
| Zig |
|---|
| pub const SleepStatus = struct {
sleeping: bool,
total_players: i32,
active_sleeping: i32,
// ...
};
|
玩家们的睡眠状态。
world.Village
| Zig |
|---|
| pub const Village = struct {
uuid: []const u8,
center: Pos3,
bounds: Bounds,
poi_count: i32,
// ...
};
|
一个村庄。
world.Structure
| Zig |
|---|
| pub const Structure = struct {
kind: []const u8,
bounds: Bounds,
// ...
};
|
一个硬编码的生成区域:要塞、女巫小屋、海底神殿或类似的结构。
world.BlockInfo
| Zig |
|---|
| pub const BlockInfo = struct {
x: i32,
y: i32,
z: i32,
name: []const u8,
snbt: []const u8,
// ...
};
|
宿主报告的一个方块。
world.EntityInfo
| Zig |
|---|
| pub const EntityInfo = struct {
x: i32,
y: i32,
z: i32,
type_name: []const u8,
snbt: []const u8,
// ...
};
|
扫描时落在区域里的一个实体。
world.PaletteEntry
| Zig |
|---|
| pub const PaletteEntry = struct {
name: []const u8,
snbt: []const u8,
// ...
};
|
scanIndexed 遇到的一种不同的方块状态。
world.BlockCell
| Zig |
|---|
| pub const BlockCell = extern struct {
x: i32,
y: i32,
z: i32,
index: u32,
// ...
};
|
scanIndexed 或 setBlocks 的一个格子:一个位置加上调色板里的一个索引。
world.ExplodeOptions
| Zig |
|---|
| pub const ExplodeOptions = struct {
radius: f32,
max_resistance: f32 = 3.4028235e38,
/// The actor blamed for the blast, or null for no source.
source: ?props.Entity = null,
fire: bool = false,
breaks_blocks: bool = true,
allow_underwater: bool = false,
// ...
};
|
一次爆炸做什么、由谁引起。