From 55ef03625a30fc35a6867e8cbe76f4d978c8caed Mon Sep 17 00:00:00 2001 From: sascham Date: Sun, 20 Dec 2020 16:20:49 +0000 Subject: [PATCH] Inital Commit of mining_lane.lua --- Mining_Things/mining_lane.lua | 70 +++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 Mining_Things/mining_lane.lua diff --git a/Mining_Things/mining_lane.lua b/Mining_Things/mining_lane.lua new file mode 100644 index 0000000..5e48e72 --- /dev/null +++ b/Mining_Things/mining_lane.lua @@ -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 ') + 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() \ No newline at end of file