Advertisement
MrKey2b

auto

Oct 25th, 2023 (edited)
845
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.07 KB | None | 0 0
  1. -- Recherchez la périphérie ME Bridge
  2. me = peripheral.wrap("meBridge_1")
  3.  
  4. -- Recherchez la périphérie Monitor
  5. mon = peripheral.wrap("top")
  6.  
  7. label = "CPU's Crafting"
  8.  
  9. -- Liste des articles à surveiller
  10. local itemsToCheck = {
  11.     "electrodynamics:motor"
  12. }
  13.  
  14. function prepareMonitor()
  15.     mon.clear()
  16.     CenterT(label, 1, colors.black, colors.white, "head", false)
  17. end
  18.  
  19. -- Une fonction pour imprimer le texte centré sur le moniteur
  20. function CenterT(text, line, txtback, txtcolor, pos, clear)
  21.     monX, monY = mon.getSize()
  22.     mon.setTextColor(txtcolor)
  23.     length = string.len(text)
  24.     dif = math.floor(monX - length)
  25.     x = math.floor(dif / 2)
  26.  
  27.     if pos == "head" then
  28.         mon.setCursorPos(x + 1, line)
  29.         mon.write(text)
  30.     elseif pos == "left" then
  31.         if clear then
  32.             clearBox(2, 2 + length, line, line)
  33.         end
  34.         mon.setCursorPos(2, line)
  35.         mon.write(text)
  36.     elseif pos == "right" then
  37.         if clear then
  38.             clearBox(monX - length - 8, monX, line, line)
  39.         end
  40.         mon.setCursorPos(monX - length, line)
  41.         mon.write(text)
  42.     end
  43. end
  44.  
  45. -- Une fonction pour effacer une zone spécifique
  46. function clearBox(xMin, xMax, yMin, yMax)
  47.     mon.setBackgroundColor(colors.black)
  48.     for xPos = xMin, xMax, 1 do
  49.         for yPos = yMin, yMax do
  50.             mon.setCursorPos(xPos, yPos)
  51.             mon.write(" ")
  52.         end
  53.     end
  54. end
  55.  
  56. prepareMonitor()
  57.  
  58. while true do
  59.     mon.clear()
  60.     CenterT(label, 1, colors.black, colors.white, "head", false)
  61.     CenterT("Crafting Items:", 3, colors.black, colors.yellow, "left", false)
  62.  
  63.     -- Vérifiez l'état de chaque article spécifique
  64.     local line = 5
  65.     for _, itemName in ipairs(itemsToCheck) do
  66.         local isCrafting = me.isItemCrafting({ name = itemName })
  67.         local status = isCrafting and "Crafting" or "Not Crafting"
  68.         mon.setCursorPos(2, line)
  69.         mon.write(itemName .. " - " .. status)
  70.         line = line + 1
  71.     end
  72.  
  73.     sleep(5) -- Attendez quelques secondes avant de rafraîchir la liste
  74. end
  75.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement