Advertisement
BigBlow_

MobFarm-Global-Controller

Mar 14th, 2025 (edited)
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.70 KB | None | 0 0
  1. -- Configuration des spawners (Liste 1 + Liste 2)
  2. local spawnersList1 = {
  3. {id = 51, name = "Mob Mashers"},
  4. {id = 52, name = "Mob Fans"},
  5. {id = 53, name = "Lamps"},
  6. {id = 54, name = "Void Mod"},
  7. {id = 55, name = "Blood Cleaner"}
  8. }
  9.  
  10. local spawnersList2 = {
  11. {id = 1, name = "Cave Creeper"},
  12. {id = 2, name = "Blaze"},
  13. {id = 3, name = "Ancient Knight"},
  14. {id = 4, name = "Enderman"},
  15. {id = 5, name = "Witch"},
  16. {id = 6, name = "Cave Enderman"},
  17. {id = 7, name = "Creeper"},
  18. {id = 8, name = "Wither Skeleton"},
  19. {id = 9, name = "Drowned"},
  20. {id = 10, name = "Deepling"},
  21. {id = 11, name = "Slime"},
  22. {id = 12, name = "Magma Slime"},
  23. {id = 13, name = "Skeleton"},
  24. {id = 14, name = "Evoker"}
  25. }
  26.  
  27. -- Liste des spawners actifs au demarrage
  28. local activatedSpawners = {51, 52, 53, 55}
  29.  
  30. -- Canal du modem (modifiable ici)
  31. local channel = 128 -- Change ce nombre pour choisir un autre canal
  32.  
  33. -- Timestamp pour les logs
  34. local function getTimestamp()
  35. return os.date("%Y-%m-%d %H:%M:%S")
  36. end
  37.  
  38. -- Detection du modem et ecran
  39. local modem = peripheral.find("modem")
  40. if not modem then error("Aucun modem sans fil detecte") end
  41. modem.open(channel)
  42.  
  43. local mon = peripheral.find("monitor")
  44. if not mon then error("Aucun ecran detecte") end
  45. mon.setTextScale(1)
  46.  
  47. -- Etat des spawners
  48. local state = {}
  49. for _, s in ipairs(spawnersList1) do state[s.id] = false end
  50. for _, s in ipairs(spawnersList2) do state[s.id] = false end
  51.  
  52. -- Ecran de demarrage
  53. local function startupScreen()
  54. mon.clear()
  55. for i = 5, 0, -1 do
  56. mon.setCursorPos(5, 3)
  57. mon.setTextColor(colors.white)
  58. mon.write("Demarrage dans " .. i)
  59. mon.setCursorPos(5, 5)
  60. mon.setTextColor(colors.yellow)
  61. mon.write("[Passer]")
  62. local timer = os.startTimer(1)
  63. while true do
  64. local event, side, x, y = os.pullEvent()
  65. if event == "timer" and side == timer then break
  66. elseif event == "monitor_touch" and x >= 5 and x <= 11 and y == 5 then return end
  67. end
  68. end
  69. end
  70.  
  71. -- Desactivation globale sauf liste active
  72. local function deactivateAllExceptActivated()
  73. local function isActive(id)
  74. for _, activeID in ipairs(activatedSpawners) do
  75. if id == activeID then return true end
  76. end
  77. return false
  78. end
  79.  
  80. for _, s in ipairs(spawnersList1) do
  81. if not isActive(s.id) then
  82. modem.transmit(channel, channel, {id = s.id, state = false})
  83. print(getTimestamp() .. " - ID " .. s.id .. " OFF")
  84. os.sleep(0.1)
  85. end
  86. end
  87. for _, s in ipairs(spawnersList2) do
  88. if not isActive(s.id) then
  89. modem.transmit(channel, channel, {id = s.id, state = false})
  90. print(getTimestamp() .. " - ID " .. s.id .. " OFF")
  91. os.sleep(0.1)
  92. end
  93. end
  94. end
  95.  
  96. -- Activation des spawners de la liste
  97. local function activateSpawnersOnStart()
  98. for _, id in ipairs(activatedSpawners) do
  99. modem.transmit(channel, channel, {id = id, state = true})
  100. print(getTimestamp() .. " - ID " .. id .. " ON")
  101. os.sleep(0.1)
  102. state[id] = true
  103. end
  104. end
  105.  
  106. -- Interface
  107. local function drawUI()
  108. mon.clear()
  109. mon.setTextColor(colors.white)
  110. mon.setCursorPos(1, 1)
  111. mon.write("System Control Panel :")
  112.  
  113. for i, s in ipairs(spawnersList1) do
  114. mon.setCursorPos(1, i + 2)
  115. mon.setTextColor(colors.white)
  116. mon.write(s.name)
  117. mon.setCursorPos(20, i + 2)
  118. if state[s.id] then
  119. mon.setTextColor(colors.green)
  120. mon.write("ON")
  121. else
  122. mon.setTextColor(colors.red)
  123. mon.write("OFF")
  124. end
  125. end
  126.  
  127. mon.setCursorPos(1, #spawnersList1 + 4)
  128. mon.setTextColor(colors.white)
  129. mon.write("Spawners Control Panel :")
  130.  
  131. for i, s in ipairs(spawnersList2) do
  132. mon.setCursorPos(1, i + #spawnersList1 + 5)
  133. mon.setTextColor(colors.white)
  134. mon.write(s.name)
  135. mon.setCursorPos(20, i + #spawnersList1 + 5)
  136. if state[s.id] then
  137. mon.setTextColor(colors.green)
  138. mon.write("ON")
  139. else
  140. mon.setTextColor(colors.red)
  141. mon.write("OFF")
  142. end
  143. end
  144. end
  145.  
  146. -- Envoi d'une commande
  147. local function sendCommand(id, newState)
  148. modem.transmit(channel, channel, {id = id, state = newState})
  149. print(getTimestamp() .. " - ID " .. id .. " " .. (newState and "ON" or "OFF"))
  150. os.sleep(0.1)
  151. end
  152.  
  153. -- Gestion clics sur l'ecran
  154. local function handleClick(x, y)
  155. local index1 = y - 2
  156. local index2 = y - (#spawnersList1 + 5)
  157.  
  158. if spawnersList1[index1] then
  159. local s = spawnersList1[index1]
  160. state[s.id] = not state[s.id]
  161. sendCommand(s.id, state[s.id])
  162. drawUI()
  163. elseif spawnersList2[index2] then
  164. local s = spawnersList2[index2]
  165. state[s.id] = not state[s.id]
  166. sendCommand(s.id, state[s.id])
  167. drawUI()
  168. end
  169. end
  170.  
  171. -- Reception messages modem
  172. local function listenForMessages()
  173. while true do
  174. local _, _, _, _, msg = os.pullEvent("modem_message")
  175. if msg and msg.id and msg.state ~= nil then
  176. state[msg.id] = msg.state
  177. print(getTimestamp() .. " - Recu <- ID " .. msg.id .. " " .. (msg.state and "ON" or "OFF"))
  178. drawUI()
  179. end
  180. end
  181. end
  182.  
  183. -- Lancement
  184. startupScreen()
  185. deactivateAllExceptActivated()
  186. activateSpawnersOnStart()
  187. drawUI()
  188.  
  189. -- Execution parallele
  190. parallel.waitForAny(listenForMessages, function()
  191. while true do
  192. local event, side, x, y = os.pullEvent("monitor_touch")
  193. handleClick(x, y)
  194. end
  195. end)
  196.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement