Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local fuel_level = turtle.getFuelLevel()
- local modem = peripheral.find("modem")
- modem.open(1)
- 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 oretypLenght = 9 --* Length of " (Oretype: "
- local test1 = longueurBase + typeLength
- local test2 = longueurBase + variantLength
- local test3 = 0
- local newsom = 0
- local screenWidth, screenHeight = term.getSize()
- term.setBackgroundColor(colors.gray)
- term.clear()
- function printText(txt1, color1)
- local oldColor = term.getTextColor() -- sauvegarde de la couleur courante
- term.setTextColor(color1)
- print(txt1)
- term.setTextColor(oldColor) -- restauration de la couleur courante
- end
- function printCenter(txt,color)
- local w, h = term.getSize()
- paintutils.drawFilledBox(math.floor(w/2-txt:len()/2+.5-1),6,math.floor(w/2+txt:len()/2+.5),8,colors.cyan)
- term.setCursorPos(math.floor(w/2-txt:len()/2+.5),h/2+1)
- local oldColorTxt = term.getTextColor() -- sauvegarde de la couleur courante
- --local oldColorBackground = term.getBackgroundColor() -- sauvegarde de la couleur courante
- term.setTextColor(color)
- print(txt)
- sleep(2)
- term.setBackgroundColor(colors.gray)
- term.setTextColor(oldColorTxt) -- restauration de la couleur courante
- end
- local blockList = {}
- -- fonction pour afficher les blocs et leur quantité sans pagination
- local function displayBlocks(blocks)
- local page = 1
- local pageSize = 8
- local blockList = {}
- print("Blocks Mined:")
- for block, data in pairs(blocks) do
- local colonIndex = string.find(block, ":", 1, true)
- local name = string.sub(block, 1, colonIndex - 1)
- local metadata = string.sub(block, colonIndex + 1)
- --local metadata2 = string.match(block, "^(.*):(.*)$") -- Capture everything before and after colon :
- if name == "tconstruct" or name == "biomesoplenty" then
- --if metadata then
- newname = string.sub(metadata, string.len(string.match(metadata, "^([^:]*):")) + 2) -- Extract text after colon
- end
- --end
- local count = data.count
- if name == "tconstruct" then
- test3 = test1
- print("- " .. name .. " (Type: " .. metadata .. ") x" .. count)
- elseif name == "biomesoplenty" then
- test3 = test2
- print("- " .. name .. " (Variant: " .. metadata .. ") x" .. count)
- elseif name == "deepresonance" then
- test3 = test2
- print("- " .. name .. " (Oretype: " .. metadata .. ") x" .. count)
- else
- test3 = 7
- print("- " .. name .. " (" .. metadata .. ") x" .. count)
- end
- -- Récupérer les longueurs des chaînes variables
- longueurNom = string.len(name)
- longueurType = string.len(metadata)
- longueurQuantite = string.len(tostring(data.count)) -- Convertir la quantité en chaîne de caractères
- -- Calculer la longueur totale estimée
- local longueurTotale = test3 + longueurNom + longueurType + longueurQuantite --longueurBase + longueurNom + longueurType + longueurQuantite
- if longueurTotale > newsom then
- newsom = longueurTotale
- end
- if name == "tconstruct" or name == "biomesoplenty" then
- table.insert(blockList, "- " .. newname .. " x" .. count)
- elseif name == "deepresonance" then
- table.insert(blockList, "- " .. metadata .. " x" .. count)
- --elseif name == "minecraft" and metadata ~= nil then
- --table.insert(blockList, "- " .. metadata .. " x" .. count)
- else
- table.insert(blockList, "- " .. name .. " (" .. metadata .. ") x" .. count)
- end
- end
- sleep(5)
- while true do
- local totalPages = math.ceil(#blockList / pageSize)
- term.clear()
- term.setCursorPos(1,1)
- print("Blocks Mined (Page " .. page .. " of " .. totalPages .. "):")
- for i = (page-1)*pageSize+1,page*pageSize do
- if blockList[i] then
- print(blockList[i]) --a changer si type variant or pas
- else
- break
- end
- end
- term.setCursorPos(1,11)
- printText("press 'enter' for print menu",colors.yellow)
- term.setCursorPos(1,12)
- printText("press 'q' for quit",colors.red)
- --attendre une entrée clavier pour passer à la page suivante ou précédente
- local event, key = os.pullEvent("key")
- if key == keys.right and #blockList > page*pageSize then
- page = page + 1
- elseif key == keys.left and page > 1 then
- page = page - 1
- elseif key == keys.enter then
- -- Appeler la fonction pour imprimer les pages
- printCenter("Success",colors.green)
- sleep(1)
- --sendBlocks(blocks)
- --else
- elseif key == keys.q then
- printCenter("Terminer",colors.red)
- sleep(2)
- term.setBackgroundColor(colors.black)
- term.clear()
- term.setCursorPos(1, screenHeight)
- break
- --return displayMenu()
- end
- end
- --print(blockList)
- --print("Longueur type estimée :", test1)
- --print("Longueur variant estimée :", test2)
- --print("Longueur block estimée :", test3)
- --print("Longueur nom estimée :", longueurNom or 0)
- --print("Longueur type estimée :", longueurType or 0)
- --print("Longueur quantite estimée :", longueurQuantite or 0)
- --Afficher la longueur maximale calculée
- --print("Longueur maximale estimée :", newsom or 0)
- end
- -- fonction pour envoyer les données au moniteur
- local function sendBlocks(blocks)
- local message = textutils.serializeJSON(blocks)
- modem.transmit(1, 1, message)
- end
- -- initialiser le tableau des blocs minés
- local blocks = {}
- function CheckInventory() -- Fonction pour vérifier l'inventaire de la turtle
- for i=1,16 do
- local itemDetail = turtle.getItemDetail(i)
- if itemDetail then
- local colonIndex = string.find(itemDetail.name, ":", 1, true)
- local name = string.sub(itemDetail.name, colonIndex + 1)
- print("Slot " .. i .. ": " .. itemDetail.count .. "x " .. name)
- end
- end
- end
- -- Vérifie le niveau de carburant de la turtle
- function check_fuel_level()
- local fuel_level = turtle.getFuelLevel()
- if fuel_level == "unlimited" then
- print("Le niveau de carburant est illimité.")
- return
- end
- print("Niveau de carburant : " .. fuel_level)
- if fuel_level < 10 then
- print("Le niveau de carburant est faible, recherche de carburant dans l'inventaire...")
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(0) then
- local fuel_count = turtle.getItemCount()
- local needed_fuel = math.ceil((10 - fuel_level) / 80)
- if fuel_count >= needed_fuel then
- turtle.refuel(needed_fuel)
- print("Carburant trouvé et rechargé.")
- return
- end
- end
- end
- print("Aucun carburant trouvé, en attente...")
- while turtle.getFuelLevel() < 10 do
- os.pullEvent("turtle_inventory")
- end
- print("Carburant ajouté.")
- end
- end
- --[[function MineLayer() -- Fonction pour miner une ligne
- for i=1,10 do
- check_fuel_level()
- -- miner le bloc et l'ajouter au tableau des blocs minés
- local success, data = turtle.inspect()
- if success then
- local block = data.name
- local metadata = data.state -- Récupère les métadonnées
- if metadata and metadata.type then
- print(metadata.type)
- end
- blocks[block] = (blocks[block] or 0) + 1
- end
- turtle.dig()
- turtle.forward()
- end
- end]]
- function MineLayer() -- Fonction pour miner une ligne
- for i=1,5 do
- check_fuel_level()
- -- Miner le bloc et l'ajouter au tableau des blocs minés
- local success, data = turtle.inspect()
- if success then
- local block = data.name
- if data.state and data.state.type then
- block = block .. ":" .. data.state.type
- elseif data.state and data.state.variant then
- block = block .. ":" .. data.state.variant
- elseif data.state and data.state.oretype then
- block = block .. ":" .. data.state.oretype
- end
- if not blocks[block] then
- blocks[block] = { count = 0 }
- end
- blocks[block].count = blocks[block].count + 1
- end
- turtle.dig()
- turtle.forward()
- end
- end
- function RetourDepart()
- -- retourne au point de départ
- for i=1,5 do
- check_fuel_level()
- turtle.back()
- end
- end
- -- Main Program
- --for u =1,10 do
- MineLayer()
- RetourDepart()
- --print(u)
- --end
- -- afficher les blocs et leur quantité
- displayBlocks(blocks)
- --CheckInventory()
- -- envoyer les données au moniteur
- sendBlocks(blocks)
- --print("Niveau de carburant : " .. turtle.getFuelLevel())
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement