SDKRecipes
Follow an entity
Start a durable follow task using the entity under the bot's cursor.
Point the bot at an entity within five blocks before running this program. It reads an entity reference that includes the connection epoch, so SoulFire can reject it if the bot reconnects and a network ID is reused.
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 target = yield* bot.world.entityAtCursor(5);
if (!target?.reference) throw new Error("Point the bot at an entity first");
const task = yield* bot.tasks.followEntity(target.reference, 3);
console.log("Follow task ID:", task.id);
}),
);
await Effect.runPromise(program);The server owns the follow task after it starts. Use task controls to watch it, stop it, or reconnect to it by ID.
How is this page?
Last updated on
