Last active
June 7, 2019 00:01
-
-
Save admiral0/08533bf1f003c528fe7c9843fbb28033 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- | |
-- Excavator | |
-- | |
-- Under 1000 the turtle will try to consume all fuel it mines | |
fuel = 1000 | |
y = tonumber(arg[1]) - 1 | |
x = tonumber(arg[2]) - 1 | |
depth = 0 | |
buffer = {} | |
-- Hook called after each refuel | |
function hookConsumed(item, quantity) | |
end | |
function hookMined(items) | |
end | |
function hookDone() | |
end | |
function hasFreeSpace() | |
for slot = 1, 15 do | |
if turtle.getItemCount(slot) == 0 then | |
return true | |
end | |
end | |
return false | |
end | |
function doFuel() | |
if turtle.getFuelLevel() < fuel then | |
for slot in 1,15 do | |
turtle.select(slot) | |
local data = turtle.getItemDetail() | |
turtle.refuel() | |
local countAfter = turtle.getItemCount() | |
local consumedAmount = data.count - countAfter | |
if consumedAmount > 0 then | |
hookConsumed(data, consumedAmount) | |
end | |
end | |
end | |
end | |
function storeLoot() | |
turtle.select(16) | |
turtle.place() | |
local buffer = {} | |
for slot = 1, 15 do | |
turtle.select(slot) | |
local data = turtle.getItemDetail() | |
local amount = 0 | |
if data ~= nil then | |
if buffer[data.name] ~= nil then | |
amount = buffer[data.name] + data.count | |
else | |
amount = data.count | |
end | |
buffer[data.name] = amount | |
turtle.drop() | |
end | |
end | |
turtle.select(16) | |
turtle.dig() | |
hookMined(buffer) | |
turtle.select(1) | |
end | |
function checkLoot() | |
if hasFreeSpace() then | |
return nil | |
end | |
storeLoot() | |
end | |
function mine3() | |
while turtle.detect() do | |
turtle.dig() | |
checkLoot() | |
end | |
turtle.digUp() | |
checkLoot() | |
turtle.digDown() | |
checkLoot() | |
doFuel() | |
end | |
function moveDown() | |
if turtle.down() then | |
depth = depth + 1 | |
return true | |
end | |
return false | |
end | |
function initialPosition() | |
turtle.up() | |
turtle.turnLeft() | |
turtle.turnLeft() | |
--[[turtle.digDown() | |
if moveDown() == false then | |
return false; | |
end | |
turtle.digDown() | |
if moveDown() == false then | |
return false; | |
end | |
return true | |
--]] | |
end | |
function mineLineRow(row, depth) | |
for column=1, y do | |
mine3() | |
if not turtle.forward() then | |
print("Stuck at row " .. row .. " at column " .. column .. " at depth " .. depth) | |
return false | |
end | |
end | |
return true | |
end | |
function mineLevel(depth, invstart) | |
local invertedTurn = invstart | |
for row=1, x do | |
if not mineLineRow(row, depth) then | |
return false | |
end | |
if not invertedTurn then | |
turtle.turnRight() | |
mine3() | |
if not turtle.forward() then | |
print("Failed to turn at row " .. row .. " at depth " .. depth) | |
return false | |
end | |
turtle.turnRight() | |
else | |
turtle.turnLeft() | |
mine3() | |
if not turtle.forward() then | |
print("Failed to turn at row " .. row .. " at depth " .. depth) | |
return false | |
end | |
turtle.turnLeft() | |
end | |
invertedTurn = not invertedTurn | |
end | |
return mineLineRow(x, depth) | |
end | |
function descend3(inverted) | |
if not inverted then | |
turtle.turnLeft() | |
else | |
turtle.turnRight() | |
end | |
for step=1,3 do | |
mine3() | |
if not turtle.down() then | |
return false | |
end | |
end | |
if not inverted then | |
turtle.turnLeft() | |
else | |
turtle.turnRight() | |
end | |
return true | |
end | |
function quarry() | |
local depth = 1 | |
local inverted = false | |
while descend3(inverted) do | |
if not mineLevel(depth, inverted) then | |
return false | |
end | |
inverted = not inverted | |
depth = depth + 3 | |
end | |
storeLoot() | |
goUp(depth) | |
end | |
function goUp(depth) | |
for steps=1,depth do | |
turtle.up() | |
end | |
end | |
initialPosition() | |
quarry() | |
hookDone() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment