Skip to content

src/place-blocks.ts

23 lines · 986 B · TypeScript
Raw
/**
 * Place blocks for a build. Writes stream in small batches (default 24 blocks
 * every 150 ms) so viewers watch the build appear live. Up to 600 blocks per
 * call; call again for bigger builds. Out-of-bounds or unknown materials are
 * skipped and counted in `rejected`.
 *
 * @param input - `{ buildId, blocks: [{ x, y, z, material }], batchSize?, delayMs? }`
 * @returns `{ buildId, placed, rejected, batches }`
 * @example
 * import placeBlocks from 'kody:@kentcdodds/world-builder/place-blocks'
 * await placeBlocks({ buildId, blocks: [{ x: 0, y: 0, z: 0, material: 'stone' }] })
 */
import { streamBuildOps } from './lib/agent.ts'

export default async function placeBlocks(input: {
	buildId: string
	blocks: Array<{ x: number; y: number; z: number; material: string }>
	batchSize?: number
	delayMs?: number
}) {
	const out = await streamBuildOps({ ...input, kind: 'put' })
	return { buildId: out.buildId, placed: out.placed, rejected: out.rejected, batches: out.batches }
}