Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --check for right arguments
- local args = {...}
- if #args ~= 3 then
- error("please enter x,y,z of the target position")
- end
- local x,y,z = tonumber(args[1]),tonumber(args[2]),tonumber(args[3])
- --open Rednet
- if not rednet.isOpen() then
- peripheral.find("modem", rednet.open)
- end
- --check for enderchests
- local slot15 = turtle.getItemDetail(15)
- local slot16 = turtle.getItemDetail(16)
- if slot15 and slot16 then
- if not(slot15.name == "enderstorage:ender_chest" and slot15.name == "enderstorage:ender_chest") then
- print("enderchest missing")
- error()
- end
- else
- print("enderchest missing")
- error()
- end
- --place enderchest, take lava bucket, refuel and put enderchest back in inventory
- function refuel()
- if turtle.getFuelLevel() < 1000 then
- print("fuel = "..turtle.getFuelLevel())
- turtle.select(16)
- turtle.digUp()
- turtle.up()
- turtle.digUp()
- turtle.down()
- local ok,err = turtle.placeUp()
- if not ok then
- print("could not place enderchest")
- print(err)
- error()
- end
- turtle.suckUp()
- turtle.refuel()
- turtle.dropUp()
- turtle.digUp()
- end
- end
- -- -x = 1, -z = 2, +x = 3, +z = 4
- function getDirection()
- local loc1 = vector.new(gps.locate(2, false))
- if not turtle.forward() then
- for j=1,6 do
- if not turtle.forward() then
- turtle.dig()
- else
- break
- end
- end
- end
- loc2 = vector.new(gps.locate(2, false))
- heading = loc2 - loc1
- turtle.back()
- return ((heading.x + math.abs(heading.x) * 2) + (heading.z + math.abs(heading.z) * 3))
- end
- -- -x = 1, -z = 2, +x = 3, +z = 4
- function turn(cfacing, tfacing)
- print(cfacing, tfacing)
- while cfacing ~= tfacing do
- local facingDiff = tfacing - cfacing
- if math.abs(facingDiff) ~= 3 then
- if facingDiff > 0 then
- turtle.turnRight()
- cfacing = cfacing + 1
- else
- turtle.turnLeft()
- cfacing = cfacing - 1
- end
- else
- if facingDiff > 0 then
- turtle.turnLeft()
- cfacing = cfacing + 3
- else
- turtle.turnRight()
- cfacing = cfacing - 3
- end
- end
- end
- end
- function moveToPos(tx,ty,tz)
- local cfacing = getDirection()
- local cx,cy,cz = gps.locate()
- refuel()
- os.sleep(2)
- print(cy, ty)
- print(gps.locate())
- if cy < ty then
- while cy < ty do
- if not turtle.up() then
- turtle.digUp()
- else
- cy = cy + 1
- end
- end
- end
- refuel()
- if cx ~= tx then
- if cx < tx then --move to +x
- turn(cfacing,3)
- cfacing = 3
- while cx < tx do
- turtle.forward()
- cx = cx + 1
- end
- else --move to -x
- turn(cfacing,1)
- cfacing = 1
- while cx > tx do
- turtle.forward()
- cx = cx - 1
- end
- end
- end
- refuel()
- if cz ~= tz then
- if cz < tz then --move to +x
- turn(cfacing,4)
- cfacing = 4
- while cz < tz do
- turtle.forward()
- cz = cz + 1
- end
- else --move to -x
- turn(cfacing,2)
- cfacing = 2
- while cz > tz do
- turtle.forward()
- cz = cz - 1
- end
- end
- end
- refuel()
- if cy > ty then
- while cy > ty do
- if not turtle.down() then
- turtle.digDown()
- else
- cy = cy - 1
- end
- end
- end
- end
- moveToPos(x,y,z)
- rednet.broadcast(string.format("arrived at: x: %s, y: %s, z: %s",x,y,z))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement