Advertisement
Pankola

Mekanism Monitor Screen

May 19th, 2023 (edited)
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.45 KB | None | 0 0
  1. --Fontion text
  2. function putValue (line, text, color)
  3.     local align = 30 - string.len(text)
  4.     term.setCursorPos(align, line)
  5.     term.setTextColor(color)
  6.     print(text)
  7.   end
  8.  
  9. --Fonction nombre
  10. function putNumber (number)
  11.   local round = 0
  12.   local texts = ""
  13.  
  14.   if number >= 1000000000000000000 then
  15.     round = (number / 1000000000000000000)
  16.     texts = string.sub(round, 0, 5) .. " ERF"
  17.   else
  18.     if number >= 1000000000000000 then
  19.       round = (number / 1000000000000000)
  20.       texts = string.sub(round, 0, 5) .. " PRF"
  21.     else
  22.       if number >= 1000000000000 then
  23.         round = (number / 1000000000000)
  24.         texts = string.sub(round, 0, 5) .. " TRF"
  25.       else
  26.         if number >= 1000000000 then
  27.           round = (number / 1000000000)
  28.           texts = string.sub(round, 0, 5) .. " GRF"
  29.         else
  30.           if number >= 1000000 then
  31.             round = (number / 1000000)
  32.             texts = string.sub(round, 0, 5) .. " MRF"
  33.           else
  34.             if number >= 1000 then
  35.               round = (number / 1000)
  36.               texts = string.sub(round, 0, 5) .. " kRF"
  37.             else
  38.               texts = string.sub(number, 0, 5) .. "  RF"
  39.             end
  40.           end
  41.         end
  42.       end
  43.     end
  44.   end
  45.  
  46.   return texts
  47. end
  48.  
  49. --Initialisation periphérique
  50. monitor = peripheral.wrap("top")
  51. battery = peripheral.find("inductionPort")
  52.  
  53. --Check periphérique
  54. if monitor == nil then
  55.     error("ER: Pas d'ecran trouvé")
  56. else
  57.     monitor.clear()
  58.     term.redirect(monitor)
  59.     term.setCursorPos(1, 1)
  60.     term.setBackgroundColor(colors.black)
  61. end
  62.  
  63. if battery == nil then
  64.     error("ER: Pas de batterie trouvé")
  65. end
  66.  
  67.  --Creation de l'interface
  68.  term.setCursorPos(11, 2);
  69.  print("Max RF:")
  70.  term.setCursorPos(11, 3);
  71.  print("Max Thru:")
  72.  
  73.  term.setCursorPos(11, 5);
  74.  print("Cur In:")
  75.  term.setCursorPos(11, 6);
  76.  print("Cur Out:")
  77.  term.setCursorPos(11, 7);
  78.  print("Cur Bal:")
  79.  
  80.  term.setCursorPos(11, 9);
  81.  print("Stored:")
  82.  term.setCursorPos(11, 10);
  83.  print("Filled:")
  84.  
  85. --Actualisaiton des données
  86. while true do
  87.   --donnees fixes I/O
  88.   batteryMaxCharge = battery.getMaxEnergy()
  89.   batteryMaxInOuts = battery.getTransferCap()
  90.   putValue(2, putNumber(batteryMaxCharge), colors.lightBlue)
  91.   putValue(3, putNumber(batteryMaxInOuts), colors.lightBlue)
  92.  
  93.   --Delta I/O
  94.   batteryCurrentIn = battery.getLastInput()
  95.   batteryCurrentOut = battery.getLastOutput()
  96.   putValue(5, putNumber(batteryCurrentIn), colors.lightBlue)
  97.   putValue(6, putNumber(batteryCurrentOut), colors.lightBlue)
  98.  
  99.   --Couleur et Signe I/O
  100.   batteryCurrentBalance = batteryCurrentIn - batteryCurrentOut
  101.   batteryCurrentColor = (batteryCurrentBalance >= 0) and colors.green or colors.red
  102.   batteryCurrentSign = (batteryCurrentBalance >= 0) and "+" or ""
  103.   putValue(7, batteryCurrentSign .. putNumber(batteryCurrentBalance), batteryCurrentColor)
  104.  
  105.   --Donnees fixes charge
  106.   batteryCurrentCharge = battery.getEnergy()
  107.   putValue(9, putNumber(batteryCurrentCharge), colors.lightBlue)
  108.  
  109.   --Pourcentage de charge
  110.   batteryCurrentColor = colors.red
  111.   batteryCurrentPercentage = ((batteryCurrentCharge / batteryMaxCharge) * 100)
  112.   if batteryCurrentPercentage > 30 then batteryCurrentColor = colors.orange end
  113.   if batteryCurrentPercentage > 60 then batteryCurrentColor = colors.green end
  114.   putValue(10, string.sub(putNumber(batteryCurrentPercentage), 0, 4) .. "%", batteryCurrentColor)
  115.  
  116.   --Temps d'Actualisaiton
  117.   os.sleep(0.5)
  118.  
  119.   end
  120.  
Tags: minecraft
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement