Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- args = {...}
- d = 0
- distance = args[1]
- tonumber(distance)
- tx = args[1]
- ty = args[2]
- tz = args[3]
- hx,hy,hz = gps.locate()
- x = hx
- y = hy
- z = hz
- print("home:",hx,hy,hz)
- print("target:",tx,ty,tz)
- planted = false
- function Refuel()
- d2 = (2*math.abs(tx-hx)+2*math.abs(tz-hz)+math.abs(120-hy)+math.abs(120-ty))
- n=math.ceil(d2/80)
- print(n)
- turtle.select(1)
- turtle.refuel(n)
- end
- function Det()
- print(table.getn(args))
- i = table.getn(args)
- if i == 0 or i == nil then
- printError("Nothing Defined, Use distance or coordinates")
- elseif i == 1 then
- print("Running In Distance Mode")
- Run()
- elseif i == 3 then
- print("Running In GPS Mode")
- GPSCal()
- elseif i >= 3 then
- printError("Too many Arguments")
- end
- end
- function GPSCal()
- Refuel()
- --go up to lvl 120
- while y < 120 do
- turtle.up()
- y = y+1
- end
- --calibrate x and y
- ix,iy,iz = gps.locate()
- turtle.forward()
- x,y,z = gps.locate()
- if x - ix == 1 then
- RunGPS()
- elseif x - ix == -1 then
- turtle.turnRight()
- turtle.turnRight()
- RunGPS()
- elseif z - iz == 1 then
- turtle.turnLeft()
- RunGPS()
- elseif z - iz == -1 then
- turtle.turnRight()
- RunGPS()
- else
- printError("GPS ERROR")
- end
- end
- function RunGPS()
- x,y,z = gps.locate()
- --go x
- if x < tonumber(tx) then
- while x<tonumber(tx) do
- if turtle.getFuelLevel() == 0 then
- Refuel()
- end
- turtle.forward()
- x=x+1
- end
- elseif x > tonumber(tx) then
- while x>tonumber(tx) do
- if turtle.getFuelLevel() == 0 then
- Refuel()
- end
- turtle.back()
- x=x-1
- end
- end
- --go z
- if z<tonumber(tz) then
- turtle.turnRight()
- while z<tonumber(tz) do
- if turtle.getFuelLevel() == 0 then
- Refuel()
- end
- turtle.forward()
- z=z+1
- end
- elseif z>tonumber(tz) then
- turtle.turnLeft()
- while z>tonumber(tz) do
- if turtle.getFuelLevel() == 0 then
- Refuel()
- end
- turtle.forward()
- z=z-1
- end
- end
- --DESCEND
- while y>tonumber(ty) or turtle.detectDown() == false do
- if turtle.getFuelLevel() == 0 then
- Refuel()
- end
- turtle.down()
- y=y-1
- if turtle.detectDown() == true then
- if planted == false then
- Plant()
- else
- print("home")
- end
- end
- end
- end
- function Run()
- turtle.refuel(math.ceil(tx/80))
- redstone.setOutput("right", false)
- while tonumber(d) < tonumber(distance) do
- if turtle.detect() == false then
- turtle.forward()
- d = d+1
- elseif turtle.detect() == true then
- Plant()
- elseif d == distance then
- Plant()
- end
- end
- end
- function Plant()
- turtle.back()
- turtle.select(2)
- turtle.place()
- turtle.back()
- turtle.back()
- turtle.select(3)
- turtle.place()
- turtle.turnLeft()
- redstone.setOutput("right", true)
- planted = true
- tx = hx
- ty = hy
- tz = hz
- GPSCal()
- end
- Det()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement