Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/lua5.3
- function main(arg)
- validateInput(arg)
- startMining(math.floor(arg[1]))
- end
- function validateInput(arg)
- if #arg < 1
- then
- print("Too few arguments!")
- showUsage()
- elseif #arg > 1
- then
- print("Too many arguments!")
- showUsage()
- elseif not tonumber(arg[1])
- then
- print("The parameter you provided was not numeric!")
- showUsage()
- elseif (tonumber(arg[1]) ~= math.floor(arg[1]))
- then
- print("Only whole numbers are allowed!")
- showUsage()
- elseif tonumber(arg[1]) < 1
- then
- print("No work to do! Enter a number greater than 0!")
- showUsage()
- end
- end
- function showUsage()
- print("Usage: spiral " .. "<int number of complete cycles>")
- os.exit()
- end
- function checkFuel()
- if turtle.getFuelLevel() == 0
- then
- burnFuel()
- end
- end
- function burnFuel()
- for i = 1, 16, 1
- do
- turtle.select(i)
- if turtle.refuel(1)
- then
- break
- end
- end
- if turtle.getFuelLevel() == 0
- then
- print("Fatal Error: Out of fuel")
- os.exit()
- end
- end
- function digOut()
- turtle.turnLeft()
- while turtle.detect()
- do
- turtle.dig()
- end
- turtle.turnRight()
- turtle.turnRight()
- while turtle.detect()
- do
- turtle.dig()
- end
- turtle.turnLeft()
- while turtle.detectDown()
- do
- turtle.digDown()
- end
- while turtle.detectUp()
- do
- turtle.digUp()
- end
- while turtle.detect()
- do
- turtle.dig()
- end
- checkFuel()
- while not turtle.forward()
- do
- turtle.dig()
- end
- end
- function startMining(cycles)
- local n = 0
- local c = 3
- while n < cycles
- do
- for i = 1, 4, 1
- do
- for j = 1, c, 1
- do
- digOut()
- end
- c = c + 3
- turtle.turnRight()
- end
- n = n + 1
- end
- end
- args = {...}
- main(args)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement