Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local mon = peripheral.find("monitor") -- Remplacez "monitor" par le nom de votre moniteur
- local mod = peripheral.find("modem") -- Remplacez "modem" par le nom de votre modem
- -- Affiche la largeur de l'écran
- --print("Largeur de l'écran :", screenWidth)
- -- Affiche la hauteur de l'écran
- --print("Hauteur de l'écran :", screenHeight)
- if mon == nil then
- print("Monitor not found. Please connect a monitor and try again.")
- return
- end
- if mod == nil then
- print("Modem not found. Please connect a modem and try again.")
- return
- end
- mod.open(1)
- --mon.clear()
- mon.setTextScale(0.5)
- mon.setPaletteColour(colors.yellow, 0x018281) -- win 95/98
- mon.setBackgroundColor(colors.yellow)
- --mon.clear()
- --local longueurBase = 13 -- Longueur de base pour les caractères fixes ("- ", " (Type: ", " x")
- local longueurBase = 7 -- Longueur de base pour les caractères fixes ("- ", " (Type: ", " x")
- local typeLength = 6 -- Length of " (Type: "
- local variantLength = 9 -- Length of " (Variant: "
- local test1 = longueurBase + typeLength
- local test2 = longueurBase + variantLength
- local newsom = 0
- local oldsom = 0
- local oldsom2 = 0
- local oldsom3 = 0
- local screenWidth, screenHeight = mon.getSize()
- if screenWidth == nil then
- print("Erreur: impossible de récupérer la largeur de l'écran.")
- return
- end
- local column2 = screenWidth / 2 --recupere la moitier de l'ecran
- local config = true
- if config == true then
- linemax = 10
- else
- linemax = screenHeight
- end
- --local line = 1
- --local column = 1
- --local newcolumn = 1
- while true do
- local event, modemSide, senderChannel, replyChannel, message, senderDistance = os.pullEvent("modem_message")
- local receivedBlocks = textutils.unserializeJSON(message)
- mon.clear()
- --mon.setTextScale(0.5)
- local line = 1
- local column = 1
- local newcolumn = 1
- mon.setCursorPos(column, line)
- mon.write("Blocks Mined:")
- for block, data in pairs(receivedBlocks) do --for block, count in pairs(receivedBlocks) do
- if line > linemax - 1 then -- Vérification de changement de ligne
- if newcolumn == 3 then
- oldsom3 = oldsom2 + newsom
- --newsom = 0
- elseif newcolumn == 2 then
- oldsom2 = oldsom + newsom
- --newsom = 0
- else
- oldsom = newsom
- end
- if newcolumn == 3 then
- column = oldsom3 + 1
- --line = 1
- --mon.setCursorPos(column, line)
- --newcolumn = newcolumn + 1
- elseif newcolumn == 2 then
- column = oldsom2 + 1
- --line = 1
- --mon.setCursorPos(column, line)
- --newcolumn = newcolumn + 1
- else
- column = oldsom + 1
- --line = 1
- --mon.setCursorPos(column, line)
- --newcolumn = newcolumn + 1
- end
- newsom = 0
- newcolumn = newcolumn + 1
- line = 1
- mon.setCursorPos(column, line)
- end
- line = line + 1
- mon.setCursorPos(column, line)
- local colonIndex = string.find(block, ":", 1, true)
- local name = string.sub(block, 1, colonIndex - 1)
- local metadata = string.sub(block, colonIndex + 1)
- longueurNom = string.len(name)
- longueurType = string.len(metadata) or 0 -- Handle cases where metadata is absent
- longueurQuantite = string.len(tostring(data.count)) -- Convertir la quantité en chaîne de caractères
- if name == "tconstruct" then
- test3 = test1
- elseif name == "biomesoplenty" then
- test3 = test2
- else
- test3 = 7
- end
- -- Calculer la longueur totale estimée
- --local longueurTotale = longueurBase + longueurNom + longueurType + longueurQuantite
- local longueurTotale = test3 + longueurNom + longueurType + longueurQuantite
- if longueurTotale > screenWidth then
- print("Erreur: augmenter la largeur de l'écran.")
- return
- end
- if longueurTotale > newsom then
- newsom = longueurTotale
- end
- --line = line + 1
- --mon.setCursorPos(column, line)
- ----mon.write("- " .. name .. " (Type: " .. metadata .. ") x" .. data.count)
- if name == "tconstruct" then
- mon.write(string.format("-%s (Type: %s) x%d", name, metadata, data.count))
- elseif name == "biomesoplenty" then
- mon.write(string.format("-%s (Variant: %s) x%d", name, metadata, data.count))
- else
- mon.write(string.format("-%s (%s) x%d", name, metadata, data.count))
- end
- --mon.write(string.format("-%s (Type: %s) x%d", name, metadata, data.count))
- end
- mon.setCursorPos(column2 - string.len("Longueur maximale estimée : %d l x%d h x%d")/2, 1)
- -- Afficher la longueur maximale calculée
- mon.write(string.format("Longueur maximale estimée : %d l x%d h x%d", newsom, screenWidth, screenHeight)) -- Affichage clair
- --mon.write("Longueur maximale estimée :", newsom)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement