Recovers the bot from the live-server symptoms reported 2026-05-26: 1) constant supervisor reconnects, 2) chop "clicks once and stops", 3) sleep does nothing without a bed and so blocks night-skipping for other players, 4) curriculum reflex always fell through to wander. Supervisor (#38): - runtime/watch-filter.js: pure predicate excluding *.test.js + the supervisor itself; recursive:true so skills/ + social/ edits also restart. Burned a working main once when test files counted toward the rollback threshold. - runtime/supervisor.js: watch-triggered restarts no longer count toward the crash-loop rollback path. Watcher is now recursive. Chop / mine (#39): - runtime/actions.js + runtime/skills/gather-stone.js: replaced raw pathfinder.goto + bot.dig with mineflayer-collectblock's bot.collectBlock.collect — handles approach, repositioning, LoS, dig and pickup as one primitive. Old version "swung once" because GoalGetToBlock often parked the bot in leaves above the log. Sleep + bed (#40): - runtime/actions.js: sleepInBed now ALSO places a carried bed on solid ground next to the bot and sleeps on it. Critical so the bot stops blocking player night-skipping the moment it owns a bed. Bed pipeline (#41): - runtime/skills/gather-wool.js: gather.wool skill — mines wool block if any nearby, otherwise shears or attacks the nearest sheep. - runtime/skills/craft.js: craftBedSkill (any colour the bot has ≥3 wool of, plus 3 planks, plus a table). - runtime/curriculum.js: new milestone survive.bed sits between wood.tools and stone.32 so the bot gets a bed BEFORE everything else. Test fixture updated to include a red_bed in post-survive.bed stages. Village / shelter / wheat (#42, #43): - runtime/skills/build-shelter.js: village.build-shelter — real 3×3×3 resumable hut blueprint around the recorded base, places one block per loop, idempotent so an interrupted build resumes correctly, marks each placed block in the owned-blocks ledger. - runtime/skills/deposit-surplus.js: village.deposit-surplus opens the nearest chest and transfers surplus stacks while keeping a reserve of tools/food/bed. - runtime/skills/farm-wheat.js: farm.wheat does one step per call (till adjacent-to-water grass, plant seeds, or harvest ripe wheat). - runtime/curriculum.js: village.shelter milestone after base-site. Scheduler glitch (root of "always wander"): - runtime/bot.js: curriculum + locations are now computed BEFORE runTick. Previously they were stamped AFTER, so reflex.js saw snapshot.curriculum=undefined every tick and fell through to the wander fallback. Verified live: scheduler now dispatches gather.logs/gather.stone/craft.* by id via runSkill. Eat-spam: - runtime/reflex.js: eatReflex now checks inventory for actual food and updates lastEatAt on EVERY dispatch (not only successes), so a failed eat respects the 5 s cooldown instead of firing every tick. npm test 123/123. Validated live on play.xmatic.team (curriculum dispatched gather.logs via runSkill, recover hint switched to wander when no log in range). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
137 lines
4.3 KiB
JavaScript
137 lines
4.3 KiB
JavaScript
// gather.stone — find a nearby stone/cobble/deepslate block, equip a
|
|
// pickaxe (best available), path to it and mine it. Stone-tier mining
|
|
// needs at least a wooden pickaxe — the preconditions enforce that.
|
|
|
|
import pathfinderPkg from "mineflayer-pathfinder";
|
|
const { pathfinder, goals, Movements } = pathfinderPkg;
|
|
import collectBlockPkg from "mineflayer-collectblock";
|
|
const collectBlockPlugin =
|
|
collectBlockPkg.plugin ??
|
|
collectBlockPkg.default?.plugin ??
|
|
collectBlockPkg.default ??
|
|
collectBlockPkg;
|
|
|
|
import { pickaxes } from "./groups.js";
|
|
import { info, warn } from "../log.js";
|
|
|
|
const STONE_NAMES = ["stone", "cobblestone", "deepslate", "cobbled_deepslate", "andesite", "diorite", "granite"];
|
|
|
|
let pluginLoaded = new WeakSet();
|
|
function ensurePathfinder(bot) {
|
|
if (pluginLoaded.has(bot)) return;
|
|
bot.loadPlugin(pathfinder);
|
|
pluginLoaded.add(bot);
|
|
}
|
|
|
|
let collectBlockLoaded = new WeakSet();
|
|
function ensureCollectBlock(bot) {
|
|
ensurePathfinder(bot);
|
|
if (collectBlockLoaded.has(bot)) return;
|
|
bot.loadPlugin(collectBlockPlugin);
|
|
collectBlockLoaded.add(bot);
|
|
}
|
|
|
|
function setMovementsForGather(bot) {
|
|
const m = new Movements(bot);
|
|
m.canDig = true;
|
|
m.allow1by1towers = false;
|
|
bot.pathfinder.setMovements(m);
|
|
}
|
|
|
|
const PICKAXE_PRIORITY = ["netherite_pickaxe", "diamond_pickaxe", "iron_pickaxe", "stone_pickaxe", "wooden_pickaxe"];
|
|
async function equipBestPickaxe(bot) {
|
|
for (const name of PICKAXE_PRIORITY) {
|
|
const item = bot.inventory.items().find((i) => i.name === name);
|
|
if (item) {
|
|
try {
|
|
await bot.equip(item, "hand");
|
|
return name;
|
|
} catch {}
|
|
}
|
|
}
|
|
return null;
|
|
}
|
|
|
|
function withTimeout(promise, ms, label) {
|
|
let timer;
|
|
const timeout = new Promise((_, reject) => {
|
|
timer = setTimeout(() => reject(new Error(`${label} timed out after ${ms / 1000}s`)), ms);
|
|
});
|
|
return Promise.race([promise, timeout]).finally(() => clearTimeout(timer));
|
|
}
|
|
|
|
const stoneBlacklist = new WeakMap();
|
|
const BLACKLIST_TTL_MS = 5 * 60_000;
|
|
|
|
function getBlacklist(bot) {
|
|
let m = stoneBlacklist.get(bot);
|
|
if (!m) {
|
|
m = new Map();
|
|
stoneBlacklist.set(bot, m);
|
|
}
|
|
const now = Date.now();
|
|
for (const [k, exp] of m) if (exp < now) m.delete(k);
|
|
return m;
|
|
}
|
|
|
|
export const skill = Object.freeze({
|
|
id: "gather.stone",
|
|
title: "Gather cobblestone",
|
|
timeoutMs: 90_000,
|
|
preconditions(ctx) {
|
|
if (!ctx?.bot) return { ok: false, code: "no_bot", detail: "bot missing" };
|
|
const available = pickaxes(ctx.bot);
|
|
if (available.size === 0) {
|
|
return { ok: false, code: "unsupported_version", detail: "no pickaxes in registry" };
|
|
}
|
|
const owned = ctx.bot.inventory.items().some((i) => available.has(i.name));
|
|
if (!owned) {
|
|
return { ok: false, code: "missing_tool", detail: "no pickaxe in inventory" };
|
|
}
|
|
return { ok: true };
|
|
},
|
|
async execute(ctx) {
|
|
const bot = ctx.bot;
|
|
const blacklist = getBlacklist(bot);
|
|
const target = bot.findBlock({
|
|
matching: (b) => {
|
|
if (!b || !b.position || !STONE_NAMES.includes(b.name)) return false;
|
|
const key = `${b.position.x},${b.position.y},${b.position.z}`;
|
|
return !blacklist.has(key);
|
|
},
|
|
maxDistance: 32,
|
|
});
|
|
if (!target) {
|
|
return { ok: false, code: "no_target", detail: "no reachable stone within 32 blocks", worldDelta: null };
|
|
}
|
|
|
|
ensureCollectBlock(bot);
|
|
setMovementsForGather(bot);
|
|
const pickaxe = await equipBestPickaxe(bot);
|
|
info("action", `gather.stone: ${target.name} at ${target.position.x},${target.position.y},${target.position.z} (tool=${pickaxe ?? "fists"})`);
|
|
try {
|
|
await withTimeout(bot.collectBlock.collect(target), 60_000, "collectStone");
|
|
return {
|
|
ok: true,
|
|
code: "done",
|
|
detail: { blockType: target.name, at: target.position },
|
|
worldDelta: { minedAt: target.position, blockType: target.name },
|
|
};
|
|
} catch (e) {
|
|
warn("action", `gather.stone failed: ${e.message}`);
|
|
const key = `${target.position.x},${target.position.y},${target.position.z}`;
|
|
blacklist.set(key, Date.now() + BLACKLIST_TTL_MS);
|
|
const msg = String(e?.message ?? "");
|
|
const code = msg.includes("timed out") ? "timeout" : "failed";
|
|
return { ok: false, code, detail: e.message, worldDelta: null };
|
|
}
|
|
},
|
|
validate(ctx, result) {
|
|
return result.ok && !!result.worldDelta?.blockType;
|
|
},
|
|
recover(ctx, result) {
|
|
if (result.code === "no_target") return { hint: "wander", reason: "no stone within 32 blocks" };
|
|
return null;
|
|
},
|
|
});
|