feat(goo): improve mining flow and top-side traversal
This commit is contained in:
parent
01611e167f
commit
15e4373d0e
@ -1,4 +1,4 @@
|
||||
local _VERSION = '0.1.2';
|
||||
local _VERSION = '0.2.0';
|
||||
|
||||
local args = table.pack(...);
|
||||
local command = args[1];
|
||||
@ -133,6 +133,22 @@ local function waitForInventory(message)
|
||||
os.pullEvent('turtle_inventory');
|
||||
end
|
||||
|
||||
local function hasFreeSlot()
|
||||
for slot = 1, 16 do
|
||||
if turtle.getItemCount(slot) == 0 then
|
||||
return true;
|
||||
end
|
||||
end
|
||||
|
||||
return false;
|
||||
end
|
||||
|
||||
local function ensureMiningSpace()
|
||||
while not hasFreeSlot() do
|
||||
waitForInventory('Inventory is full. Remove items to keep mining.');
|
||||
end
|
||||
end
|
||||
|
||||
local function getFuelLevel()
|
||||
local fuelLevel = turtle.getFuelLevel();
|
||||
|
||||
@ -326,6 +342,7 @@ local function workTarget(inspectFn, digFn, placeFn, gooTier, targetName)
|
||||
end
|
||||
|
||||
print('Mining processed ' .. targetName .. ' block: ' .. tostring(inspected.name));
|
||||
ensureMiningSpace();
|
||||
return digFn();
|
||||
end
|
||||
|
||||
@ -365,19 +382,25 @@ local function workHorizontalSides(gooTier)
|
||||
return changed;
|
||||
end
|
||||
|
||||
-- Returns `changed, reachedTop`. `reachedTop` is true only once we have actually
|
||||
-- climbed above the goo and inspected its top face, so the caller can stop trying
|
||||
-- the remaining sides; it stays false when this side is blocked or unclimbable.
|
||||
local function workTopFromCurrentSide(gooTier)
|
||||
if not turtle.forward() then
|
||||
return false;
|
||||
return false, false;
|
||||
end
|
||||
|
||||
-- Only the presence of a block above matters here; ignore the inspect metadata.
|
||||
local sideOccupied = turtle.inspectUp();
|
||||
local changed = false;
|
||||
local reachedTop = false;
|
||||
|
||||
if not sideOccupied then
|
||||
if turtle.up() then
|
||||
if turtle.up() then
|
||||
turnAround();
|
||||
changed = workTarget(turtle.inspect, turtle.dig, turtle.place, gooTier, 'top');
|
||||
reachedTop = true;
|
||||
turnAround();
|
||||
|
||||
if not turtle.down() then
|
||||
@ -399,15 +422,20 @@ local function workTopFromCurrentSide(gooTier)
|
||||
error('could not return below the goo after top side check');
|
||||
end
|
||||
|
||||
return changed;
|
||||
return changed, reachedTop;
|
||||
end
|
||||
|
||||
local function workTop(gooTier)
|
||||
local changed = false;
|
||||
local done = false;
|
||||
|
||||
-- Iterate all four sides so the four turnRight calls net to zero (facing is
|
||||
-- restored), but skip the climb once the single top face has been handled.
|
||||
for _ = 1, 4 do
|
||||
if not changed then
|
||||
changed = workTopFromCurrentSide(gooTier);
|
||||
if not done then
|
||||
local sideChanged, reachedTop = workTopFromCurrentSide(gooTier);
|
||||
changed = sideChanged or changed;
|
||||
done = sideChanged or reachedTop;
|
||||
end
|
||||
|
||||
turtle.turnRight();
|
||||
@ -458,6 +486,9 @@ local function workBottom()
|
||||
|
||||
local changed = false;
|
||||
|
||||
-- The bottom face is worked as one atomic round-trip (place -> wait -> mine ->
|
||||
-- return) rather than fire-and-forget like the other faces, because the turtle
|
||||
-- must vacate and then reclaim its home cell within a single pass.
|
||||
while true do
|
||||
local ok, inspected = turtle.inspect();
|
||||
|
||||
@ -494,6 +525,7 @@ local function workBottom()
|
||||
error('unexpected goo block in the turtle center position');
|
||||
else
|
||||
print('Mining processed bottom block: ' .. tostring(inspected.name));
|
||||
ensureMiningSpace();
|
||||
|
||||
if turtle.dig() then
|
||||
changed = true;
|
||||
@ -517,6 +549,8 @@ while true do
|
||||
ensureRuntimeFuel();
|
||||
|
||||
local gooTier = ensureGooAlive();
|
||||
-- Also relied on for its side effect: emits the "requires goo tier X" warnings
|
||||
-- for blocks the current tier cannot process yet.
|
||||
local hasEligibleBlocks = findEligibleProcessSlot(gooTier) ~= nil;
|
||||
|
||||
local changed = false;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user