SHARE
TWEET

Untitled

a guest Jul 16th, 2019 78 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. --1:z+  2:x-   3:z-  4:x+
  2. local args = {...}
  3. local wX=-861
  4. local wY=68
  5. local wZ=-566
  6.  
  7. --Functii
  8. function turn(poz)
  9.     print("Turn " .. poz)
  10.     local run2=1
  11.     if poz==heading then
  12.         return
  13.     end
  14.     if poz==heading-1 then
  15.         turtle.turnLeft()
  16.         run1=0
  17.     end
  18.     if poz==4 then
  19.         if heading==1 then
  20.             turtle.turnLeft()
  21.             run1=0
  22.         end
  23.     end
  24.     if run2==1 then
  25.         if poz==heading+1 then
  26.             turtle.turnRight()
  27.         else
  28.             turtle.turnRight()
  29.             turtle.turnRight()
  30.         end
  31.     end
  32.  
  33.     heading = poz
  34.     save_coord()
  35. end
  36. function mergi_coord(X_dorit, Y_dorit, Z_dorit, prioritate_Y)
  37.     if prioritate_Y==1 then
  38.         mergi_y(Y_dorit)
  39.     end
  40.     mergi_x(X_dorit)
  41.     mergi_z(Z_dorit)
  42.     if prioritate_Y==0 then
  43.         mergi_y(Y_dorit)
  44.     end
  45. end
  46. function mergi_x(X_dorit)
  47.     local add_val=0
  48.     if my_X>X_dorit then
  49.         turn(2)
  50.         add_val=-1
  51.     elseif my_X<X_dorit then
  52.         turn(4)
  53.         add_val=1
  54.     end
  55.     local de_mers=math.abs(my_X-X_dorit)
  56.     print("Merg pe X "..de_mers)
  57.     for i=1,de_mers do
  58.         turtle.dig()
  59.         turtle.forward()
  60.         my_X=my_X+add_val
  61.         save_coord()
  62.     end
  63. end
  64. function mergi_z(Z_dorit)
  65.     local add_val=0
  66.     if my_Z>Z_dorit then
  67.         turn(3)
  68.         add_val=-1
  69.     elseif my_Z<Z_dorit then
  70.         turn(1)
  71.         add_val=1
  72.     end
  73.     local de_mers=math.abs(my_Z-Z_dorit)
  74.     print("Merg pe Z "..de_mers)
  75.     for i=1,de_mers do
  76.         turtle.dig()
  77.         turtle.forward()
  78.         my_Z=my_Z+add_val
  79.         save_coord()
  80.     end
  81. end
  82. function mergi_y(Y_dorit)
  83.     local de_mers=math.abs(my_Y-Y_dorit)
  84.     print("Merg pe Y "..de_mers)
  85.     if my_Y>Y_dorit then
  86.         for i=1,de_mers do
  87.             turtle.digDown()
  88.             turtle.down()
  89.             my_Y=my_Y-1
  90.             save_coord()
  91.         end
  92.     elseif my_Y<Y_dorit then
  93.             for i=1,de_mers do
  94.             turtle.digUp()
  95.             turtle.up()
  96.             my_Y=my_Y+1
  97.             save_coord()
  98.         end
  99.     end
  100. end
  101. function load_coord()
  102.     --load home
  103.     local home_file = fs.open("home.lua", "r")
  104.     home_X=tonumber(home_file.readLine())
  105.     home_Y=tonumber(home_file.readLine())
  106.     home_Z=tonumber(home_file.readLine())
  107.     home_file.close()
  108.     --load my_coord
  109.     local my_file = fs.open("my.lua", "r")
  110.     my_X=tonumber(my_file.readLine())
  111.     my_Y=tonumber(my_file.readLine())
  112.     my_Z=tonumber(my_file.readLine())
  113.     heading=tonumber(my_file.readLine())
  114.     my_file.close()
  115.     print(heading)
  116. end
  117. function save_coord()
  118.     local my_file = fs.open("my.lua", "w")
  119.     my_file.write(tostring(my_X))
  120.     my_file.write("\n")
  121.     my_file.write(tostring(my_Y))
  122.     my_file.write("\n")
  123.     my_file.write(tostring(my_Z))
  124.     my_file.write("\n")
  125.     my_file.write(tostring(heading))
  126.     my_file.write("\n")
  127.     my_file.close()
  128. end
  129.  
  130.  
  131. load_coord()
  132. --mergi_coord(wX,wY,wZ,1)
  133. turn(tonumber(args[0]))
  134. save_coord()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top