SHARE
TWEET

Untitled

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