SoulFire LogoSoulFire
SDKRecipes

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.

collect-blocks.ts
import { Effect, Stream } 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.start();
    yield* bot.waitForOnline();

    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. The idempotency key prevents a duplicate task when the start request is retried.

How is this page?

Last updated on