le_Fish

Autofurnace

Jul 22nd, 2019
547
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.18 KB | None | 0 0
  1. local times_swapped
  2. local counter = 120
  3.  
  4. function run()
  5.     while(true) do
  6.         print("Getting buckets")
  7.         turtle.turnRight()
  8.         for i=1,16 do
  9.             turtle.select(i)
  10.             turtle.suck(1)
  11.         end
  12.         turtle.turnRight()
  13.         print("Filling buckets")
  14.         for i=1,16 do
  15.             turtle.select(i)
  16.             turtle.place()
  17.         end
  18.         turtle.turnRight()
  19.         print("Returning buckets")
  20.         for i=1,16 do
  21.             turtle.select(i)
  22.             item_data = turtle.getItemDetail(i)
  23.             if(item_data ~= nil) then
  24.                 if(string.find(item_data.name, "lava_bucket")) then
  25.                     turtle.drop(1)
  26.                     times_swapped = times_swapped + 1
  27.                 end
  28.             end
  29.            
  30.             local h = fs.open("autofurnace/times_lavaswapped", "w")
  31.             h.writeLine(times_swapped)
  32.             h.close()
  33.         end
  34.         turtle.turnRight()
  35.         repeat
  36.             print("Swapped empty buckets with full buckets " .. times_swapped .. " times.")
  37.             print("")
  38.             print("Waiting " .. counter .. " seconds.")
  39.             sleep(1)
  40.             term.clear()
  41.             counter = counter - 1
  42.         until counter == 0
  43.         counter = 120
  44.     end
  45. end
  46.  
  47. function start()
  48.     if fs.exists("autofurnace") then
  49.         print("Furnace folder exists, probably a crash")
  50.         crashReport()
  51.         checkDirection()
  52.         crashed_checkInv()
  53.         term.clear()
  54.         run()
  55.     else
  56.         print("making folder")
  57.         fs.makeDir("autofurnace")
  58.         local h = fs.open("autofurnace/times_lavaswapped", "w")
  59.         h.writeLine(0)
  60.         h.close()
  61.         local h = fs.open("autofurnace/times_crashed", "w")
  62.         h.writeLine(0)
  63.         h.close()
  64.         checkDirection()
  65.         term.clear()
  66.         times_swapped = 0
  67.         run()
  68.     end
  69. end
  70.  
  71. function crashReport()
  72.     print("Making crash report")
  73.     local times_crashed
  74.     local h = fs.open("autofurnace/times_crashed", "r")
  75.     times_crashed = tonumber(h.readLine())
  76.     h.close()
  77.     times_crashed = times_crashed + 1
  78.     local h = fs.open("autofurnace/times_crashed", "w")
  79.     h.writeLine(times_crashed)
  80.     h.close()
  81.  
  82.     local h = fs.open("autofurnace/times_lavaswapped", "r")
  83.     times_swapped = tonumber(h.readLine())
  84.     h.close()
  85.  
  86. end
  87.  
  88. function checkDirection()
  89.     print("Getting right direction")
  90.     if turtle.forward() == false then
  91.         repeat
  92.             turtle.turnLeft()
  93.         until turtle.forward() == true
  94.     end
  95.     turtle.back()
  96. end
  97.  
  98. function crashed_checkInv()
  99.     print("Empty inventory after crash")
  100.     local item_data
  101.     for i=1,16 do
  102.         turtle.select(i)
  103.         item_data = turtle.getItemDetail(i)
  104.         if(item_data ~= nil) then
  105.             if(string.find(item_data.name, "bucket")) then
  106.                 if(item_data.count > 1) then
  107.                     turtle.turnRight()
  108.                     turtle.drop(item_data.count - 1)
  109.                     turtle.turnLeft()
  110.                 end
  111.             elseif(string.find(item_data.name, "lava_bucket")) then
  112.                 turtle.turnLeft()
  113.                 turtle.drop()
  114.                 turtle.turnRight()
  115.             else
  116.                 turtle.dropDown(item_data.count)
  117.             end
  118.         end
  119.     end
  120. end
  121.  
  122. start()
Advertisement
Add Comment
Please, Sign In to add comment