Skip to content

Zig: World

Functions

world.time

Zig
pub fn time() core.Error!i64

The world time in ticks.

  • Return type: core.Error!i64
  • Slots: get_time

world.setTime

Zig
pub fn setTime(t: i64) core.Error!void

Sets the world time natively.

  • Parameters:
    • t : i64
  • Return type: core.Error!void
  • Slots: set_time

world.setWeather

Zig
pub fn setWeather(weather: types.Weather) core.Error!void
  • Parameters:
    • weather : types.Weather
  • Return type: core.Error!void
  • Slots: set_weather

world.updateWeather

Zig
pub fn updateWeather(rain_level: f32, rain_ticks: i32, lightning_level: f32, lightning_ticks: i32) core.Error!void

Sets the level and the remaining duration, in ticks, of rain and of lightning.

  • Parameters:
    • rain_level : f32
    • rain_ticks : i32
    • lightning_level : f32
    • lightning_ticks : i32
  • Return type: core.Error!void
  • Slots: 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
  • Parameters:
    • d : types.Difficulty
  • Return type: core.Error!void
  • Slots: set_difficulty

world.seed

Zig
pub fn seed() core.Error!i64
  • Return type: core.Error!i64
  • Slots: get_seed

world.gameRule

Zig
pub fn gameRule(allocator: Allocator, name: []const u8) core.Error!GameRuleValue

Reads one game rule. An unrecognized rule name is NoAnswer and not some default value.

  • Parameters:
    • allocator : Allocator
    • name : []const u8
  • Return type: core.Error!GameRuleValue
  • Slots: game_rule_get

world.setGameRule

Zig
pub fn setGameRule(name: []const u8, value: []const u8) core.Error!void

Writes one game rule from its text form, such as "true" or "300".

  • Parameters:
    • name : []const u8
    • value : []const u8
  • Return type: core.Error!void
  • Slots: 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

Saves to disk immediately.

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

The biome name at one cell, owned by the caller.

  • Parameters:
    • allocator : Allocator
    • dim : i32
    • x : i32
    • y : i32
    • z : i32
  • Return type: core.Error![]u8
  • Slots: 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

Sets the biome of a region, column by column, and returns how many columns were set.

The corners are given in either order and no y is taken, since Bedrock stores biomes per column. A return of 0 means none were set.

  • Parameters:
    • dim : i32
    • from_x : i32
    • from_z : i32
    • to_x : i32
    • to_z : i32
    • biome_name : []const u8
  • Return type: core.Error!i32
  • Slots: level_set_biome

world.villages

Zig
pub fn villages(allocator: Allocator, dim: i32) core.Error!types.Owned(Village)

The villages in one dimension.

  • Parameters:
    • allocator : Allocator
    • dim : i32
  • Return type: core.Error!types.Owned(Village)
  • Slots: villages

world.structuresNear

Zig
pub fn structuresNear(allocator: Allocator, dim: i32, x: i32, y: i32, z: i32, radius: i32) core.Error!types.Owned(Structure)

The hardcoded generation areas in the loaded chunks within a radius.

  • Parameters:
    • allocator : Allocator
    • dim : i32
    • x : i32
    • y : i32
    • z : i32
    • radius : i32
  • Return type: core.Error!types.Owned(Structure)
  • Slots: 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

Whether every chunk covered by the region is in memory.

  • Parameters:
    • dim : i32
    • min_x : i32
    • min_z : i32
    • max_x : i32
    • max_z : i32
  • Return type: core.Error!bool
  • Slots: level_chunks_loaded

world.deleteChunkKeys

Zig
pub fn deleteChunkKeys(dim: i32, chunk_x: i32, chunk_z: i32) core.Error!i32

Deletes every save key of a chunk, so the engine regenerates it from the generator on its next load. Only an unloaded chunk can be restored this way. Returns how many keys went.

world.chunkKeys

Zig
pub fn chunkKeys(allocator: Allocator, dim: i32, chunk_x: i32, chunk_z: i32) core.Error![][]u8

Lists every save key of a chunk, each owned by the caller with the slice holding them.

  • Parameters:
    • allocator : Allocator
    • dim : i32
    • chunk_x : i32
    • chunk_z : i32
  • Return type: core.Error![][]u8
  • Slots: level_chunk_keys

world.deleteKey

Zig
pub fn deleteKey(key: []const u8) core.Error!void

Deletes one save key byte for byte. The content is not interpreted.

  • Parameters:
    • key : []const u8
  • Return type: core.Error!void
  • Slots: level_delete_key

world.findPath

Zig
pub fn findPath(allocator: Allocator, who: props.Entity, x: i32, y: i32, z: i32) core.Error![]u8

Computes a path for an actor to a target cell, as the host's SNBT {nodes, reached}. Every current host answers NotProvided: pathfinding is not implemented.

  • Parameters:
    • allocator : Allocator
    • who : props.Entity
    • x : i32
    • y : i32
    • z : i32
  • Return type: core.Error![]u8
  • Slots: level_find_path

world.getBlock

Zig
pub fn getBlock(allocator: Allocator, dim: i32, x: i32, y: i32, z: i32) core.Error!types.Owned(BlockInfo)

Reads one block. The name and the SNBT belong to the arena inside the result.

  • Parameters:
    • allocator : Allocator
    • dim : i32
    • x : i32
    • y : i32
    • z : i32
  • Return type: core.Error!types.Owned(BlockInfo)
  • Slots: get_block

world.setBlock

Zig
pub fn setBlock(dim: i32, x: i32, y: i32, z: i32, spec: []const u8) core.Error!void

Places a block natively with the default update flags. spec is a bare name such as "minecraft:stone", or full SNBT. An unknown name fails instead of placing a placeholder.

  • Parameters:
    • dim : i32
    • x : i32
    • y : i32
    • z : i32
    • spec : []const u8
  • Return type: core.Error!void
  • Slots: set_block

world.getExtraBlock

Zig
pub fn getExtraBlock(allocator: Allocator, dim: i32, x: i32, y: i32, z: i32) core.Error![]u8

Reads the liquid layer of a cell as a block name; an empty layer gives air.

  • Parameters:
    • allocator : Allocator
    • dim : i32
    • x : i32
    • y : i32
    • z : i32
  • Return type: core.Error![]u8
  • Slots: get_extra_block

world.setExtraBlock

Zig
pub fn setExtraBlock(dim: i32, x: i32, y: i32, z: i32, spec: []const u8, update: BlockUpdate) core.Error!void

Writes the liquid layer of a cell; write "minecraft:air" to clear it.

  • Parameters:
    • dim : i32
    • x : i32
    • y : i32
    • z : i32
    • spec : []const u8
    • update : BlockUpdate
  • Return type: core.Error!void
  • Slots: 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

Writes a block from serialized NBT, the shape getBlock produces.

  • Parameters:
    • dim : i32
    • x : i32
    • y : i32
    • z : i32
    • snbt : []const u8
    • update : BlockUpdate
  • Return type: core.Error!void
  • Slots: 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

Writes a block from a name and optional partial states. An empty states_snbt means every state at its default.

  • Parameters:
    • dim : i32
    • x : i32
    • y : i32
    • z : i32
    • name : []const u8
    • states_snbt : []const u8
    • update : BlockUpdate
  • Return type: core.Error!void
  • Slots: edit_set_block_states

world.setBlockEntity

Zig
pub fn setBlockEntity(dim: i32, x: i32, y: i32, z: i32, snbt: []const u8) core.Error!void

Writes a block entity's NBT back. The cell must already hold the matching block.

  • Parameters:
    • dim : i32
    • x : i32
    • y : i32
    • z : i32
    • snbt : []const u8
  • Return type: core.Error!void
  • Slots: edit_set_block_entity

world.scan

Zig
pub fn scan(allocator: Allocator, dim: i32, bounds: Bounds) core.Error!Scan

Scans a region and collects every block and actor into memory.

  • Parameters:
    • allocator : Allocator
    • dim : i32
    • bounds : Bounds
  • Return type: core.Error!Scan
  • Slots: scan_region

world.scanIndexed

