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 args = table.pack(...);
|
||||||
local command = args[1];
|
local command = args[1];
|
||||||
@ -133,6 +133,22 @@ local function waitForInventory(message)
|
|||||||
os.pullEvent('turtle_inventory');
|
os.pullEvent('turtle_inventory');
|
||||||
end
|
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 function getFuelLevel()
|
||||||
local fuelLevel = turtle.getFuelLevel();
|
local fuelLevel = turtle.getFuelLevel();
|
||||||
|
|
||||||
@ -326,6 +342,7 @@ local function workTarget(inspectFn, digFn, placeFn, gooTier, targetName)
|
|||||||
end
|
end
|
||||||
|
|
||||||
print('Mining processed ' .. targetName .. ' block: ' .. tostring(inspected.name));
|
print('Mining processed ' .. targetName .. ' block: ' .. tostring(inspected.name));
|
||||||
|
ensureMiningSpace();
|
||||||
return digFn();
|
return digFn();
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -365,19 +382,25 @@ local function workHorizontalSides(gooTier)
|
|||||||
return changed;
|
return changed;
|
||||||
end
|
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)
|
local function workTopFromCurrentSide(gooTier)
|
||||||
if not turtle.forward() then
|
if not turtle.forward() then
|
||||||
return false;
|
return false, false;
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Only the presence of a block above matters here; ignore the inspect metadata.
|
||||||
local sideOccupied = turtle.inspectUp();
|
local sideOccupied = turtle.inspectUp();
|
||||||
local changed = false;
|
local changed = false;
|
||||||
|
local reachedTop = false;
|
||||||
|
|
||||||
if not sideOccupied then
|
if not sideOccupied then
|
||||||
if turtle.up() then
|
if turtle.up() then
|
||||||
if turtle.up() then
|
if turtle.up() then
|
||||||
turnAround();
|
turnAround();
|
||||||
changed = workTarget(turtle.inspect, turtle.dig, turtle.place, gooTier, 'top');
|
changed = workTarget(turtle.inspect, turtle.dig, turtle.place, gooTier, 'top');
|
||||||
|
reachedTop = true;
|
||||||
turnAround();
|
turnAround();
|
||||||
|
|
||||||
if not turtle.down() then
|
if not turtle.down() then
|
||||||
@ -399,15 +422,20 @@ local function workTopFromCurrentSide(gooTier)
|
|||||||
error('could not return below the goo after top side check');
|
error('could not return below the goo after top side check');
|
||||||
end
|
end
|
||||||
|
|
||||||
return changed;
|
return changed, reachedTop;
|
||||||
end
|
end
|
||||||
|
|
||||||
local function workTop(gooTier)
|
local function workTop(gooTier)
|
||||||
local changed = false;
|
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
|
for _ = 1, 4 do
|
||||||
if not changed then
|
if not done then
|
||||||
changed = workTopFromCurrentSide(gooTier);
|
local sideChanged, reachedTop = workTopFromCurrentSide(gooTier);
|
||||||
|
changed = sideChanged or changed;
|
||||||
|
done = sideChanged or reachedTop;
|
||||||
end
|
end
|
||||||
|
|
||||||
turtle.turnRight();
|
turtle.turnRight();
|
||||||
@ -458,6 +486,9 @@ local function workBottom()
|
|||||||
|
|
||||||
local changed = false;
|
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
|
while true do
|
||||||
local ok, inspected = turtle.inspect();
|
local ok, inspected = turtle.inspect();
|
||||||
|
|
||||||
@ -494,6 +525,7 @@ local function workBottom()
|
|||||||
error('unexpected goo block in the turtle center position');
|
error('unexpected goo block in the turtle center position');
|
||||||
else
|
else
|
||||||
print('Mining processed bottom block: ' .. tostring(inspected.name));
|
print('Mining processed bottom block: ' .. tostring(inspected.name));
|
||||||
|
ensureMiningSpace();
|
||||||
|
|
||||||
if turtle.dig() then
|
if turtle.dig() then
|
||||||
changed = true;
|
changed = true;
|
||||||
@ -517,6 +549,8 @@ while true do
|
|||||||
ensureRuntimeFuel();
|
ensureRuntimeFuel();
|
||||||
|
|
||||||
local gooTier = ensureGooAlive();
|
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 hasEligibleBlocks = findEligibleProcessSlot(gooTier) ~= nil;
|
||||||
|
|
||||||
local changed = false;
|
local changed = false;
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user