Guide 1 Docs 2 Reference 3
40

world global · type World

A room's blocks, entities, displays, screens and time: the world global, or room.world.

Docs: World

Functions 39

world.on_generate(fn: (chunk: Chunk) -> ())

Called for a chunk each time it comes into memory, in a script world; it must make the same blocks every time.

world.on_populate(fn: (chunk: Chunk) -> ())

Each chunk the overworld terrain made, once, after it made it.

world.dimension(name: string) → World

Another world of the server's group, by dimension id or its last part ("dungeon", "minecraft:the_nether"): that world's own world table.

world.drop(pos: Vec3, item: ItemSpec)

A stack on the ground at a block, as a broken block leaves one.

world.container(pos: Vec3) → Container?

A chest's stacks, or nil where the block keeps none.

world.rules(opts: { survival: boolean?, fall: boolean?, damage: boolean?, hunger: boolean?, anticheat: boolean?, day_cycle: boolean?, redstone: boolean? }?) → Rules

world.rules{ fall = true } switches one on, false off; a rule left out or nil keeps its value, and a number or a string is an error. world.rules() reads them.

world.raycast(from: Vec3, direction: Vec3, max: number?) → RayHit?

The first block a ray from from along direction meets within max blocks, and the face it came in through; nil for none.

world.sees(from: Vec3, to: Vec3) → boolean

True when no block stops the line from from to to: a block with a collision box does (glass, leaves), water and grass do not.

world.raycasts(rays: buffer, out: buffer, n: number)

n lines at once. rays holds six f64 a line (from x, y, z, to x, y, z); out gets one f64 a line: how far along it the first block is that stops it, or -1 for a clear line.

world.light_at(pos: Vec3) → (number, number, boolean)

Block light and sky light, 0 to 15, and whether nothing above holds off the sky.

world.path(from: Vec3, to: Vec3, opts: { size: (number | { number })?, swim: boolean?, fall: number?, range: number?, budget: number? }?) → { Vec3 }?

The points a body walks from from to the block at to, or nil. The game's own search: a step up of one block, falls of fall (3). size is { width, height } (0.6, 1.8); swim goes through water; range (the distance + 16) and budget (2000 nodes) stop a long search, which then gives the part that came closest.

world.zone(opts: { from: Vec3, to: Vec3, on_enter: ((player: Player) -> ())?, on_leave: ((player: Player) -> ())? }) → Zone

Makes a box of blocks, both corners included, that knows who is in it; checked once a tick by feet position. Ends with the script.

world.set_block(pos: Vec3, block: BlockRef, opts: { skin: HeadSkin? }?)

skin is for "player_head" and "player_wall_head" only: an account's name, or the raw textures property.

world.set_blocks(changes: { { at: Vec3, block: BlockRef, skin: HeadSkin? } })

Sets many blocks at once, live, stored and sent; the cheapest way. A row takes skin too, for a player head.

world.fill(from: Vec3, to: Vec3, block: BlockRef)

Fills a box of blocks between two corners, live, stored and sent to everyone.

world.schematic(file: string) → Schematic

A file inside the pack; a path that leaves it, or one that is not there, is an error naming the file.

world.build(fn: (b: Builder) -> (), opts: { detail: number? }?) → Schematic

The same value, written in code instead of read from a file. { detail = 2 }: coordinates are half blocks, fitted to slabs and stairs.

world.paste(schem: Schematic, origin: Vec3, opts: { air: boolean?, part: string? }?)

Live, stored and sent; air is skipped unless air is true.

world.get_block(pos: Vec3) → string?

nil where that chunk is not in memory: a read never generates.

world.block(pos: Vec3) → BlockAt?

The block there as the handle a hook gets: reads are live, and what it does lands on the next tick. state and data are for this pack's own blocks. nil where that chunk is not in memory.

world.get_biome(pos: Vec3) → string?

Returns the biome name of the column at pos; nil where that chunk is not in memory.

world.generate(rules: GeneratorRules) → Generated

Declares this world: the engine makes each chunk from the rules, on every core, and no script runs for a chunk.

world.get_blocks(from: Vec3, to: Vec3) → { string? }

A box, in x, then z, then y order.

world.items() → { GroundItem }

The stacks on the ground: { id, item, count, at } rows.

world.spawn(def: EntityDef | string, pos: Vec3, data: { [string]: any }?) → EntityHandle?

Puts an entity at a point and returns its handle. A mob kind of the game by name (world.spawn("cow", pos)) is the game's own entity, and takes no data. A pack's own kind takes the data it starts life holding. nil for a kind nothing defined and this game does not have.

world.entities(query: { near: Vec3?, radius: number?, kind: string?, mob: boolean? }?) → { EntityHandle }

Live and queued entities, in ascending id. Optional near/radius select a sphere; kind filters by canonical name. near and radius go together. mob = true gives the mobs only, mob = false the rest.

world.explode(pos: Vec3, power: number?)

A blast at a point. The power is clamped by this game's own column and the tick's explosion budget decides when it goes off, never whether.

world.on_block_break(fn: (player: Player?, pos: Vec3, block: string) -> ()) → Connection

What the survival tick did. Observe-only: the world has already changed, and what the callback returns is not read.

world.on_block_place(fn: (player: Player?, pos: Vec3, block: string) -> ()) → Connection

Tells after a block was placed, with its canonical name. Observe-only; player is nil when nobody placed it or they left.

world.on_entity_spawn(fn: (entity: EntityHandle, name: string) -> ()) → Connection

Tells after a mob appeared, with its handle and name; a natural spawn fires it on every game version that has one, and a pack's own world.spawn("cow", pos) fires it too. Mob kinds only.

world.on_entity_death(fn: (id: number, name: string) -> ()) → Connection

Tells after a mob died; it is gone, so its id and name is all there is. Mob kinds only.

world.time((at: number | TimeName | (s: number) -> number | TimeName) -> ()) → & (() -> number)

Holds the sky at a time (ticks, or "sunrise", "day", "noon", "sunset", "night", "midnight"), or asks a function each tick, s seconds after the call. With no argument: the time of day now, 0 to 23999.

world.light(sources: { LightSource })

Sends players light no block makes, 1 to 15 a source; each call replaces the last, {} ends it. 1.14 and later.

world.screen(opts: { at: Vec3, facing: Facing | "up", up: Facing?, width: number?, height: number?, glow: boolean?, on_click: ((player: Player, x: number, y: number, button: "left" | "right") -> ())?, }) → Screen

Puts a wall of map frames, width by height frames (128 pixels each), in front of a wall; at is the top-left frame. Returns a Screen.

world.canvas(opts: { width: number?, height: number? }?) → Canvas

Makes a picture of width by height maps (1 by 1 by default, 16 at most a side) with no frame of its own, for a frame, a hand or a screen.

world.display((opts: { kind: "model", model: Model, at: Vec3?, rotation: Orientation?, scale: (number | Vec3)?, -- models require equal positive axes paint: { [string]: Ink }?, fallback: string?, seats: { Vec3 }?, lead: boolean?, }) -> ModelDisplay) → & ((opts: { kind: "item" | "text" | "block" | "frame", at: Vec3?, rotation: Orientation?, scale: (Vec3 | number)?, billboard: Billboard?, glow: (Ink | false)?, item: ItemSpec?, canvas: Canvas?, context: Context?, text: Text?, color: Ink?, background: (Ink | false)?, line_width: number?, shadow: boolean?, block: string?, facing: ScreenFacing?, invisible: boolean?, glide: number?, lead: boolean?, }) -> Display)

A model stands in the world through the same call as everything else, and is the one kind that hands back something other than a Display.

world.hitbox(opts: { at: Vec3, width: number?, height: number?, depth: number?, solid: boolean?, on_click: ((player: Player, button: "left" | "right") -> ())?, }) → Hitbox

Makes an invisible box a player can click; solid also makes it a wall. depth is the width unless given. 1.19.4 and later.

world.npc(opts: { name: string?, at: Vec3?, rotation: BodyRotation?, skin: (string | { value: string, signature: string } | false)?, }) → Npc

Places a player-shaped entity every client from 1.8 sees; removed when the script ends or reloads.

world.puppet(opts: { kind: string, at: Vec3?, rotation: BodyRotation?, name: Text? }) → Puppet

Places a mob's body with no mind of its own that the script moves; its name tag always shows. An error when this game has no such mob kind.

Fields 1

world.spawn_point: Vec3

Where players arrive in this room; writable. The same value as the room's spawn_point.