Zig
pub fn scanIndexed(allocator: Allocator, dim: i32, bounds: Bounds) core.Error!IndexedScan

Scans the blocks of a region into a palette plus cells. Each distinct block state is serialized once, so a region of a million stone cells costs one SNBT and not a million.

  • Parameters:
    • allocator : Allocator
    • dim : i32
    • bounds : Bounds
  • Return type: core.Error!IndexedScan
  • Slots: scan_region_indexed

world.fillRegion

Zig
pub fn fillRegion(dim: i32, bounds: Bounds, spec: []const u8, update: BlockUpdate) core.Error!u64

Fills a box with one block and returns how many cells were written. spec is a bare name or full SNBT, resolved once for the whole box.

  • Parameters:
    • dim : i32
    • bounds : Bounds
    • spec : []const u8
    • update : BlockUpdate
  • Return type: core.Error!u64
  • Slots: 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

Writes many cells in one call and returns how many were written. Each entry of palette is a block spec resolved once; a cell whose index is out of range, or whose block did not resolve, is skipped.

  • Parameters:
    • allocator : Allocator
    • dim : i32
    • palette : []const []const u8
    • cells : []const BlockCell
    • update : BlockUpdate
  • Return type: core.Error!u64
  • Slots: 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

Spawns a mob and returns it.

  • Parameters:
    • dim : i32
    • type_name : []const u8
    • x : f64
    • y : f64
    • z : f64
  • Return type: core.Error!props.Entity
  • Slots: spawn_mob

world.spawnEntityNbt

Zig
pub fn spawnEntityNbt(dim: i32, snbt: []const u8, pos: ?types.Vec3) core.Error!props.Entity

Spawns an actor from full NBT, the inverse of Entity.snapshot. A pos overrides the Pos tag. Every current host answers NotProvided: the engine helper that gives a loaded actor a fresh unique id is not reachable.

  • Parameters:
    • dim : i32
    • snbt : []const u8
    • pos : ?types.Vec3
  • Return type: core.Error!props.Entity
  • Slots: edit_spawn_entity_nbt

world.explode

Zig
pub fn explode(dim: i32, x: f64, y: f64, z: f64, options: ExplodeOptions) core.Error!void

Detonates at a point.

  • Parameters:
    • dim : i32
    • x : f64
    • y : f64
    • z : f64
    • options : ExplodeOptions
  • Return type: core.Error!void
  • Slots: explode

world.spawnParticle

Zig
pub fn spawnParticle(dim: i32, effect: []const u8, x: f64, y: f64, z: f64) core.Error!void

A particle visible across the whole dimension. Showing it to one person only uses spawnParticleFor.

  • Parameters:
    • dim : i32
    • effect : []const u8
    • x : f64
    • y : f64
    • z : f64
  • Return type: core.Error!void
  • Slots: 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

A particle shown to one player.

  • Parameters:
    • player : props.Player
    • dim : i32
    • effect : []const u8
    • x : f64
    • y : f64
    • z : f64
  • Return type: core.Error!void
  • Slots: spawn_particle_for

world.playerPosition

Zig
pub fn playerPosition(name: []const u8) core.Error!types.PlayerPosition

Looks up the feet position and dimension of a connected player by name.

  • Parameters:
    • name : []const u8
  • Return type: core.Error!types.PlayerPosition
  • Slots: get_player_position

world.weatherValue

Zig
pub fn weatherValue(dim: i32, prop: i32) core.Error!f64

One weather value of a dimension by its PIER_WPROP_* key.

  • Parameters:
    • dim : i32
    • prop : i32
  • Return type: core.Error!f64
  • Slots: world_get_num

world.rainLevel

Zig
pub fn rainLevel(dim: i32) core.Error!f64

The rain level of a dimension, 0 for none to 1 for full rain.

  • Parameters:
    • dim : i32
  • Return type: core.Error!f64
  • Slots: world_get_num

world.targetRainLevel

Zig
pub fn targetRainLevel(dim: i32) core.Error!f64
  • Parameters:
    • dim : i32
  • Return type: core.Error!f64
  • Slots: world_get_num

world.lightningLevel

Zig
pub fn lightningLevel(dim: i32) core.Error!f64

The lightning level of a dimension, 0 for none to 1 for a storm.

  • Parameters:
    • dim : i32
  • Return type: core.Error!f64
  • Slots: world_get_num

world.targetLightningLevel

Zig
pub fn targetLightningLevel(dim: i32) core.Error!f64
  • Parameters:
    • dim : i32
  • Return type: core.Error!f64
  • Slots: world_get_num

world.fogLevel

Zig
pub fn fogLevel(dim: i32) core.Error!f64
  • Parameters:
    • dim : i32
  • Return type: core.Error!f64
  • Slots: world_get_num

world.skyFlashTime

Zig
pub fn skyFlashTime(dim: i32) core.Error!f64
  • Parameters:
    • dim : i32
  • Return type: core.Error!f64
  • Slots: world_get_num

Declarations

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
1
2
3
4
5
6
pub const Scan = struct {
    arena: std.heap.ArenaAllocator,
    blocks: []const BlockInfo,
    entities: []const EntityInfo,
    // ...
};

The result of one scan: every block of the region and every actor inside it.

world.Scan.deinit

Zig
pub fn deinit(self: *Scan) void
  • Return type: void

world.Scan.nonAirCount

Zig
pub fn nonAirCount(self: *const Scan) usize

Cells that are not air, by block name.

  • Return type: usize

world.IndexedScan

Zig
1
2
3
4
5
6
pub const IndexedScan = struct {
    arena: std.heap.ArenaAllocator,
    palette: []const PaletteEntry,
    cells: []const BlockCell,
    // ...
};

The result of one scanIndexed: every distinct block state once, and one cell for each position holding an index into the palette.

world.IndexedScan.deinit

Zig
pub fn deinit(self: *IndexedScan) void
  • Return type: void

world.IndexedScan.blockOf

Zig
pub fn blockOf(self: *const IndexedScan, cell: BlockCell) ?PaletteEntry

The palette entry of a cell, or null for an index the palette does not have.

  • Parameters:
    • cell : BlockCell
  • Return type: ?PaletteEntry

world.GameRuleValue

Zig
1
2
3
4
5
6
pub const GameRuleValue = union(enum) {
    boolean: bool,
    int: i64,
    float: f64,
    // ...
};

The value of one game rule.

world.SleepStatus

Zig
1
2
3
4
5
6
pub const SleepStatus = struct {
    sleeping: bool,
    total_players: i32,
    active_sleeping: i32,
    // ...
};

The sleep status of the players.

world.Village

Zig
1
2
3
4
5
6
7
pub const Village = struct {
    uuid: []const u8,
    center: Pos3,
    bounds: Bounds,
    poi_count: i32,
    // ...
};

One village.

world.Structure

Zig
1
2
3
4
5
pub const Structure = struct {
    kind: []const u8,
    bounds: Bounds,
    // ...
};

One hardcoded generation area: a stronghold, a witch hut, an ocean monument or a similar structure.

world.BlockInfo

Zig
1
2
3
4
5
6
7
8
pub const BlockInfo = struct {
    x: i32,
    y: i32,
    z: i32,
    name: []const u8,
    snbt: []const u8,
    // ...
};

One block as the host reports it.

world.EntityInfo

Zig
1
2
3
4
5
6
7
8
pub const EntityInfo = struct {
    x: i32,
    y: i32,
    z: i32,
    type_name: []const u8,
    snbt: []const u8,
    // ...
};

One actor that fell inside the region during a scan.

world.PaletteEntry

Zig
1
2
3
4
5
pub const PaletteEntry = struct {
    name: []const u8,
    snbt: []const u8,
    // ...
};

One distinct block state met by scanIndexed.

world.BlockCell

Zig
1
2
3
4
5
6
7
pub const BlockCell = extern struct {
    x: i32,
    y: i32,
    z: i32,
    index: u32,
    // ...
};

One cell of scanIndexed or setBlocks: a position and an index into a palette.

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,
    // ...
};

What an explosion does and who caused it.