SamuelDeboni

mine.lua

Dec 3rd, 2020 (edited)
1,062
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.66 KB | None | 0 0
  1. size_z = 16
  2. size_x = 32
  3. size_y = 1
  4.  
  5. path = {}
  6.  
  7.  
  8. function createPath()
  9.     i = 1
  10.     for y = 1, size_y, 1 do
  11.         for z = 1, size_z, 1 do
  12.             for z = 1, size_x, 1 do
  13.                 path[i] = "mov"
  14.                 i = i + 1
  15.             end
  16.             path[i] = "tl"
  17.             i = i + 1
  18.             path[i] = "mov"
  19.             i = i + 1
  20.             path[i] = "tl"
  21.             i = i + 1
  22.             for z = 1, size_x, 1 do
  23.                 path[i] = "mov"
  24.                 i = i +1
  25.             end
  26.             path[i] = "tr"
  27.             i = i + 1
  28.             path[i] = "mov"
  29.             i = i + 1
  30.             path[i] = "tr"
  31.             i = i + 1
  32.         end
  33.         path[i] = "y"
  34.         i = i + 1
  35.         path[i] = "y"
  36.         i = i + 1
  37.         path[i] = "y"
  38.         i = i + 1
  39.         path[i] = "tl"
  40.         i = i + 1
  41.     end
  42. end
  43.  
  44. function putChest()
  45.     while turtle.detectDown() do
  46.         turtle.digDown()
  47.     end
  48.  
  49.     turtle.select(1)
  50.     turtle.placeDown()
  51.  
  52.     for i = 2, 16 do
  53.         turtle.select(i)
  54.         turtle.dropDown()
  55.     end
  56.     turtle.select(1)
  57.  
  58.     -- Ender chest
  59.     turtle.digDown()
  60. end
  61.  
  62. function move()
  63.     while turtle.detectUp() do
  64.         turtle.digUp()
  65.     end
  66.  
  67.     while turtle.detect() do
  68.         turtle.dig()
  69.     end
  70.  
  71.     while turtle.detectDown() do
  72.         turtle.digDown()
  73.     end
  74.     os.sleep(0.2)  
  75.     turtle.forward()
  76. end
  77.  
  78.  
  79. function serialize(data, name)
  80.   if not fs.exists('/data') then
  81.     fs.makeDir('/data')
  82.   end
  83.     local f = fs.open('/data/'..name, 'w')
  84.     f.write(textutils.serialize(data))
  85.     f.close()
  86. end
  87.  
  88. function unserialize(name)
  89.         if fs.exists('/data/'..name) then
  90.             local f = fs.open('/data/'..name, 'r')
  91.             data = textutils.unserialize(f.readAll())
  92.             f.close()
  93.         else
  94.             data = cp
  95.         end
  96.     return data
  97. end
  98.  
  99. counter = 0
  100.  
  101. -- Loads path, if dont exit create
  102. if not fs.exists('/data/'..name) then
  103.     createPath()
  104.     path["startPoint"] = 1
  105.     serialize(path, 'tpath')
  106. else
  107.     path = unserialize('tpath')
  108. end
  109.  
  110. -- Find path size
  111. for i, value in pairs(path) do
  112.     counter = counter + 1
  113. end
  114.  
  115. for i = path["startPoint"], counter do
  116.     print(path[i])
  117.  
  118.     if path[i] == "mov" then
  119.         move()
  120.     end
  121.     if path[i] == "tr" then
  122.         turtle.turnRight()
  123.     end
  124.     if path[i] == "tl" then
  125.         turtle.turnLeft()
  126.     end
  127.    
  128.     if path[i] == "y" then
  129.         turtle.digDown()
  130.         turtle.moveDown()
  131.     end
  132.  
  133.     if turtle.getItemCount(16) > 0 then
  134.         putChest()
  135.     end
  136.  
  137.     path["startPoint"] = path["startPoint"] + 1
  138.     serialize(path, 'tpath')
  139. end
  140.  
  141.  
Add Comment
Please, Sign In to add comment