fix(perception): use numeric block ids — callback matchers silently fail under ViaBackwards
Root cause of "bot just stands still": every gather.* skill was using
bot.findBlock({ matching: (b) => names.includes(b.name) }), and under
mineflayer 1.21.4 + ViaBackwards the Block objects fed into the
callback have a wrong .name field (Block.type / numeric id is still
correct — this is mineflayer issue #2347). Every search returned null,
every skill reported "no_target", reflex looped wander → tunnel-out
forever. The bot's logs said "dispatch ok" while the operator watched
it pace in circles.
Proven live with a new diag.match skill on play.xmatic.team:
findBlocks({matching: numericIds}) → 50 hits
findBlocks({matching: (b) => b.name === ...}) → 0 hits ← the bug
findBlock({matching: (b) => b.name === ...}) → null ← the bug
findBlock({matching: numericIds}) → dark_oak_log @ (606,62,110)
After this fix the same bot from the same spawn dispatches gather.logs
and reaches the chop loop ("chop: dark_oak_log at 606,62,110 (tool=fists)")
instead of returning "no reachable log within 64 blocks".
Changes:
- runtime/perception.js (new): findBlocksByName / findNearestBlockByName
centralise the numeric-id workaround for any future skill.
- runtime/actions.js: chopNearestTree, sleepInBed, placeCraftingTable now
use perception. Also load mineflayer-tool plugin alongside collectblock
(collectblock 1.6 hard-requires bot.tool to dispatch a dig).
- gather-stone, gather-wool, deposit-surplus rewritten to numeric-id
search. gather-wool also loads mineflayer-tool.
- diagnose-scan.js (new): two diagnostic skills — diag.scan reports
findBlocks counts per radius for common blocks; diag.match cross-tests
the four matcher styles so this regression can be re-proven on demand.
- runtime/skills/index.js: registers diag.scan + diag.match.
Memory: project_findblock_callback_broken_under_viabackwards.md.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -9,10 +9,18 @@
|
||||
|
||||
import collectBlockPkg from "mineflayer-collectblock";
|
||||
import pathfinderPkg from "mineflayer-pathfinder";
|
||||
import toolPkg from "mineflayer-tool";
|
||||
const toolPlugin = toolPkg.plugin ?? toolPkg.default?.plugin ?? toolPkg.default ?? toolPkg;
|
||||
|
||||
import { info, warn } from "../log.js";
|
||||
import { findNearestBlockByName } from "../perception.js";
|
||||
|
||||
const { pathfinder, goals, Movements } = pathfinderPkg;
|
||||
const WOOL_NAMES = [
|
||||
"white_wool", "orange_wool", "magenta_wool", "light_blue_wool", "yellow_wool",
|
||||
"lime_wool", "pink_wool", "gray_wool", "light_gray_wool", "cyan_wool",
|
||||
"purple_wool", "blue_wool", "brown_wool", "green_wool", "red_wool", "black_wool",
|
||||
];
|
||||
const collectBlockPlugin =
|
||||
collectBlockPkg.plugin ??
|
||||
collectBlockPkg.default?.plugin ??
|
||||
@@ -25,6 +33,7 @@ let pluginLoaded = new WeakSet();
|
||||
function ensurePlugins(bot) {
|
||||
if (pluginLoaded.has(bot)) return;
|
||||
bot.loadPlugin(pathfinder);
|
||||
bot.loadPlugin(toolPlugin); // collectblock needs bot.tool
|
||||
bot.loadPlugin(collectBlockPlugin);
|
||||
pluginLoaded.add(bot);
|
||||
}
|
||||
@@ -77,11 +86,8 @@ export const skill = Object.freeze({
|
||||
ensurePlugins(bot);
|
||||
setMovementsForGather(bot);
|
||||
|
||||
// 1. Placed wool block?
|
||||
const woolBlock = bot.findBlock({
|
||||
matching: (b) => b?.name && (b.name.endsWith("_wool") || b.name === "wool"),
|
||||
maxDistance: 32,
|
||||
});
|
||||
// 1. Placed wool block? Numeric-id search — see runtime/perception.js.
|
||||
const woolBlock = findNearestBlockByName(bot, WOOL_NAMES, { maxDistance: 32 });
|
||||
if (woolBlock) {
|
||||
info("action", `gather.wool: mining ${woolBlock.name} at ${woolBlock.position}`);
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user