AnonymusHochgenuss

chunkgoto

Jul 15th, 2021 (edited)
653
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.34 KB | None | 0 0
  1. local tArgs = { ... }
  2. if #tArgs ~= 3 then
  3.  print( "Usage: goto <cordinates>" )
  4.  return
  5. end
  6. cid=os.getComputerID()
  7. x1 = tonumber(tArgs[1])
  8. y1 = 81+cid
  9. z1 = tonumber(tArgs[3])
  10. print("target: "..x1..", "..y1..", "..z1)
  11. ---- functions ----
  12.  
  13. function locate()
  14.  x, y, z = gps.locate()
  15. end
  16.  
  17. function locate1()
  18.  locate()
  19.  x2=tonumber(x)
  20.  y2=tonumber(y)
  21.  z2=tonumber(z)
  22.  e=0
  23.  while turtle.detect() do
  24.   turtle.turnRight()
  25.   e=e+1
  26.   if e > 3 then
  27.    print("all sides blocked")
  28.    return
  29.   end
  30.  end
  31.  while not turtle.forward() do
  32.   sleep(1)
  33.  end
  34.  locate()
  35.  turtle.back()
  36.  if z < z2 then
  37.   f="north"
  38.  elseif x > x2 then
  39.   f="east"
  40.  elseif z > z2 then
  41.   f="south"
  42.  elseif x < x2 then
  43.   f="west"
  44.  end
  45. end
  46.  
  47.  
  48. function facing(f1)
  49.  -- locate1()
  50.  print("facing actually to: "..f)
  51.  print("turning facing to "..f1)
  52.  if f1 == "north" then
  53.   if f == "north" then
  54.   elseif f == "east" then
  55.    turtle.turnRight()
  56.    turtle.turnRight()
  57.    turtle.turnRight()
  58.   elseif f == "south" then
  59.    turtle.turnRight()
  60.    turtle.turnRight()
  61.   elseif f == "west" then
  62.    turtle.turnRight()
  63.   end
  64.   f="north"
  65.  end
  66.  if f1 == "east" then
  67.   if f == "north" then
  68.    turtle.turnRight()
  69.   elseif f == "east" then
  70.   elseif f == "south" then
  71.    turtle.turnRight()
  72.    turtle.turnRight()
  73.    turtle.turnRight()
  74.   elseif f == "west" then
  75.    turtle.turnRight()
  76.    turtle.turnRight()
  77.   end
  78.   f="east"
  79.  end
  80.  if f1 == "south" then
  81.   if f == "north" then
  82.    turtle.turnRight()
  83.    turtle.turnRight()
  84.   elseif f == "east" then
  85.    turtle.turnRight()
  86.   elseif f == "south" then
  87.   elseif f == "west" then
  88.    turtle.turnRight()
  89.    turtle.turnRight()
  90.    turtle.turnRight()
  91.   end
  92.   f="south"
  93.  end
  94.  if f1 == "west" then
  95.   if f == "north" then
  96.    turtle.turnRight()
  97.    turtle.turnRight()
  98.    turtle.turnRight()
  99.   elseif f == "east" then
  100.    turtle.turnRight()
  101.    turtle.turnRight()
  102.   elseif f == "south" then
  103.    turtle.turnRight()
  104.   elseif f == "west" then
  105.   end
  106.   f="west"
  107.  end
  108. end
  109.  
  110. ---------------------------
  111.  
  112. x=false
  113. y=false
  114. z=false
  115. locate()
  116. if x then
  117.  print("position: "..x..", "..y..", "..z)
  118.  x2=tonumber(x)
  119.  y2=tonumber(y)
  120.  z2=tonumber(z)
  121.  e=0
  122.  while turtle.detect() do
  123.   turtle.turnRight()
  124.   e=e+1
  125.   if e > 3 then
  126.    print("all sides blocked. couldn't determine")
  127.    return
  128.   end
  129.  end
  130.  while not turtle.forward() do
  131.   sleep(1)
  132.  end
  133.  locate()
  134.  turtle.back()
  135.  if z < z2 then
  136.   f="north"
  137.  elseif x > x2 then
  138.   f="east"
  139.  elseif z > z2 then
  140.   f="south"
  141.  elseif x < x2 then
  142.   f="west"
  143.  end
  144.  while y < 81+cid do
  145.   while not turtle.up() do
  146.    sleep(1)
  147.   end
  148.   y=y+1
  149.  end
  150.  locate()
  151.  if x1 < x then
  152.   f1="west"
  153.   facing(f1)
  154.   while x > x1 do
  155.    while not turtle.forward() do
  156.     sleep(0.5)
  157.    end
  158.    x=x-1
  159.   end
  160.  elseif x1 > x then
  161.   f1="east"
  162.   facing(f1)
  163.   while x < x1 do
  164.    while not turtle.forward() do
  165.     sleep(0.5)
  166.    end
  167.    x=x+1
  168.   end
  169.  end
  170.  if z1 > z then
  171.   f1="south"
  172.   facing(f1)
  173.   while z < z1 do
  174.    while not turtle.forward() do
  175.     sleep(0.5)
  176.    end
  177.    z=z+1
  178.   end
  179.  elseif z1 < z then
  180.   f1="north"
  181.   facing(f1)
  182.   while z > z1 do
  183.    while not turtle.forward() do
  184.     sleep(0.5)
  185.    end
  186.    z=z-1
  187.   end
  188.  end
  189.  locate()
  190.  print("position: "..x..", "..y..", "..z)
  191.  while y > y1 do
  192.   while not turtle.down() do
  193.    sleep(0.5)
  194.   end
  195.   y=y-1
  196.  end
  197. else
  198.  print("location not found")
  199. end
  200.  
Add Comment
Please, Sign In to add comment