Advertisement
JMANN2400

WoodArchiver[NoFuel]

Aug 18th, 2017
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.74 KB | None | 0 0
  1.  
  2.  
  3.  
  4. x = 0
  5.  
  6. y = 0
  7.  
  8. xmax = 0
  9.  
  10. size = 0
  11.  
  12. oakTotal = 0
  13.  
  14. birchTotal = 0
  15.  
  16. depositChest = 0
  17.  
  18. currentChestFullness = 0
  19.  
  20. function writeFile()
  21.     file = fs.open("ArchiveInfo", "w")
  22.     file.writeLine(xmax)
  23.     file.writeLine(size)
  24.     file.writeLine(oakTotal)
  25.     file.writeLine(birchTotal)
  26.     file.writeLine(depositChest)
  27.     file.writeLine(currentChestFullness)
  28.     file.close()
  29. end
  30.  
  31. function readFile()
  32.     file = fs.open("ArchiveInfo","r")
  33.     fileData = {}
  34.     local i = 0
  35.     while i < 6 do
  36.         line = file.readLine()
  37.         table.insert(fileData, line)
  38.         i = i + 1
  39.     end
  40.     file.close()
  41.     xmax = tonumber(fileData[1])
  42.     size = tonumber(fileData[2])
  43.     oakTotal = tonumber(fileData[3])
  44.     birchTotal = tonumber(fileData[4])
  45.     depositChest = tonumber(fileData[5])
  46.     currentChestFullness = tonumber(fileData[6])
  47. end
  48.  
  49. function printData()
  50.     print("x = ", x)
  51.     print("y = ", y)
  52.     print("xmax = ", xmax)
  53.     print("size = ", size)
  54.     print("oakTotal = ", oakTotal)
  55.     print("birchTotal = ", birchTotal)
  56.     print("depositChest = ", depositChest)
  57.     print("currentChestFullness = ", currentChestFullness)
  58. end
  59.  
  60. function countWood()
  61.     for i = 2,16,1 do
  62.         local data = turtle.getItemDetail(i)
  63.         if data ~= nil then
  64.             if data.damage == 0 then
  65.                 oakTotal = oakTotal + data.count
  66.             end
  67.             if data.damage == 2 then
  68.                 birchTotal = birchTotal + data.count
  69.             end
  70.         end
  71.     end
  72.     writeFile()
  73. end
  74.    
  75. function makeChests()
  76.     turtle.select(2)
  77.     local data = turtle.getItemDetail()
  78.     if data.damage == 0 then
  79.         oakTotal = oakTotal - 32
  80.     end
  81.     if data.damage == 2 then
  82.         birchTotal = birchTotal - 32
  83.     end
  84.     turtle.dropDown(16)
  85.     sleep(3)
  86.     turtle.dropDown(16)
  87.     sleep(5)
  88.     turtle.select(1)
  89. end
  90.  
  91. function hardDig()
  92.     while turtle.detect() do
  93.         turtle.dig()
  94.     end
  95. end
  96.  
  97. function digFour()
  98.     turtle.up()
  99.     turtle.up()
  100.     turtle.up()
  101.     turtle.up()
  102.     hardDig()
  103.     turtle.down()
  104.     hardDig()
  105.     turtle.down()
  106.     hardDig()
  107.     turtle.down()
  108.     hardDig()
  109.     turtle.down()
  110.     hardDig()
  111. end
  112.  
  113. function chestColumn()
  114.     turtle.up()
  115.     turtle.up()
  116.     turtle.up()
  117.     turtle.up()
  118.     hardDig()
  119.     turtle.select(1)
  120.     turtle.down()
  121.     hardDig()
  122.     turtle.place()
  123.     turtle.down()
  124.     hardDig()
  125.     turtle.place()
  126.     turtle.down()
  127.     hardDig()
  128.     turtle.place()
  129.     turtle.down()
  130.     hardDig()
  131.     turtle.place()
  132. end
  133.  
  134. function fullChest()
  135.     digFour()
  136.     if turtle.forward() then
  137.         x = x + 1
  138.     end
  139.     digFour()
  140.     turtle.turnLeft()
  141.     chestColumn()
  142.     turtle.turnRight()
  143.     turtle.turnRight()
  144.     chestColumn()
  145.     turtle.turnLeft()
  146.     if turtle.forward() then
  147.         x = x + 1
  148.     end
  149.     turtle.turnLeft()
  150.     chestColumn()
  151.     turtle.turnRight()
  152.     turtle.turnRight()
  153.     chestColumn()
  154.     turtle.turnLeft()
  155.     if turtle.back() then
  156.         x = x - 1
  157.     end
  158.     if turtle.back() then
  159.         x = x - 1
  160.     end
  161.     xmax = xmax + 3
  162.     size = size + 27648
  163.     writeFile()
  164. end
  165.  
  166. function deposit()
  167.     for i = 2,16,1 do
  168.         currentChestFullness = currentChestFullness + turtle.getItemCount(i)
  169.         turtle.select(i)
  170.         turtle.drop()
  171.     end
  172.     if currentChestFullness >= 3456 then
  173.         currentChestFullness = 0
  174.         if depositChest ~= 7 then
  175.             depositChest = depositChest + 1
  176.         else
  177.             depositChest = 0
  178.         end
  179.     end
  180.     writeFile()
  181. end
  182.  
  183. function determineChest()
  184.     if depositChest <= 3 then
  185.         turtle.turnLeft()
  186.         if depositChest == 0 then
  187.             deposit()
  188.         end
  189.         if depositChest == 1 then
  190.             turtle.up()
  191.             deposit()
  192.             turtle.down()
  193.         end
  194.         if depositChest == 2 then
  195.             turtle.up()
  196.             turtle.up()
  197.             deposit()
  198.             turtle.down()
  199.             turtle.down()
  200.         end
  201.         if depositChest == 3 then
  202.             turtle.up()
  203.             turtle.up()
  204.             turtle.up()
  205.             deposit()
  206.             turtle.down()
  207.             turtle.down()
  208.             turtle.down()
  209.         end
  210.         turtle.turnRight()
  211.     end
  212.     if depositChest >= 4 then
  213.         turtle.turnRight()
  214.         if depositChest == 4 then
  215.             deposit()
  216.         end
  217.         if depositChest == 5 then
  218.             turtle.up()
  219.             deposit()
  220.             turtle.down()
  221.         end
  222.         if depositChest == 6 then
  223.             turtle.up()
  224.             turtle.up()
  225.             deposit()
  226.             turtle.down()
  227.             turtle.down()
  228.         end
  229.         if depositChest == 7 then
  230.             turtle.up()
  231.             turtle.up()
  232.             turtle.up()
  233.             deposit()
  234.             turtle.down()
  235.             turtle.down()
  236.             turtle.down()
  237.         end
  238.         turtle.turnLeft()
  239.     end
  240. end
  241.  
  242. function returnHome()
  243.     while y > 0 do
  244.         if turtle.down() then
  245.             y = y - 1
  246.         else
  247.             turtle.digDown()
  248.         end
  249.     end
  250.     while x > 0 do
  251.         if turtle.back() then
  252.             x = x - 1
  253.         end
  254.     end
  255. end
  256.  
  257. while true do
  258.  
  259.     local event, p1 = os.pullEvent("turtle_inventory")
  260.  
  261.     sleep(5)
  262.  
  263.     readFile()
  264.  
  265.     countWood()
  266.  
  267.     printData()
  268.  
  269.     if oakTotal + birchTotal > size then
  270.         makeChests()
  271.         while x < xmax do
  272.             if turtle.forward() then
  273.                 x = x + 1
  274.             else
  275.                 digFour()
  276.             end
  277.         end
  278.         fullChest()
  279.     end
  280.  
  281.     returnHome()
  282.  
  283.     printData()
  284.    
  285.     sleep(1)
  286.  
  287.     while x < xmax - 2 do
  288.         if turtle.forward() then
  289.             x = x + 1
  290.         else
  291.             digFour()
  292.         end
  293.     end
  294.  
  295.     determineChest()
  296.  
  297.     returnHome()
  298.  
  299.     printData()
  300.  
  301. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement