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 dig down to")
- print("bedrock and then come back up and place")
- print("blocks in the chest. It will continue to")
- print("mine in a grid until it reaches the max")
- print("grid size that you specify.")
- 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("")
- -- function to move the turtle
- -- with up to three retries
- local function go(movefunc)
- local moved = false
- local retry = 0
- while moved == false and retry < 3 do
- if retry > 0 then
- os.sleep(0.25)
- end
- moved = movefunc()
- retry = retry + 1
- end
- if moved == false then
- error("failed to move turtle")
- end
- end
- isMore = true
- lasty = -1
- lastx = -1
- while isMore do
- if turtle.getFuelLevel() < (x + y + 128) then
- error("Not enough fuel")
- end
- -- go to the initial square (1,1)
- loopy = 1
- loopx = 1
- if turtle.detect() then
- turtle.dig()
- end
- go(turtle.forward)
- -- find the column we are working on
- -- go right until you hit a wall
- -- or hit the end of the grid
- turtle.turnRight()
- if lasty < 0 then
- while loopy < y and turtle.detect() == false do
- go(turtle.forward)
- loopy = loopy + 1
- end
- else
- end
- -- find the row we are working on
- -- go forward until you hit a wall
- -- or get to the end of the grid
- turtle.turnLeft()
- if lastx < 0 then
- while loopx < x and turtle.detect() == false do
- go(turtle.forward)
- loopx = loopx + 1
- end
- else
- end
- -- if we got to the end of the column
- -- and had finished the whole thing
- -- go back and start a new column
- -- otherwise this is the spot
- if loopx < x then
- turtle.dig()
- go(turtle.forward)
- loopx = loopx + 1
- elseif loopy < y then
- turtle.turnRight()
- turtle.turnRight()
- while loopx > 1 do
- go(turtle.forward)
- loopx = loopx - 1
- end
- turtle.turnLeft()
- turtle.dig()
- go(turtle.forward)
- loopy = loopy + 1
- turtle.turnLeft()
- else
- isMore = false
- end
- if isMore == true then
- z = 0
- while turtle.detectDown() == false or turtle.digDown() do
- go(turtle.down)
- z = z + 1
- end
- for loopz=1,z do
- go(turtle.up)
- end
- end
- -- return home
- turtle.turnLeft()
- while loopy > 1 do
- go(turtle.forward)
- loopy = loopy - 1
- end
- turtle.turnLeft()
- while loopx > 0 do
- go(turtle.forward)
- loopx = loopx - 1
- end
- for i=1,16 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.turnRight()
- turtle.turnRight()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement