Collect blocks
Start a durable block collection task and read its result.
This program collects up to 16 oak logs near the bot. The task runs on the SoulFire server. Save task.id if another process needs to find it later.
import { Effect } from "effect";
import { SoulFire } from "@soulfiremc/sdk";
function env(name: string): string {
const value = process.env[name];
if (!value) throw new Error(`Set ${name} before running this recipe`);
return value;
}
const program = Effect.scoped(
Effect.gen(function* () {
const soulfire = yield* SoulFire.connect({
baseUrl: env("SOULFIRE_URL"),
token: env("SOULFIRE_TOKEN"),
});
const bot = soulfire
.instance(env("SOULFIRE_INSTANCE_ID"))
.bot(env("SOULFIRE_BOT_ID"));
yield* bot.connect();
const task = yield* bot.tasks.collectBlocks(["minecraft:oak_log"], {
count: 16,
searchRadius: 32,
idempotencyKey: crypto.randomUUID(),
});
console.log("Task ID:", task.id);
const result = yield* task.result();
console.log(result);
}),
);
await Effect.runPromise(program);The bot needs loaded chunks and suitable tools. If the task cannot reach every block, inspect its result and task progress. Reuse the same idempotency key when retrying an uncertain start request to prevent a duplicate task.
Collect without a task handle
For a finite job, use the convenience method inside your workflow:
const result = yield* bot.collect("#logs", { count: 16, searchRadius: 32 });result = yield from bot.collect("#logs", count=16, search_radius=32)collect waits for the result and cancels unfinished work on interruption.
Use tasks.collectBlocks / tasks.collect_blocks when you need a durable task ID for progress or later reattachment.
How is this page?
Last updated on
