Advertisement
Vodka51200

afficheBlockMinedNether

Jul 10th, 2024 (edited)
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.76 KB | Gaming | 0 0
  1. local mon = peripheral.find("monitor") -- Remplacez "monitor" par le nom de votre moniteur
  2. local mod = peripheral.find("modem") -- Remplacez "modem" par le nom de votre modem
  3.  
  4. -- Affiche la largeur de l'écran
  5. --print("Largeur de l'écran :", screenWidth)
  6. -- Affiche la hauteur de l'écran
  7. --print("Hauteur de l'écran :", screenHeight)
  8.  
  9. if mon == nil then
  10.   print("Monitor not found. Please connect a monitor and try again.")
  11.   return
  12. end
  13.  
  14. if mod == nil then
  15.   print("Modem not found. Please connect a modem and try again.")
  16.   return
  17. end
  18.  
  19. mod.open(1)
  20. --mon.clear()
  21. mon.setTextScale(0.5)
  22. mon.setPaletteColour(colors.yellow, 0x018281) -- win 95/98
  23. mon.setBackgroundColor(colors.yellow)
  24. --mon.clear()
  25. --local longueurBase = 13 -- Longueur de base pour les caractères fixes ("- ", " (Type: ", " x")
  26. local longueurBase = 7  -- Longueur de base pour les caractères fixes ("- ", " (Type: ", " x")
  27. local typeLength = 6   -- Length of " (Type: "
  28. local variantLength = 9  -- Length of " (Variant: "
  29. local test1 = longueurBase + typeLength
  30. local test2 = longueurBase + variantLength
  31.  
  32. local newsom = 0
  33. local oldsom = 0
  34. local oldsom2 = 0
  35. local oldsom3 = 0
  36.  
  37. local screenWidth, screenHeight = mon.getSize()
  38.  
  39. if screenWidth == nil then
  40.   print("Erreur: impossible de récupérer la largeur de l'écran.")
  41.   return
  42. end
  43.  
  44. local column2 = screenWidth / 2 --recupere la moitier de l'ecran
  45.  
  46. local config = true
  47.  
  48. if config == true then
  49.   linemax = 10
  50. else
  51.   linemax = screenHeight
  52. end
  53.  
  54. --local line = 1
  55. --local column = 1
  56. --local newcolumn = 1
  57.  
  58. while true do
  59.   local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
  60.   local receivedBlocks = textutils.unserializeJSON(message)
  61.  
  62.   mon.clear()
  63.   --mon.setTextScale(0.5)
  64.   local line = 1
  65.   local column = 1
  66.   local newcolumn = 1
  67.  
  68.   mon.setCursorPos(column, line)
  69.   mon.write("Blocks Mined:")
  70.  
  71.   for block, data in pairs(receivedBlocks) do --for block, count in pairs(receivedBlocks) do
  72.     if line > linemax - 1 then  -- Vérification de changement de ligne
  73.       if newcolumn == 3 then
  74.         oldsom3 = oldsom2 + newsom
  75.         --newsom = 0
  76.       elseif newcolumn == 2 then
  77.         oldsom2 = oldsom + newsom
  78.         --newsom = 0
  79.       else
  80.         oldsom = newsom
  81.       end
  82.  
  83.       if newcolumn == 3 then
  84.         column = oldsom3 + 1
  85.         --line = 1
  86.         --mon.setCursorPos(column, line)
  87.         --newcolumn = newcolumn + 1
  88.       elseif newcolumn == 2 then
  89.         column = oldsom2 + 1
  90.         --line = 1
  91.         --mon.setCursorPos(column, line)
  92.         --newcolumn = newcolumn + 1
  93.       else
  94.         column = oldsom + 1
  95.         --line = 1
  96.         --mon.setCursorPos(column, line)
  97.         --newcolumn = newcolumn + 1
  98.       end
  99.       newsom = 0
  100.       newcolumn = newcolumn + 1
  101.       line = 1
  102.       mon.setCursorPos(column, line)
  103.     end
  104.  
  105.     line = line + 1
  106.     mon.setCursorPos(column, line)
  107.  
  108.     local colonIndex = string.find(block, ":", 1, true)
  109.     local name = string.sub(block, 1, colonIndex - 1)
  110.     local metadata = string.sub(block, colonIndex + 1)
  111.  
  112.     longueurNom = string.len(name)
  113.     longueurType = string.len(metadata) or 0 -- Handle cases where metadata is absent
  114.     longueurQuantite = string.len(tostring(data.count))  -- Convertir la quantité en chaîne de caractères
  115.    
  116.     if name == "tconstruct" then
  117.       test3 = test1
  118.     elseif name == "biomesoplenty" then
  119.       test3 = test2
  120.     else
  121.       test3 = 7
  122.     end
  123.  
  124.     -- Calculer la longueur totale estimée
  125.     --local longueurTotale = longueurBase + longueurNom + longueurType + longueurQuantite
  126.     local longueurTotale = test3 + longueurNom + longueurType + longueurQuantite
  127.     if longueurTotale > screenWidth then
  128.       print("Erreur: augmenter la largeur de l'écran.")
  129.       return
  130.     end
  131.     if longueurTotale > newsom then
  132.       newsom = longueurTotale
  133.     end
  134.     --line = line + 1
  135.     --mon.setCursorPos(column, line)
  136.     ----mon.write("- " .. name .. " (Type: " .. metadata .. ") x" .. data.count)
  137.     if name == "tconstruct" then
  138.       mon.write(string.format("-%s (Type: %s) x%d", name, metadata, data.count))
  139.     elseif name == "biomesoplenty" then
  140.       mon.write(string.format("-%s (Variant: %s) x%d", name, metadata, data.count))
  141.     else
  142.       mon.write(string.format("-%s (%s) x%d", name, metadata, data.count))
  143.     end
  144.     --mon.write(string.format("-%s (Type: %s) x%d", name, metadata, data.count))
  145.   end
  146.   mon.setCursorPos(column2 - string.len("Longueur maximale estimée : %d l x%d h x%d")/2, 1)
  147.   -- Afficher la longueur maximale calculée
  148.   mon.write(string.format("Longueur maximale estimée : %d l x%d h x%d", newsom, screenWidth, screenHeight))  -- Affichage clair
  149.   --mon.write("Longueur maximale estimée :", newsom)
  150. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement