Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local modem = peripheral.wrap("left")
- local idealIron = 22
- local idealDiamond = 12
- local originX, originY, originZ = gps.locate()
- local currentX, currentY, currentZ = gps.locate()
- local counter = 0
- if not currentX then
- log("Cannot determine my position! Exiting...")
- error()
- end
- if not originX then
- log("Cannot determine my origin! Exiting...")
- error()
- end
- function log(message)
- modem.transmit(99,1,message)
- end
- function move(direction)
- if direction == "fwd" then
- while not turtle.forward() do
- turtle.forward()
- log("Can't move forward")
- end
- elseif direction == "bwd" then
- while not turtle.backward() do
- turtle.back()
- log("Can't move backward")
- end
- elseif direction == "left" then
- turtle.turnLeft()
- while not turtle.forward() do
- turtle.forward()
- log("Can't move to the left")
- end
- turtle.turnRight()
- elseif direction == "right" then
- turtle.turnRight()
- while not turtle.forward() do
- turtle.forward()
- log("Can't move to the right")
- end
- turtle.turnLeft()
- else
- log("Invalid direction passed for move(Str)")
- error()
- end
- updatePos()
- end
- function updatePos()
- local newX, newY, newZ = gps.locate()
- if not newX then
- log("Cannot determine my current position! Exiting...")
- error()
- end
- currentX = newX
- currentY = newY
- currentZ = newZ
- end
- function dig(direction)
- local oX, oY, oZ = gps.locate()
- local distance = 0
- if not oX then
- log("Cannot determine position before digging")
- error()
- end
- if direction == "left" then
- turtle.turnLeft()
- elseif direction == "right" then
- turtle.turnRight()
- else
- log("Invalid direction for digging given!")
- end
- while distance < 32 do
- os.sleep(0.5)
- turtle.dig()
- turtle.digUp()
- turtle.forward()
- updatePos()
- local dX = currentX - oX
- local dY = currentY - oY
- local dZ = currentZ - oZ
- distance = math.sqrt(dX*dX+dY*dY+dZ*dZ)
- end
- turtle.turnLeft()
- turtle.turnLeft()
- log("Returning..")
- while distance > 0 do
- turtle.dig()
- turtle.digUp()
- turtle.forward()
- local dX = currentX - oX
- local dY = currentY - oY
- local dZ = currentZ - oZ
- updatePos()
- distance = math.sqrt(dX*dX+dY*dY+dZ*dZ)
- end
- if direction == "left" then
- turtle.turnLeft()
- elseif direction == "right" then
- turtle.turnRight()
- end
- end
- function store()
- local c
- for i=1,16 do
- turtle.select(i)
- c = c + turtle.getItemCount(i)
- turtle.drop(turtle.getItemCount(i))
- end
- log("Stored "..c.." items!")
- end
- while true do
- if(turtle.detect()) then
- turtle.dig()
- turtle.digUp()
- end
- move("fwd")
- if(turtle.detect()) then
- turtle.dig()
- turtle.digUp()
- end
- move("fwd")
- dig("left")
- dig("right")
- counter = counter + 2
- log("Completed tunnel #"..counter/2)
- if turtle.getItemCount(16)==64 then
- log("I think I'm full. Let'g go home")
- local pos = counter
- while counter>0 do
- move("bwd")
- counter = counter - 1
- end
- turtle.turnLeft()
- store()
- turtle.turnRight()
- while counter<pos do
- turtle.move("fwd")
- counter = counter +1
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement