Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local originX = -2511
- local originY = 58
- local originZ = 972
- local x, y, z
- function setCoordinates()
- repeat
- print("Locating (" .. textutils.formatTime(os.time(), false) .. ")")
- x, y, z = gps.locate(5)
- until not((not x) or (not y) or (not z))
- end
- function distanceToOrigin()
- return math.abs((originX - x) + (originY - y) + (originZ - z))
- end
- function forward()
- turtle.forward()
- setCoordinates()
- end
- function back()
- turtle.back()
- setCoordinates()
- end
- function up()
- turtle.up()
- setCoordinates()
- end
- function down()
- turtle.down()
- setCoordinates()
- end
- function completeRefuel()
- for slot = 1, 16 do
- turtle.select(slot)
- if turtle.refuel(0) then
- turtle.refuel()
- end
- end
- end
- function checkForOre(success, data)
- if success then
- if string.find(data.name, "ore") then
- return true
- end
- end
- return false
- end
- function mineOres()
- local success, data
- success, data = turtle.inspect()
- if checkForOre(success, data) then
- turtle.dig()
- forward()
- mineOres()
- back()
- end
- turtle.turnRight()
- success, data = turtle.inspect()
- if checkForOre(success, data) then
- turtle.dig()
- forward()
- mineOres()
- back()
- end
- turtle.turnRight()
- turtle.turnRight()
- success, data = turtle.inspect()
- if checkForOre(success, data) then
- turtle.dig()
- forward()
- mineOres()
- back()
- end
- turtle.turnRight()
- success, data = turtle.inspectUp()
- if checkForOre(success, data) then
- turtle.digUp()
- up()
- mineOres()
- down()
- end
- success, data = turtle.inspectDown()
- if checkForOre(success, data) then
- turtle.digDown()
- down()
- mineOres()
- up()
- end
- end
- function returnToOrigin()
- if y > originY then
- repeat
- turtle.digDown()
- down()
- until y == originY
- elseif y < originY then
- repeat
- turtle.digUp()
- up()
- until y == originY
- end
- local oldDistanceToOrigin
- while x ~= originX and z~= originZ do
- print("A")
- oldDistanceToOrigin = distanceToOrigin()
- turtle.dig()
- forward()
- if distanceToOrigin() > oldDistanceToOrigin then
- turtle.turnRight()
- turtle.turnRight()
- end
- if x == originX or z == originZ then
- turtle.turnRight()
- end
- end
- for slot = 1, 16 do
- turtle.select(slot)
- if not turtle.refuel(0) then
- turtle.dropUp()
- end
- end
- end
- setCoordinates()
- completeRefuel()
- returnToOrigin()
- while true do
- completeRefuel()
- if distanceToOrigin() >= turtle.getFuelLevel() then
- returnToOrigin()
- end
- mineOres()
- turtle.dig()
- turtle.digDown()
- forward()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement