Incremental world mutation
This example spreads pyramid construction across game ticks. The generator yields after each block, and system.runJob advances it until completion.
Create config/questscript/scripts/pyramid.js:
// @ts-check
world.sendMessage("Build pyramid script");
const overworld = world.getDimension("overworld");
function* buildPyramid() {
const center = [204, 64, -332];
const size = 7;
world.sendMessage(`Building pyramid at ${center} with size ${size}`);
const blocks = getPyramidBlockCoordinates(center, size);
for (const [x, y, z] of blocks) {
yield system.waitTicks(1);
overworld.setBlockType({ x, y, z }, "minecraft:gold_block");
}
world.sendMessage("Pyramid built");
}
/**
* @param {number[]} center
* @param {number} size
* @returns {[number, number, number][]}
*/
function getPyramidBlockCoordinates(center, size) {
/** @type {[number, number, number][]} */
const coordinates = [];
const [cx, cy, cz] = center;
let currentSize = size;
let layerY = 0;
while (currentSize > 0) {
const halfSize = Math.floor(currentSize / 2);
for (let x = -halfSize; x < halfSize + (currentSize % 2); x++) {
for (let z = -halfSize; z < halfSize + (currentSize % 2); z++) {
coordinates.push([cx + x, cy + layerY, cz + z]);
}
}
currentSize -= 2;
layerY += 1;
}
return coordinates;
}
system.runJob(buildPyramid());
Load it with /qs load pyramid.js. The setBlockType call uses the public { x, y, z } shape; the tuple remains only a local JavaScript data structure.
Large volumes still need a server-cost budget: incremental execution spreads work across ticks, but does not remove the cost of the world mutations themselves.