Inital Commit of mining_lane.lua

This commit is contained in:
sascham 2020-12-20 16:20:49 +00:00
parent d7226d2cac
commit 55ef03625a

View File

@ -0,0 +1,70 @@
os.loadAPI("modules.lua")
-- handle command line arguments
local cliArgs = {...}
local length = tonumber(cliArgs[1])
local height = tonumber(cliArgs[2])
if length == nil or height == nil or cliArgs[1] == '?' then
print('Usage: mining_lane <length> <height>')
print('length = How wide the turtle should dig.')
print('height = How high the turtle should dig.')
return
end
-- Check if we have enough fuel.
local fuelNeeded = (height + 1) * (length + 1)
while (turtle.getFuelLevel() < fuelNeeded) do
local missingFuel = fuelNeeded - turtle.getFuelLevel()
print("Not enough fuel. Put items in slot 1 in the equivalent of " .. missingFuel .. " fuel")
read()
turtle.select(1)
turtle.refuel()
end
local front = true
-- Main Loop. Dig your tunnel
for j = 1, height do
for k = 1, length do
modules.check_fuel()
turtle.dig()
turtle.forward()
end
if j < height then
print('executing digup')
turtle.digUp()
modules.check_fuel()
turtle.up()
end
turtle.turnLeft()
turtle.turnLeft()
front = not front
end
-- Go all the way down
for tdown = 1, height-1 do
modules.check_fuel()
turtle.down()
end
-- If we are away from our starting point go back to your starting point
if not front then
for tfront = 1, length do
modules.check_fuel()
turtle.forward()
end
else
turtle.turnLeft()
turtle.turnLeft()
end
-- Puke everything in your inventory out
modules.puke()
-- Turn left to set the turtle to the starting positin
turtle.turnLeft()
turtle.turnLeft()