Advertisement
PiggyWhiskey

Heated Redstone Generator

May 24th, 2014
255
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.97 KB | None | 0 0
  1. --[[
  2. Little LUA code by PiggyWhiskey
  3. This will work for any Extra Utilites Generator that has a linear fuel calculation
  4. High-Temp Furnace Generator won't work
  5. Potion Generator will only work if they have the same level of potion etc etc
  6.  
  7. Please feel free to use however you want...but let me have the original credit :)
  8. --]]
  9. local gen = peripheral.wrap("left") --Redstone Generator
  10. local eCell = peripheral.wrap("back") --Energy Cell
  11.  
  12. local productionTime = 250 -- Fuel Burn Time (Furnace = 15, Molten Redstone = 250)
  13. local energyPerTick = 320  -- Fuel RF/t (Furnace = 80, Molten Redstone = 320)
  14. local energyProduced = productionTime * energyPerTick * 20 -- Total RF Generated
  15.  
  16. --t1 = Time burn started
  17. --t2 = Current time
  18. local t1 = os.clock()
  19. local t2
  20.  
  21. local burning = false
  22. local needBurn = false
  23.  
  24. local genMax = 0
  25. local genCur = 0
  26. local cellMax = 0
  27. local cellCur = 0
  28.  
  29. local so = redstone.setOutput
  30.  
  31. function getEnergyValues()
  32.   genMax = tonumber(gen.getMaxEnergyStored("left"))
  33.   genCur = tonumber(gen.getEnergyStored("left"))
  34.  
  35.   cellMax = tonumber(eCell.getMaxEnergyStored("left"))
  36.   cellCur = tonumber(eCell.getEnergyStored("left"))
  37. end
  38.  
  39. function checkNeedBurn()
  40.   getEnergyValues()
  41.   if ((genMax + cellMax) - (genCur + cellCur)) >= energyProduced then
  42.     needBurn = true
  43.   else
  44.     needBurn = false
  45.   end
  46. end
  47.  
  48. function burn()
  49.   so("top",true)
  50.   sleep(0.1)
  51.   so("top",false)
  52.   burning=true
  53. end
  54.  
  55. while true do
  56.   t2 = os.clock()
  57.  
  58.   --If I'm not burning...do I need to be?
  59.   if not burning then
  60.     --Do I Need more fuel?
  61.     checkNeedBurn()
  62.     if needBurn then
  63.       --Burn another lot of Fuel and reset burn timer
  64.       burn()
  65.       t1=os.clock()
  66.     end
  67.   end
  68.  
  69.   --Burn has finished...reset the variable
  70.   if (t2 - t1) >= productionTime then
  71.     burning = false
  72.   end
  73.  
  74.   --Print current timer
  75.   print("Time: "..t2-t1)
  76.   print("Burning: "..tostring(burning))
  77.   print("Need Burn: "..tostring(needBurn))      
  78.   sleep(1)
  79. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement