Advertisement
MinoCraft72

Power Monitor [CC/AP-MC 1.16+]

Apr 30th, 2022
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.99 KB | None | 0 0
  1. -- Config:
  2.  
  3.  batSide = "rftoolspower:cell3_1"
  4.  batMods = "rftools"
  5.  minCharge = 15
  6.  maxCharge = 100
  7.  outSide = "bottom"
  8.  monSide = "monitor_0"
  9.  
  10. -- Prog:
  11.  
  12. --term.clear()
  13. bat = peripheral.wrap(batSide)
  14.  
  15. if monSide ~= " " then
  16.  mon = peripheral.wrap(monSide)
  17. end
  18. makeRF = false
  19. stateColor = colors.orange
  20.  
  21. function monitor()
  22.  prod = tostring(makeRF)
  23.  mon.clear()
  24.  mon.setCursorPos(1,1)
  25.  mon.setTextColor(colors.white)
  26.  mon.write("Energy Storage")
  27.  mon.setCursorPos(1,3)
  28.  mon.write(energy.."/"..capacity.." RF")
  29.  progressBar = math.ceil((percent*17)/100)
  30.   if percent >= 0 and percent < 25 then
  31.    progressColor = colors.red
  32.   elseif percent >= 25 and percent < 50 then
  33.    progressColor = colors.orange
  34.   elseif percent >= 50 and percent < 75 then
  35.    progressColor = colors.yellow
  36.   elseif percent >= 75 and percent <= 100 then
  37.    progressColor = colors.lime
  38.   end
  39.   mon.setCursorPos(1,5)
  40.   mon.clearLine()
  41.   for i = 0,progressBar do
  42.    mon.setCursorPos(i,5)
  43.    mon.setBackgroundColor(progressColor)
  44.    mon.write(" ")
  45.    mon.setBackgroundColor(colors.black)
  46.    mon.setTextColor(dataColor)
  47.    mon.write(" "..tostring(rate))
  48.    mon.setTextColor(colors.white)
  49.    mon.write(" RF/t")
  50.   end
  51.  mon.setBackgroundColor(colors.black)
  52.  mon.setCursorPos(1,7)
  53.  mon.write("Info:")
  54.  mon.setCursorPos(1,8)
  55.  mon.write(percent.."% (Need: "..needed.." RF)")
  56.  mon.setCursorPos(1,9)
  57.  mon.write("Production: ")
  58.  mon.setTextColor(stateColor)
  59.  mon.write(prod)
  60. end
  61.  
  62. time_new = os.time()
  63. while true do
  64. time_old = time_new
  65. sleep(0.2)
  66. time_new = os.time()
  67.   if batMods == "mekanism" then
  68.    energy = bat.getTotalEnergy()
  69.    capacity = bat.getTotalMaxEnergy()
  70.    needed = bat.getTotalEnergyNeeded()
  71.    percent = bat.getTotalEnergyFilledPercentage() *100
  72.   elseif batMods == "rftools" then
  73.    energy = bat.getEnergy()
  74.    capacity = bat.getEnergyCapacity()
  75.    needed = capacity - energy
  76.    percent = math.ceil((energy*100)/capacity)
  77.   end
  78. getEnergy_temp = energy
  79. --sleep(0)
  80.   if batMods == "mekanism" then
  81.    getEnergy = bat.getTotalEnergy()
  82.   elseif batMods == "rftools" then
  83.    getEnergy = bat.getEnergy()
  84.   end
  85. time_delta = os.time() - time_old
  86. print(time_old)
  87. print(tonumber(os.time()))
  88. print(time_delta)
  89. rate = math.ceil(((getEnergy - getEnergy_temp)/time_delta)/1000)
  90.  
  91. term.clear()
  92. term.setCursorPos(1,3)
  93. print("Energy Data: "..percent.."%")
  94. print(energy.."/"..capacity.." RF")
  95. print("Need: "..needed.." RF")
  96.   if rate < 0 then
  97.    dataColor = colors.red
  98.   else
  99.    dataColor = colors.lime
  100.   end
  101. write("Rate: ")
  102. term.setTextColor(dataColor)
  103. write(rate)
  104. term.setTextColor(colors.white)
  105. print(" RF/t")
  106.  
  107.   if percent < minCharge then
  108.    print("Current State: Generate Power ...")
  109.    stateColor = colors.lime
  110.    makeRF = true
  111.   elseif percent >= maxCharge then
  112.    print("Current State: Waiting ...")
  113.    stateColor = colors.orange
  114.    makeRF = false
  115.   end
  116.  
  117.   monitor()
  118.  
  119.   if makeRF then
  120.    rs.setOutput(outSide,true)
  121.   else
  122.    rs.setOutput(outSide,false)
  123.   end
  124. end
  125.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement