MrKey2b

autocraft

Oct 25th, 2023 (edited)
1,073
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.59 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. function prepareMonitor()
  10.     mon.clear()
  11.     CenterT(label, 1, colors.black, colors.white, "head", false)
  12. end
  13.  
  14. -- Une fonction pour imprimer le texte centré sur le moniteur
  15. function CenterT(text, line, txtback, txtcolor, pos, clear)
  16.     monX, monY = mon.getSize()
  17.     mon.setTextColor(txtcolor)
  18.     length = string.len(text)
  19.     dif = math.floor(monX - length)
  20.     x = math.floor(dif / 2)
  21.  
  22.     if pos == "head" then
  23.         mon.setCursorPos(x + 1, line)
  24.         mon.write(text)
  25.     elseif pos == "left" then
  26.         if clear then
  27.             clearBox(2, 2 + length, line, line)
  28.         end
  29.         mon.setCursorPos(2, line)
  30.         mon.write(text)
  31.     elseif pos == "right" then
  32.         if clear then
  33.             clearBox(monX - length - 8, monX, line, line)
  34.         end
  35.         mon.setCursorPos(monX - length, line)
  36.         mon.write(text)
  37.     end
  38. end
  39.  
  40. -- Une fonction pour effacer une zone spécifique
  41. function clearBox(xMin, xMax, yMin, yMax)
  42.     mon.setBackgroundColor(colors.black)
  43.     for xPos = xMin, xMax, 1 do
  44.         for yPos = yMin, yMax do
  45.             mon.setCursorPos(xPos, yPos)
  46.             mon.write(" ")
  47.         end
  48.     end
  49. end
  50.  
  51. prepareMonitor()
  52.  
  53. while true do
  54.     mon.clear()
  55.     CenterT(label, 1, colors.black, colors.white, "head", false)
  56.     CenterT("Crafting Items:", 3, colors.black, colors.yellow, "left", false)
  57.  
  58.     -- Vérifiez si la méthode listCraftingJobs existe
  59.     if me.listCraftingJobs then
  60.         -- Obtenez la liste des articles en cours de craft
  61.         local craftingJobs = me.listCraftingJobs()
  62.  
  63.         -- Vérifiez si la liste n'est pas nulle avant de l'afficher
  64.         if craftingJobs then
  65.             -- Affichez la liste des articles en cours de craft
  66.             local line = 5
  67.             for _, job in ipairs(craftingJobs) do
  68.                 local isCrafting = me.isItemCrafting({ name = job.name })
  69.                 local status = isCrafting and "Crafting" or "Not Crafting"
  70.                 mon.setCursorPos(2, line)
  71.                 mon.write(job.name .. " - " .. status)
  72.                 line = line + 1
  73.             end
  74.         else
  75.             CenterT("No crafting jobs.", 5, colors.black, colors.red, "left", false)
  76.         end
  77.     else
  78.         CenterT("Whoula la metode que j’appelle n'ai pas dispo.. Connard !", 5, colors.black, colors.red, "left", false)
  79.     end
  80.  
  81.     sleep(5) -- Attendez quelques secondes avant de rafraîchir la liste
  82. end
  83.  
Advertisement
Add Comment
Please, Sign In to add comment