Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pX = 0
- pZ = 0
- pY = 0
- dX = 0
- dZ = 0
- dY = 0
- oX = 1 --Assume the turtle is set on the X axis at start
- oZ = 0
- tX = 1
- tZ = 0
- mineWidth = 10
- mineLenght = 3
- running = true
- debug = true
- debug = false
- function main()
- for i = 0, mineWidth do
- refuel()
- while pX < mineLenght do
- moveForward()
- inspectUp()
- inspectDown()
- turnRight()
- inspect()
- turnRight()
- turnRight()
- inspect()
- turnRight()
- end
- moveUp()
- moveUp()
- moveUp()
- turnRight()
- turnRight()
- refuel()
- while pX > 0 do
- moveForward()
- inspectUp()
- inspectDown()
- turnRight()
- inspect()
- turnRight()
- turnRight()
- inspect()
- turnRight()
- end
- turnRight()
- moveForward()
- moveForward()
- moveDown()
- turnRight()
- refuel()
- while pX < mineLenght do
- moveForward()
- inspectUp()
- inspectDown()
- turnRight()
- inspect()
- turnRight()
- turnRight()
- inspect()
- turnRight()
- end
- turnRight()
- turnRight()
- moveDown()
- refuel()
- while pX > 0 do
- moveForward()
- inspectUp()
- inspectDown()
- turnRight()
- inspect()
- turnRight()
- turnRight()
- inspect()
- turnRight()
- end
- turnRight()
- moveForward()
- moveForward()
- moveDown()
- turnRight()
- end
- end
- function refuel()
- fuelLevel = turtle.getFuelLevel()
- if(fuelLevel < 1000) then
- for slot = 1,16 do
- turtle.select(slot)
- if turtle.refuel(1) then
- return true
- end
- end
- else
- --goHome()
- --shutDown()
- end
- end
- function inspect()
- if debug then
- print ("Position : "..pX.." "..pZ.." "..pY)
- print ("Orientation: "..oX.." "..oZ)
- end
- success,material = turtle.inspect()
- if material.name ~= "minecraft:stone" and material.name ~= "minecraft:dirt" then
- turtle.dig()
- end
- end
- function inspectUp()
- success,material = turtle.inspectUp()
- if material.name ~= "minecraft:stone" and material.name ~= "minecraft:dirt" then
- turtle.digUp()
- end
- end
- function inspectDown()
- success,material = turtle.inspectDown()
- if material.name ~= "minecraft:stone" and material.name ~= "minecraft:dirt" then
- turtle.digDown()
- end
- end
- function drop()
- dZ = pZ
- while pZ ~= 0 do
- if oX == 1 then
- turtle.turnRight()
- elseif oX == -1 then
- turtle.turnLeft()
- end
- if oZ == 1 then
- turnRight()
- turnRight()
- else
- moveForward()
- end
- end
- for i = 2,16 do
- turtle.select(i)
- turtle.dropDown()
- end
- turnRight()
- turnRight()
- while dZ ~= 0 do
- if oX == 1 then
- turtle.turnRight()
- elseif oX == -1 then
- turtle.turnLeft()
- elseif oZ == 1 then
- turnRight()
- turnRight()
- else
- moveForward()
- end
- end
- end
- function moveForward()
- if debug then
- print ("Position : "..pX.." "..pZ.." "..pY)
- print ("Orientation: "..oX.." "..oZ)
- end
- if turtle.forward() then
- if oX == 1 then
- pX = pX + 1
- elseif oX == -1 then
- pX = pX - 1
- elseif oZ == 1 then
- pZ = pZ + 1
- else
- pZ = pZ - 1
- end
- else
- turtle.dig()
- turtle.forward()
- if oX == 1 then
- pX = pX + 1
- elseif oX == -1 then
- pX = pX - 1
- elseif oZ == 1 then
- pZ = pZ + 1
- else
- pZ = pZ - 1
- end
- end
- end
- function moveUp()
- if debug then
- print ("Position : "..pX.." "..pZ.." "..pY)
- print ("Orientation: "..oX.." "..oZ)
- end
- if turtle.up() then
- pY = pY + 1
- else
- turtle.digUp()
- turtle.up()
- pY = pY + 1
- end
- end
- function moveDown()
- if debug then
- print ("Position : "..pX.." "..pZ.." "..pY)
- print ("Orientation: "..oX.." "..oZ)
- end
- if turtle.down() then
- pY = pY - 1
- else
- turtle.digDown()
- turtle.down()
- pY = pY - 1
- end
- end
- function goHome() --Return in X
- dZ = pZ
- while dX ~= 0 do
- if dX > 0 then
- if oX == 1 then
- turnRight()
- turnRight()
- elseif oX == -1 then
- moveForward()
- else
- turnRight()
- end
- else
- if oX == 1 then
- moveForward()
- elseif oX == -1 then
- turnRight()
- turnRight()
- else
- turnLeft()
- end
- end
- end
- while pZ ~= 0 do
- if dX > 0 then
- if oX == 1 then
- turnRight()
- turnRight()
- elseif oX == -1 then
- moveForward()
- else
- turnRight()
- end
- else
- if oX == 1 then
- moveForward()
- elseif oX == -1 then
- turnRight()
- turnRight()
- else
- turnLeft()
- end
- end
- end
- end
- function shutDown()
- running = false
- end
- function turnRight()
- turtle.turnRight()
- if oX == 1 then
- oX = 0
- oZ = -1
- elseif oX == -1 then
- oX = 0
- oZ = 1
- elseif oZ == 1 then
- oX = 1
- oZ = 0
- else
- oX = -1
- oZ = 0
- end
- end
- function turnLeft()
- turtle.turnLeft()
- if oX == 1 then
- oX = 0
- oZ = 1
- elseif oX == -1 then
- oX = 0
- oZ = -1
- elseif oZ == 1 then
- oX = -1
- oZ = 0
- else
- oX = 1
- oZ = 0
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement