Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local nbPuit = 0
- local nbPuitsTotal = 0
- local profondeur = 0
- local xPosition = 0
- local zPosition = 0
- local items = {}
- local idChannel = 123
- local fuelLevel = 0
- local fuelItemCount = 0
- local message = "attente"
- local colorsMap = {
- ["minecraft:coal"] = colors.gray,
- ["minecraft:iron_ore"] = colors.orange,
- ["minecraft:gold_ore"] = colors.yellow,
- ["minecraft:redstone"] = colors.red,
- ["minecraft:lapis_lazuli"] = colors.blue,
- ["minecraft:diamond"] = colors.cyan,
- ["minecraft:emerald"] = colors.green,
- ["minecraft:netherite_scrap"] = colors.brown,
- ["minecraft:netherrack"] = colors.red,
- ["minecraft:magma_block"] = colors.orange,
- ["alltheores:raw_tin"] = colors.lightGray,
- ["minecraft:blackstone"] = colors.gray,
- ["mysticalagriculture:soulstone_cobble"] = colors.brown,
- ["minecraft:gold_nugget"] = colors.yellow,
- ["mysticalagriculture:soulium_dust"] = colors.brown,
- ["regions_unexplored:glistering_sprout"] = colors.magenta,
- ["regions_unexplored:glistering_wart"] = colors.magenta,
- ["regions_unexplored:glistering_fern"] = colors.magenta,
- ["silentgear:raw_crimson_iron"] = colors.red,
- ["rftoolsbase:dimensionalshard"] = colors.lightBlue,
- }
- -- Fonction pour diviser une chaîne de caractères en fonction d'un motif donné
- function split(str, pat)
- local t = {} -- Tableau qui contiendra les morceaux
- local fpat = "(.-)" .. pat -- Création du motif: capture tout avant le délimiteur
- local last_end = 1 -- Position de départ pour la recherche
- local s, e, cap = str:find(fpat, 1) -- Recherche la première occurrence du motif
- -- Tant qu'une occurrence est trouvée
- while s do
- -- Si la capture n'est pas vide ou si on n'est pas en début de chaîne,
- -- on ajoute le morceau au tableau
- if s ~= 1 or cap ~= "" then
- table.insert(t, cap)
- end
- last_end = e + 1 -- Mise à jour: commence juste après le délimiteur trouvé
- s, e, cap = str:find(fpat, last_end) -- Recherche de l'occurrence suivante
- end
- -- S'il reste une partie de la chaîne après le dernier délimiteur, l'ajouter
- if last_end <= #str then
- cap = str:sub(last_end)
- table.insert(t, cap)
- end
- return t -- Retourne le tableau contenant tous les segments
- end
- local statusColors = {
- attente = colors.yellow,
- encours = colors.green,
- vidage = colors.orange,
- charbon = colors.red,
- retour = colors.orange,
- fin = colors.magenta
- }
- local function printCommonInfo()
- term.setCursorPos(1,2)
- print("X: " .. xPosition .. " / Y: " .. zPosition)
- term.setCursorPos(1,3)
- if profondeur == 0 then
- print("Profondeur: " .. profondeur)
- else
- print("Profondeur: -" .. profondeur)
- end
- term.setCursorPos(1,4)
- print("Fuel: " .. fuelLevel .. " / CoalSlot: " .. fuelItemCount)
- end
- local function printItems(startLine)
- term.setCursorPos(1, startLine)
- for i = 1, #items do
- if items[i] then
- -- Ici, on utilise une éventuelle table de couleurs associée aux items si besoin
- local color = colorsMap[items[i].name] or colors.white
- term.setTextColor(color)
- local itemName = items[i].name:match(":(.+)") or items[i].name
- print(i .. "- " .. itemName .. " x" .. items[i].count)
- end
- end
- end
- -- Configuration de l'affichage
- -- term.setBackgroundColor(colors.blue)
- -- term.clear()
- -- term.setCursorPos(1, 1)
- -- Fonction pour afficher l'état actuel sur le moniteur
- function affiche_etat()
- term.clear()
- term.setCursorPos(1,1)
- if message == "attente" then
- term.setTextColor(statusColors.attente)
- print("En attente de la tortue...")
- else
- term.setTextColor(statusColors[message] or colors.white)
- if message == "encours" then
- print("Minage: " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
- elseif message == "vidage" then
- print("Minage: " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
- term.setCursorPos(1,5)
- print("besoin de vider l'inventaire")
- elseif message == "charbon" then
- print("Minage: " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
- term.setCursorPos(1,5)
- print("besoin de charbon")
- elseif message == "retour" then
- print("Minage: " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
- term.setCursorPos(1,5)
- print("terminer, retour au point de depart...")
- elseif message == "fin" then
- print("Minage: " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
- term.setCursorPos(1,5)
- print("terminer! En attente de la tortue...")
- end
- printCommonInfo()
- -- L'affichage des items commence à la ligne 6 (ou 7 en fonction du message)
- local startLine = 6
- if message == "vidage" or message == "charbon" or message == "retour" then
- startLine = 6
- end
- printItems(startLine)
- end
- end
- --rednet.open("right")
- modem = peripheral.find("modem")
- affiche_etat()
- while true do
- modem.open(idChannel)
- event, modemSide, senderChannel, replyChannel, text, senderDistance = os.pullEvent("modem_message")
- --term.setCursorPos(1,20)
- --print("Message reçu : ", text) -- need sleep apres car trop rapide
- local data = textutils.unserialise(text)
- if data then
- items = data
- print("ok")
- --term.setCursorPos(1,1)
- --print("Données reçues de la tortue :")
- --print(text)
- else
- local tab = split(text, ":")
- if tab[1] == "etat" then message = tab[2] end
- if tab[1] == "nbPuitsTotal" then nbPuitsTotal = tonumber(tab[2]) end --if tab[1] == "nbPuitsTotal" then nbPuitsTotal = tonumber(tab[2]) end
- if tab[1] == "nbPuits" then nbPuit = tonumber(tab[2]) end --if tab[1] == "nbPuits" then nbPuit = tonumber(tab[2]) end
- if tab[1] == "profondeur" then profondeur = tonumber(tab[2]) end --if tab[1] == "profondeur" then profondeur = tonumber(tab[2]) end
- if tab[1] == "xPos" then xPosition = tonumber(tab[2]) end
- if tab[1] == "yPos" then zPosition = tonumber(tab[2]) end
- if tab[1] == "fuel" then fuelLevel = tonumber(tab[2]) end --tonumber(tab[2]) end
- if tab[1] == "fuelItem" then fuelItemCount = tonumber(tab[2]) end --tonumber(tab[2]) end
- end
- affiche_etat()
- --modem.close(idChannel)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement