Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("How deep?:")
- local depth = tonumber(read())
- print("How wide?:")
- local width = tonumber(read())
- print("How long?:")
- local length = tonumber(read())
- local complete = 0
- local curX = 1
- local curY = 1
- local curZ = 1
- local dir = 1
- local lastX = 1
- local lastY = 1
- local lastZ = 1
- local check1 = true
- local check2 = true
- local check3 = true
- local check4 = true
- local debug = true
- function turnLeft()
- turtle.turnLeft()
- dir = dir - 1
- if dir < 1 then dir = 4 end
- if debug then
- if dir == 1 then print("Turned left, facing forward") end
- if dir == 2 then print("Turned left, facing right") end
- if dir == 3 then print("Turned left, facing backward") end
- if dir == 4 then print("Turned left, facing left") end
- end
- end
- function turnRight()
- turtle.turnRight()
- dir = dir + 1
- if dir > 4 then dir = 1 end
- if debug == 1 then
- if dir == 1 then print("Turned right, facing forward") end
- if dir == 2 then print("Turned right, facing right") end
- if dir == 3 then print("Turned right, facing backward") end
- if dir == 4 then print("Turned right, facing left") end
- end
- end
- function moveDown()
- if debug then print("Moving down") end
- if curZ > depth then
- if debug then print("Reached required depth.") end
- return false
- end
- if not turtle.down() then
- if debug then print("Failed to move down, blocked.") end
- return false
- end
- curZ = curZ + 1
- if debug then print("Moved down, now at level "..curZ..".") end
- return true
- end
- function moveUp()
- if debug then print("Moving up") end
- if curZ <= 1 then
- if debug then print("Surfaced.") end
- return false
- end
- if not turtle.up() then
- if debug then print("Failed to move up, blocked.") end
- return false
- end
- curZ = curZ - 1
- if debug then print("Moved up, now at level "..curZ..".") end
- return true
- end
- function moveForward()
- if curX == 1 and dir == 3 then
- if debug then print("Failed to move forward, mining limit reached.") end
- return false
- end
- if curX == length and dir == 1 then
- if debug then print("Failed to move forward, mining limit reached.") end
- return false
- end
- if curY == 1 and dir == 4 then
- if debug then print("Failed to move forward, mining limit reached.") end
- return false
- end
- if curY == width and dir == 2 then
- if debug then print("Failed to move forward, mining limit reached.") end
- return false
- end
- if not turtle.forward() then
- if debug then print("Failed to move forward, blocked.") end
- return false
- end
- if dir == 1 then curX = curX + 1 end
- if dir == 2 then curY = curY + 1 end
- if dir == 3 then curX = curX - 1 end
- if dir == 4 then curY = curY - 1 end
- if debug then print(curX..","..curY.."(X,Y)") end
- return true
- end
- function nextLevel()
- if debug then print("Moving to next level") end
- if curX ~= 1 or curY ~= 1 or dir ~= 1 then
- -- Moving to 1,1 position
- while dir ~= 3 do turnRight() end
- while curX > 1 do moveForward() end
- turnRight()
- while curY > 1 do moveForward() end
- turnRight()
- end
- for d = 1, 3 do
- if turtle.detectDown() then
- if debug then print("Digging down") end
- if not turtle.digDown() then
- print("Failed to dig down, bedrock.")
- return false
- end
- end
- if debug then print("Moving down") end
- if not moveDown() then
- print("Failed to move down, blocked.")
- return false
- end
- end
- return true
- end
- function itemCheck()
- if debug then print("Checking available exclusions") end
- if turtle.getItemCount(1) == 0 then check1 = false end
- if turtle.getitemCount(2) == 0 then check2 = false end
- if turtle.getItemCount(3) == 0 then check3 = false end
- if turtle.getItemCount(4) == 0 then check4 = false end
- end
- function checkUp()
- if check1 then
- turtle.select(1)
- if turtle.compareUp() then return false end
- end
- if check2 then
- turtle.select(2)
- if turtle.compareUp() then return false end
- end
- if check3 then
- turtle.select(3)
- if turtle.compareUp() then return false end
- end
- if check4 then
- turtle.select(4)
- if turtle.compareUp() then return false end
- end
- return true
- end
- function checkDown()
- if check1 then
- turtle.select(1)
- if turtle.compareDown() then return false end
- end
- if check2 then
- turtle.select(2)
- if turtle.compareDown() then return false end
- end
- if check3 then
- turtle.select(3)
- if turtle.compareDown() then return false end
- end
- if check4 then
- turtle.select(4)
- if turtle.compareDown() then return false end
- end
- return true
- end
- function mine()
- if checkUp() then turtle.digUp() end
- if checkDown() then turtle.digDown() end
- end
- while complete == 0 do
- if not nextLevel() then
- complete = 1
- else
- for y = 1, width do
- for x = 1, length - 1 do
- mine()
- if turtle.detect() then turtle.dig() end
- moveForward()
- end
- mine()
- if y~= width then
- if dir == 1 then
- turnRight()
- turtle.dig()
- moveForward()
- turnRight()
- else
- if dir == 3 then
- turnLeft()
- turtle.dig()
- moveForward()
- turnLeft()
- end
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement