Advertisement
rhn

FurnaceTender

rhn
Mar 21st, 2020
277
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.42 KB | None | 0 0
  1. coalbox=peripheral.wrap("back")
  2. orebox=peripheral.wrap("top")
  3. sides={"north","south","west","east"}
  4. if (fs.exists("choices") == false) then --Check if this is first time run, no saved choices on file
  5.     while true do --Asks for side for attached inventory
  6.             print("Which direction is the back of the computer facing?")
  7.             for i=1, #sides do
  8.                 print(i..". "..sides[i])
  9.             end
  10.             local answer = read()
  11.             if tonumber(answer)==nill then
  12.                 print("-Wrong answer, input not a number-")
  13.             else
  14.                 local answerv = tonumber(string.format("%." .. 0 .. "f", answer))
  15.                 if (0 < answerv and answerv <= 4) then
  16.                     side1=answerv
  17.                     --print("Side ", sides[side1], " chosen")
  18.                     break
  19.                 else
  20.                     print("-Wrong answer, input does not match number of sides-")
  21.                 end
  22.             end
  23.     end
  24. local file = fs.open("choices","w")
  25. file.writeLine("side1="..tostring(side1))
  26. file.close()
  27. end
  28. os.loadAPI("choices") -- Reads choices from file
  29. local side1 = choices.side1
  30.  
  31. while true do
  32. --fuel refill
  33. refueled=false
  34. nofuel=false
  35. while refueled==false and nofuel==false do
  36.     for i=1,coalbox.size() do
  37.         if coalbox.getItemMeta(i) ~= nil then
  38.             coalbox.pushItems("up",i,64,2)
  39.             refueled=true
  40.             break
  41.         elseif i==coalbox.size() then
  42.             --print("Fuel box empty")
  43.             nofuel=true
  44.             --print("nofuel true")
  45.             break
  46.         else
  47.             sleep(0.05)
  48.         end
  49.     end
  50. end
  51.  
  52. --load smelting material
  53. reloaded=false
  54. noore=false
  55. output=true
  56. while reloaded==false and noore==false do
  57.     orebox.pullItems(sides[side1],3,64,orebox.size())
  58.     if orebox.getItemMeta(orebox.size()) == nil then
  59.         output=false
  60.         --print("output false")
  61.     end
  62.     orebox.pushItems("up",orebox.size(),64)
  63.  
  64.     for i=1,orebox.size()-1 do
  65.         if orebox.getItemMeta(i) ~= nil then
  66.             orebox.pushItems(sides[side1],i,64,1)
  67.             reloaded=true
  68.             break
  69.         elseif i==orebox.size()-1 then
  70.             --print("Ore box empty")
  71.             noore=true
  72.             --print("noore true")
  73.             break
  74.         else
  75.             sleep(0.05)
  76.         end
  77.     end
  78. end
  79.  
  80. if noore==true and output==false then
  81.     print("No ore, sleeping 8s")
  82.     redstone.setOutput("front", true)
  83.     sleep(8)
  84. elseif nofuel==true and output==false then
  85.     print("No fuel, sleeping 30s")
  86.     redstone.setOutput("front", true)
  87.     sleep(30)
  88. else
  89.     redstone.setOutput("front", false)
  90.     sleep(1)
  91. end
  92.  
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement