🌍 世界与方块 API¶
时间、天气、游戏规则,以及世界里的每一个方块。
世界¶
获取当前时间¶
Rust:World::get().time()
Go:levilamina.Time()
Zig:levilamina.slot("get_time")
- 返回值:当天的时间,以游戏刻计算:一天 24000 刻,0 是日出,6000 是正午,18000 是午夜
- 返回值类型:Rust
Result<i64>,Go(int64, error) - 对应槽位:
get_time -
示例:
- Rust
Rust - Go
Go
设置时间¶
Rust:World::get().set_time(t)
Go:levilamina.SetTime(t)
Zig:levilamina.slot("set_time")
- 参数:
- t : 整数
游戏刻
- t : 整数
- 返回值:成功时没有返回值
- 返回值类型:Rust
Result<()>,Goerror,Zigbool - 对应槽位:
set_time -
示例:
- Rust
Rust - Go
Go - Zig
设置天气¶
Rust:World::get().set_weather(weather)
Go:levilamina.SetWeather(weather)
Zig:levilamina.slot("set_weather")
- 参数:
- weather : Rust
Weather,Go、Zig 整数
晴、雨、雷暴(0、1、2)
- weather : Rust
- 返回值:成功时没有返回值
- 返回值类型:Rust
Result<()>,Goerror - 对应槽位:
set_weather -
示例:
- Rust
Rust - Go
Go
读写游戏规则¶
Rust:World::get().game_rule(name)
Go:levilamina.GameRule(name)
Zig:levilamina.slot("game_rule_get")
写入:Rust set_game_rule(name, value),Go SetGameRule(name, value),槽位 game_rule_set。值用文本传入,宿主按规则的类型去解析。
- 参数:
- name : 字符串
规则名,和/gamerule里的一样
- name : 字符串
- 返回值:规则的值
- 返回值类型:Rust
Result<GameRuleValue>,Go(string, error) - 对应槽位:
game_rule_get,game_rule_set -
示例:
- Rust
Rust - Go
方块¶
方块用「维度 + 坐标」来指定:Rust Block::at(dim, x, y, z),Go levilamina.Block(dim, x, y, z),Zig levilamina.BlockAt.at(dim, x, y, z)。以下用 block 代表它。
读取方块¶
Rust:block.read()
Go:block.Info()
Zig:block.typeName(allocator)
- 返回值:方块的类型名,比如
minecraft:oak_log,以及它的方块状态 - 返回值类型:Rust
Result<BlockInfo>,Go(BlockInfo, error),Ziglevilamina.Error![]u8- 世界还没加载好时,读取会返回错误。
- 对应槽位:
get_block -
示例:
- Rust
Rust - Go
Go - Zig
放置方块¶
Rust:block.set(spec)
Go:block.Set(spec)
Zig:levilamina.slot("set_block")
- 参数:
- spec : 字符串
方块,写法和/setblock一样,可以带方块状态,比如minecraft:oak_log["pillar_axis"="x"]
- spec : 字符串
- 返回值:成功时没有返回值
- 返回值类型:Rust
Result<()>,Goerror,Zigbool - 对应槽位:
set_block -
示例:
- Rust
Rust - Go
Go - Zig
读写方块状态¶
Rust:block.state(name)
Go:block.State(name)
Zig:levilamina.slot("block_get_state")
写入:Rust set_state(name, value),Go SetState(name, value),槽位 block_set_state。
- 参数:
- name : 字符串
状态名,比如原木的pillar_axis
- name : 字符串
- 返回值:状态的值
- 返回值类型:Rust
Result<String>,Go(string, error) - 对应槽位:
block_get_state,block_set_state -
示例:
- Rust
Rust - Go
含水方块是两个方块
泡在水里的台阶、栅栏,在游戏里是「台阶」加上一个「水」叠在一起。读到的是主方块;水在额外方块那一层。