Advertisement
BigBlow_

fusionReactorMonitoring

Mar 13th, 2025 (edited)
28
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.30 KB | None | 0 0
  1. -- Configuration
  2. local reactor_name = "fusionReactorLogicAdapter_1" -- Nom du peripheral du reacteur
  3. local redstone_output_face = "top" -- Face ou envoyer la redstone si le reacteur est eteint
  4. local redstone_start_face = "left" -- Face ou envoyer un pulse pour demarrer le reacteur
  5. local redstone_pulse_time = 1 -- Duree du pulse en secondes
  6.  
  7. -- Initialisation du moniteur
  8. local monitor = peripheral.find("monitor")
  9. if not monitor then
  10. error("Aucun ecran detecte")
  11. end
  12.  
  13. -- Initialisation du reacteur
  14. local reactor = peripheral.wrap(reactor_name)
  15. if not reactor then
  16. error("Reactor not detected: " .. reactor_name)
  17. end
  18. monitor.clear()
  19. monitor.setTextScale(1)
  20. monitor.setTextColor(colors.white)
  21.  
  22. -- Coordonnees du bouton
  23. local button_x1, button_y1 = 2, 7
  24. local button_x2, button_y2 = 18, 9
  25.  
  26. -- Variables de suivi
  27. local last_ignited = nil
  28. local ignition_in_progress = false -- EmpĂȘche le double envoi du signal
  29.  
  30. -- Fonction pour formater les nombres avec des espaces
  31. local function formatNumber(n)
  32. return tostring(n):reverse():gsub("(%d%d%d)", "%1 "):reverse():gsub("^ ", "")
  33. end
  34.  
  35. -- Fonction pour afficher les informations
  36. local function displayInfo()
  37. local ignited = reactor.isIgnited()
  38. monitor.clear()
  39. -- Affichage du titre
  40. monitor.setCursorPos(1, 1)
  41. monitor.write("Fusion Reactor Controller")
  42. -- Ligne vide entre le titre et les infos
  43. monitor.setCursorPos(1, 3)
  44. monitor.write("")
  45. -- Affichage du statut du reacteur
  46. monitor.setCursorPos(1, 4)
  47. monitor.write("Reactor Status :")
  48. monitor.setCursorPos(1, 5)
  49. if ignited then
  50. monitor.setTextColor(colors.green)
  51. monitor.write("Ignited")
  52. redstone.setOutput(redstone_output_face, false) -- Desactiver la redstone
  53. ignition_in_progress = false -- Reinitialiser l'etat apres allumage
  54. else
  55. monitor.setTextColor(colors.red)
  56. monitor.write("Stopped")
  57. redstone.setOutput(redstone_output_face, true) -- Activer la redstone
  58. end
  59. -- Remise de la couleur en blanc apres l'affichage du statut
  60. monitor.setTextColor(colors.white)
  61. if ignited then
  62. -- Ligne vide avant la production d'energie
  63. monitor.setCursorPos(1, 7)
  64. monitor.write("")
  65. -- Affichage de la production d'energie
  66. local production = reactor.getProductionRate()
  67. local productionRF = production / 2.5 -- Conversion de J en RF
  68. monitor.setCursorPos(1, 8)
  69. monitor.write("Energy Production")
  70. monitor.setCursorPos(1, 9)
  71. monitor.write(formatNumber(productionRF) .. " RF/t")
  72. else
  73. if ignition_in_progress then
  74. -- Affichage du message "Reactor ignition started"
  75. monitor.setCursorPos(1, 7)
  76. monitor.write("Reactor ignition")
  77. monitor.setCursorPos(1, 8)
  78. monitor.write("started...")
  79. else
  80. -- Affichage du bouton "START REACTOR"
  81. monitor.setCursorPos(button_x1, button_y1)
  82. monitor.setBackgroundColor(colors.gray)
  83. monitor.setTextColor(colors.white)
  84. monitor.write(" START REACTOR ")
  85. -- Remise a zero des couleurs apres le bouton
  86. monitor.setBackgroundColor(colors.black)
  87. monitor.setTextColor(colors.white)
  88. end
  89. end
  90. last_ignited = ignited
  91. end
  92.  
  93. -- Fonction pour gerer le clic sur le bouton
  94. local function checkTouch()
  95. while true do
  96. local event, side, x, y = os.pullEvent("monitor_touch")
  97. if not reactor.isIgnited() and not ignition_in_progress then
  98. if x >= button_x1 and x <= button_x2 and y >= button_y1 and y <= button_y2 then
  99. -- Definir l'etat "ignition en cours"
  100. ignition_in_progress = true
  101. displayInfo() -- Rafraichir pour afficher "Reactor ignition started"
  102. -- Envoi du pulse de redstone sur la face choisie
  103. redstone.setOutput(redstone_start_face, true)
  104. sleep(redstone_pulse_time)
  105. redstone.setOutput(redstone_start_face, false)
  106. end
  107. end
  108. end
  109. end
  110.  
  111. -- Boucle de mise a jour en continu
  112. parallel.waitForAny(
  113. function()
  114. while true do
  115. displayInfo()
  116. sleep(1)
  117. end
  118. end,
  119. checkTouch
  120. )
  121.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement