Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Mining program")
- print("")
- print("Place turtle on the surface facing away")
- print("from a chest. Turtle will move forward")
- print("one block and then mine in a X by Y grid.")
- print("Be sure to fuel the turtle before mining.")
- print("")
- print("How many squares forward should it mine?")
- local x = tonumber(read())
- print("")
- print("How many squares right should it mine?")
- local y = tonumber(read())
- print("")
- print("How many squares down should it mine? (0 = to bedrock)")
- local z = tonumber(read())
- if z == 0 then
- z = 999
- end
- if x < 1 or y < 1 or z < 1 then
- error("Invalid arguments")
- end
- print("")
- -- function to move the turtle
- -- with up to five retries
- local function go(movefunc)
- local moved = false
- local retry = 0
- while moved == false and retry < 10 do
- if retry > 0 then
- if movefunc == turtle.forward and turtle.detect() == false then
- turtle.attack()
- end
- os.sleep(0.5)
- end
- if movefunc == turtle.forward and turtle.detect() then
- turtle.dig()
- end
- moved = movefunc()
- retry = retry + 1
- end
- if moved == false then
- error("failed to move turtle")
- end
- end
- -- docking station is assumed to be 0,1
- -- chest is assumed to be -1,1
- for loopy=1,y do
- for loopx=1,x do
- -- check fuel level
- if turtle.getFuelLevel() < (loopx + loopy + 128) then
- error("Not enough fuel")
- end
- -- go to the initial square (1,1)
- go(turtle.forward)
- -- find the column we are working on
- col = 1
- turtle.turnRight()
- while col < loopy do
- go(turtle.forward)
- col = col + 1
- end
- -- find the row we are working on
- row = 1
- turtle.turnLeft()
- while row < loopx do
- go(turtle.forward)
- row = row + 1
- end
- -- dig to bedrock
- depth = 0
- while depth < z and (turtle.detectDown() == false or turtle.digDown()) do
- go(turtle.down)
- depth = depth + 1
- end
- for loopz=1,depth do
- go(turtle.up)
- end
- -- return home
- turtle.turnLeft()
- while col > 1 do
- go(turtle.forward)
- col = col - 1
- end
- turtle.turnLeft()
- while row > 0 do
- go(turtle.forward)
- row = row - 1
- end
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.turnRight()
- turtle.turnRight()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement