Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = { ... }
- numArgs = table.getn(args)
- FUEL_INV_LOC = 1
- FUEL_REFUEL_AMMT = 1
- FUEL_LOWER_BOUND = 0
- TORCH_INV_LOC = 2
- TORCH_INTERVAL = 5
- function fuel ()
- if turtle.getFuelLevel() == FUEL_LOWER_BOUND then
- turtle.select(FUEL_INV_LOC)
- turtle.refuel(FUEL_REFUEL_AMMT)
- end
- end
- function plantTunnelTorch ()
- turtle.select(TORCH_INV_LOC)
- turtle.placeDown()
- end
- function goodDig ()
- while turtle.detect() do
- fuel()
- turtle.dig()
- end
- fuel()
- end
- function goodDigUp ()
- while turtle.detectUp() do
- fuel()
- turtle.digUp()
- sleep(0.5)
- end
- fuel()
- end
- function clearUpDown ()
- goodDigUp()
- turtle.digDown()
- fuel()
- end
- function tunnel (len, toTorch)
- count = 0
- torch = TORCH_INTERVAL
- while count < len do
- clearUpDown()
- if torch == TORCH_INTERVAL and toTorch == true then
- plantTunnelTorch()
- torch = 0
- end
- goodDig()
- turtle.forward()
- clearUpDown()
- fuel()
- count = count+1
- torch = torch+1
- end
- end
- function leftOrRight (dire)
- if dire == 'l' then
- turtle.turnLeft()
- elseif dire == 'r' then
- turtle.turnRight()
- else
- term.write("Error, bad direction.")
- end
- end
- function swapDirection (dire)
- if dire == 'l' then
- return 'r'
- elseif dire == 'r' then
- return 'l'
- end
- end
- --================Main===============--
- digNum = tonumber(args[1])
- if numArgs == 1.0 then
- tunnel(digNum, true)
- elseif numArgs == 4.0 then
- interval = tonumber(args[2])
- direction = args[3]
- if direction ~= 'r' and direction ~= 'l' then
- error("Third argument must be 'r' or 'l'")
- end
- repeatNum = tonumber(args[4])
- if interval > 1 then
- dropTorch = true
- else
- dropTorch = false
- end
- while repeatNum > 0 do
- tunnel(digNum, true)
- repeatNum = repeatNum - 1
- if repeatNum > 0 then
- leftOrRight(direction)
- tunnel(interval, true)
- leftOrRight(direction)
- tunnel(digNum, dropTorch)
- repeatNum = repeatNum - 1
- direction = swapDirection(direction)
- leftOrRight(direction)
- tunnel(interval, true)
- leftOrRight(direction)
- direction = swapDirection(direction)
- end
- end
- else
- error("Usage: dig [int:dist] [int:interval] opt[l | r] [int:times]")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement