fix: mineBlock must reach a layer that is ABOVE the bot (measured: gold at y=52, bot stuck at y=51)
Browse files- voyager_stack.py +59 -5
voyager_stack.py
CHANGED
|
@@ -353,7 +353,7 @@ class VoyagerStack:
|
|
| 353 |
maxDistance: 32,
|
| 354 |
});
|
| 355 |
|
| 356 |
-
// Walk
|
| 357 |
// descent policy in exploreUntil: dig the block underfoot, settle, repeat.
|
| 358 |
// Never asks the pathfinder for a lower goal, which is what used to make it
|
| 359 |
// drive itself off a ledge.
|
|
@@ -377,13 +377,68 @@ class VoyagerStack:
|
|
| 377 |
return false;
|
| 378 |
};
|
| 379 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 380 |
while (mined < wanted) {
|
| 381 |
let block = findTarget(searchFloorY);
|
| 382 |
|
| 383 |
if (!block) {
|
| 384 |
// Nothing inside the dig budget at this X/Z. If the target is ores
|
| 385 |
-
// this map stacks as a layer, walk
|
| 386 |
-
// continuous, so a straight
|
| 387 |
// the block genuinely is not here and the model must travel.
|
| 388 |
const probe = bot.findBlock({
|
| 389 |
matching: (candidate) => Boolean(candidate) &&
|
|
@@ -395,8 +450,7 @@ class VoyagerStack:
|
|
| 395 |
});
|
| 396 |
const knownOre = /(^|_)ore$/.test(name);
|
| 397 |
if (probe && knownOre) {
|
| 398 |
-
|
| 399 |
-
block = reached ? findTarget(searchFloorY) : null;
|
| 400 |
}
|
| 401 |
}
|
| 402 |
|
|
|
|
| 353 |
maxDistance: 32,
|
| 354 |
});
|
| 355 |
|
| 356 |
+
// Walk a staircase the bot can always climb back out of. Mirrors the
|
| 357 |
// descent policy in exploreUntil: dig the block underfoot, settle, repeat.
|
| 358 |
// Never asks the pathfinder for a lower goal, which is what used to make it
|
| 359 |
// drive itself off a ledge.
|
|
|
|
| 377 |
return false;
|
| 378 |
};
|
| 379 |
|
| 380 |
+
// The bot can end up ABOVE the layer it is looking for -- it dug down
|
| 381 |
+
// looking for gold, passed through y=52-53 and stalled at y=51 inside the
|
| 382 |
+
// iron band, with the gold now 1-2 blocks over its head. descendToward()
|
| 383 |
+
// returns true immediately in that case (pos.y <= targetY is already true),
|
| 384 |
+
// so the caller searched again, found nothing new, and threw the same error
|
| 385 |
+
// on every cycle while the observation kept listing gold_ore as nearby.
|
| 386 |
+
//
|
| 387 |
+
// When the target layer is above the bot, mine the block overhead and step
|
| 388 |
+
// up, which is the mirror of the descent and works in a layered world where
|
| 389 |
+
// the column is solid all the way to the surface.
|
| 390 |
+
const ascendToward = async (targetY) => {
|
| 391 |
+
let steps = 0;
|
| 392 |
+
while (steps < MAX_DIG_DEPTH) {
|
| 393 |
+
const pos = bot.entity.position;
|
| 394 |
+
if (Math.floor(pos.y) >= targetY) return true;
|
| 395 |
+
const above = bot.entity.blockAt(bot.entity.position.offset(0, 2, 0));
|
| 396 |
+
if (!above) return false;
|
| 397 |
+
if (above.boundingBox !== "empty" && above.name !== "bedrock") {
|
| 398 |
+
try {
|
| 399 |
+
// Stand still and dig straight up; the block falls into the
|
| 400 |
+
// space, then the bot steps up into it.
|
| 401 |
+
await bot.dig(above, true);
|
| 402 |
+
} catch (_) {
|
| 403 |
+
return false;
|
| 404 |
+
}
|
| 405 |
+
}
|
| 406 |
+
await bot.waitForTicks(3);
|
| 407 |
+
try {
|
| 408 |
+
await bot.pathfinder.goto(new GoalBlock(
|
| 409 |
+
Math.floor(pos.x), Math.floor(pos.y) + 1, Math.floor(pos.z)
|
| 410 |
+
));
|
| 411 |
+
} catch (_) {
|
| 412 |
+
return false;
|
| 413 |
+
}
|
| 414 |
+
steps++;
|
| 415 |
+
}
|
| 416 |
+
return false;
|
| 417 |
+
};
|
| 418 |
+
|
| 419 |
+
// Reach a target layer that is either above or below the bot, then hand
|
| 420 |
+
// back a fresh search. Returns null when the layer cannot be reached, so
|
| 421 |
+
// the caller still reports a real "not here" instead of looping.
|
| 422 |
+
const approachLayer = async (targetY) => {
|
| 423 |
+
const botY = Math.floor(bot.entity.position.y);
|
| 424 |
+
if (targetY < botY) {
|
| 425 |
+
const reached = await descendToward(targetY);
|
| 426 |
+
return reached ? findTarget(searchFloorY) : null;
|
| 427 |
+
}
|
| 428 |
+
if (targetY > botY) {
|
| 429 |
+
const reached = await ascendToward(targetY);
|
| 430 |
+
return reached ? findTarget(searchFloorY) : null;
|
| 431 |
+
}
|
| 432 |
+
return null; // same level and still not found: genuinely elsewhere
|
| 433 |
+
};
|
| 434 |
+
|
| 435 |
while (mined < wanted) {
|
| 436 |
let block = findTarget(searchFloorY);
|
| 437 |
|
| 438 |
if (!block) {
|
| 439 |
// Nothing inside the dig budget at this X/Z. If the target is ores
|
| 440 |
+
// this map stacks as a layer, walk to that layer; the layer is
|
| 441 |
+
// continuous, so a straight approach reaches it. Anything else means
|
| 442 |
// the block genuinely is not here and the model must travel.
|
| 443 |
const probe = bot.findBlock({
|
| 444 |
matching: (candidate) => Boolean(candidate) &&
|
|
|
|
| 450 |
});
|
| 451 |
const knownOre = /(^|_)ore$/.test(name);
|
| 452 |
if (probe && knownOre) {
|
| 453 |
+
block = await approachLayer(probe.position.y);
|
|
|
|
| 454 |
}
|
| 455 |
}
|
| 456 |
|