fix(runtime): unstick scheduler + chop + sleep + bed/shelter/farm skills
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>
This commit is contained in:
+69
-15
@@ -5,6 +5,12 @@
|
||||
|
||||
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 { info, warn } from "./log.js";
|
||||
|
||||
@@ -29,6 +35,19 @@ function ensurePathfinder(bot) {
|
||||
pluginLoaded.add(bot);
|
||||
}
|
||||
|
||||
// collectblock handles the full "find → approach → reposition → dig →
|
||||
// pickup" cycle which raw bot.dig + pathfinder.goto does not. The old
|
||||
// chop primitive "clicked once and stopped" because bot.dig requires a
|
||||
// stable LoS that GoalGetToBlock doesn't always satisfy — bot ended up
|
||||
// in leaves above the log and swung once with no progress.
|
||||
let collectBlockLoaded = new WeakSet();
|
||||
function ensureCollectBlock(bot) {
|
||||
ensurePathfinder(bot);
|
||||
if (collectBlockLoaded.has(bot)) return;
|
||||
bot.loadPlugin(collectBlockPlugin);
|
||||
collectBlockLoaded.add(bot);
|
||||
}
|
||||
|
||||
// Each action that uses pathfinder should set its own Movements profile
|
||||
// before calling goto — otherwise it inherits whatever the previous caller
|
||||
// left set, which has caused live regressions (e.g. flee setting canDig=false,
|
||||
@@ -203,11 +222,18 @@ const BED_NAMES = [
|
||||
"black_bed",
|
||||
];
|
||||
|
||||
function carriedBedItem(bot) {
|
||||
for (const item of bot.inventory.items()) {
|
||||
if (BED_NAMES.includes(item.name)) return item;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
export async function sleepInBed(bot) {
|
||||
// Already in a bed?
|
||||
if (bot.isSleeping) return { ok: true, detail: "already sleeping" };
|
||||
|
||||
// Find a nearby placed bed first.
|
||||
// 1. Find a nearby placed bed first.
|
||||
const bedBlock = bot.findBlock({
|
||||
matching: (b) => BED_NAMES.includes(b?.name),
|
||||
maxDistance: 16,
|
||||
@@ -231,10 +257,46 @@ export async function sleepInBed(bot) {
|
||||
}
|
||||
}
|
||||
|
||||
// No placed bed — try placing one if we carry one. Skip — we don't want to
|
||||
// invent a base location accidentally. Future: only place when at our base
|
||||
// per locations.json.
|
||||
return { ok: false, detail: "no bed in range and won't place blindly" };
|
||||
// 2. No placed bed — if we're carrying one, place it right next to us
|
||||
// and sleep on it. This is critical so the bot stops blocking player
|
||||
// night-skipping the moment it owns a bed. We pick a footing block at
|
||||
// the bot's feet level + 1 in the +X direction.
|
||||
const carried = carriedBedItem(bot);
|
||||
if (carried) {
|
||||
const here = bot.entity.position;
|
||||
const referenceBlock = bot.blockAt(here.offset(1, -1, 0));
|
||||
const targetSlot = bot.blockAt(here.offset(1, 0, 0));
|
||||
if (!referenceBlock || !referenceBlock.boundingBox || referenceBlock.boundingBox === "empty") {
|
||||
return { ok: false, detail: "no solid ground to place bed on" };
|
||||
}
|
||||
if (targetSlot && targetSlot.boundingBox && targetSlot.boundingBox !== "empty") {
|
||||
return { ok: false, detail: "no space to place bed" };
|
||||
}
|
||||
try {
|
||||
await withTimeout(bot.equip(carried, "hand"), 3000, "equip bed");
|
||||
await withTimeout(
|
||||
bot.placeBlock(referenceBlock, { x: 0, y: 1, z: 0 }),
|
||||
5000,
|
||||
"placeBlock(bed)",
|
||||
);
|
||||
info("action", `sleep: placed ${carried.name} at ${referenceBlock.position.x + 0},${referenceBlock.position.y + 1},${referenceBlock.position.z + 0}`);
|
||||
// Re-scan for the placed bed (its block name may differ from the
|
||||
// item name slightly, e.g. on some servers, and the placement may
|
||||
// have shifted to an adjacent slot for the bed's second half).
|
||||
const placed = bot.findBlock({
|
||||
matching: (b) => BED_NAMES.includes(b?.name),
|
||||
maxDistance: 4,
|
||||
});
|
||||
if (!placed) return { ok: false, detail: "placed bed not found after placement" };
|
||||
await withTimeout(bot.sleep(placed), 10_000, "bot.sleep(placed)");
|
||||
return { ok: true, detail: { bedAt: placed.position, placed: true, name: carried.name } };
|
||||
} catch (e) {
|
||||
warn("action", `sleep place+sleep failed: ${e.message}`);
|
||||
return { ok: false, detail: e.message };
|
||||
}
|
||||
}
|
||||
|
||||
return { ok: false, detail: "no bed in inventory or nearby" };
|
||||
}
|
||||
|
||||
// ---- gathering -------------------------------------------------------------
|
||||
@@ -306,7 +368,7 @@ export async function chopNearestTree(bot) {
|
||||
});
|
||||
if (!log) return { ok: false, detail: "no reachable log within 32 blocks" };
|
||||
|
||||
ensurePathfinder(bot);
|
||||
ensureCollectBlock(bot);
|
||||
setMovementsForGather(bot);
|
||||
const axe = await equipBestAxe(bot);
|
||||
info(
|
||||
@@ -314,15 +376,7 @@ export async function chopNearestTree(bot) {
|
||||
`chop: ${log.name} at ${log.position.x},${log.position.y},${log.position.z} (tool=${axe ?? "fists"})`,
|
||||
);
|
||||
try {
|
||||
await withTimeout(
|
||||
bot.pathfinder.goto(new goals.GoalGetToBlock(log.position.x, log.position.y, log.position.z)),
|
||||
45_000,
|
||||
"pathToLog",
|
||||
);
|
||||
await withTimeout(bot.dig(log), 30_000, "digLog");
|
||||
// Walk over the dropped item briefly (collectblock plugin would do this
|
||||
// for us, but a simple sleep-then-resume is enough for now).
|
||||
await new Promise((r) => setTimeout(r, 1200));
|
||||
await withTimeout(bot.collectBlock.collect(log), 60_000, "collectLog");
|
||||
return { ok: true, detail: { logType: log.name, at: log.position } };
|
||||
} catch (e) {
|
||||
warn("action", `chop failed: ${e.message}`);
|
||||
|
||||
Reference in New Issue
Block a user