Advertisement
Vodka51200

affichagepocketturtlemine

Mar 7th, 2025
142
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 6.23 KB | Gaming | 0 0
  1. local nbPuit = 0
  2. local nbPuitsTotal = 0
  3. local profondeur = 0
  4. local xPosition = 0
  5. local zPosition = 0
  6. local items = {}
  7. local idChannel = 123
  8. local fuelLevel = 0
  9. local fuelItemCount = 0
  10.  
  11. local message = "attente"
  12.  
  13. local colorsMap = {
  14.     ["minecraft:coal"] = colors.gray,
  15.     ["minecraft:iron_ore"] = colors.orange,
  16.     ["minecraft:gold_ore"] = colors.yellow,
  17.     ["minecraft:redstone"] = colors.red,
  18.     ["minecraft:lapis_lazuli"] = colors.blue,
  19.     ["minecraft:diamond"] = colors.cyan,
  20.     ["minecraft:emerald"] = colors.green,
  21.     ["minecraft:netherite_scrap"] = colors.brown,
  22.     ["minecraft:netherrack"] = colors.red,
  23.     ["minecraft:magma_block"] = colors.orange,
  24.     ["alltheores:raw_tin"] = colors.lightGray,
  25.     ["minecraft:blackstone"] = colors.gray,
  26.     ["mysticalagriculture:soulstone_cobble"] = colors.brown,
  27.     ["minecraft:gold_nugget"] = colors.yellow,
  28.     ["mysticalagriculture:soulium_dust"] = colors.brown,
  29.     ["regions_unexplored:glistering_sprout"] = colors.magenta,
  30.     ["regions_unexplored:glistering_wart"] = colors.magenta,
  31.     ["regions_unexplored:glistering_fern"] = colors.magenta,
  32.     ["silentgear:raw_crimson_iron"] = colors.red,
  33.     ["rftoolsbase:dimensionalshard"] = colors.lightBlue,
  34. }
  35.  
  36. -- Fonction pour diviser une chaîne de caractères en fonction d'un motif donné
  37. function split(str, pat)
  38.     local t = {}                 -- Tableau qui contiendra les morceaux
  39.     local fpat = "(.-)" .. pat    -- Création du motif: capture tout avant le délimiteur
  40.     local last_end = 1           -- Position de départ pour la recherche
  41.     local s, e, cap = str:find(fpat, 1)  -- Recherche la première occurrence du motif
  42.  
  43.     -- Tant qu'une occurrence est trouvée
  44.     while s do
  45.         -- Si la capture n'est pas vide ou si on n'est pas en début de chaîne,
  46.         -- on ajoute le morceau au tableau
  47.         if s ~= 1 or cap ~= "" then
  48.             table.insert(t, cap)
  49.         end
  50.         last_end = e + 1       -- Mise à jour: commence juste après le délimiteur trouvé
  51.         s, e, cap = str:find(fpat, last_end)  -- Recherche de l'occurrence suivante
  52.     end
  53.  
  54.     -- S'il reste une partie de la chaîne après le dernier délimiteur, l'ajouter
  55.     if last_end <= #str then
  56.         cap = str:sub(last_end)
  57.         table.insert(t, cap)
  58.     end
  59.  
  60.     return t  -- Retourne le tableau contenant tous les segments
  61. end
  62.  
  63. local statusColors = {
  64.   attente = colors.yellow,
  65.   encours  = colors.green,
  66.   vidage   = colors.orange,
  67.   charbon  = colors.red,
  68.   retour   = colors.orange,
  69.   fin      = colors.magenta
  70. }
  71.  
  72. local function printCommonInfo()
  73.   term.setCursorPos(1,2)
  74.   print("X: " .. xPosition .. " / Y: " .. zPosition)
  75.   term.setCursorPos(1,3)
  76.   if profondeur == 0 then
  77.     print("Profondeur: " .. profondeur)
  78.   else
  79.     print("Profondeur: -" .. profondeur)
  80.   end
  81.   term.setCursorPos(1,4)
  82.   print("Fuel: " .. fuelLevel .. " / CoalSlot: " .. fuelItemCount)
  83. end
  84.  
  85. local function printItems(startLine)
  86.   term.setCursorPos(1, startLine)
  87.   for i = 1, #items do
  88.     if items[i] then
  89.       -- Ici, on utilise une éventuelle table de couleurs associée aux items si besoin
  90.       local color = colorsMap[items[i].name] or colors.white
  91.       term.setTextColor(color)
  92.       local itemName = items[i].name:match(":(.+)") or items[i].name
  93.       print(i .. "- " .. itemName .. " x" .. items[i].count)
  94.     end
  95.   end
  96. end
  97.  
  98. -- Configuration de l'affichage
  99. -- term.setBackgroundColor(colors.blue)
  100. -- term.clear()
  101. -- term.setCursorPos(1, 1)
  102.  
  103. -- Fonction pour afficher l'état actuel sur le moniteur
  104. function affiche_etat()
  105.   term.clear()
  106.   term.setCursorPos(1,1)
  107.  
  108.   if message == "attente" then
  109.     term.setTextColor(statusColors.attente)
  110.     print("En attente de la tortue...")
  111.   else
  112.     term.setTextColor(statusColors[message] or colors.white)
  113.     if message == "encours" then
  114.       print("Minage: " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
  115.     elseif message == "vidage" then
  116.       print("Minage: " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
  117.       term.setCursorPos(1,5)
  118.       print("besoin de vider l'inventaire")
  119.     elseif message == "charbon" then
  120.       print("Minage: " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
  121.       term.setCursorPos(1,5)
  122.       print("besoin de charbon")
  123.     elseif message == "retour" then
  124.       print("Minage: " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
  125.       term.setCursorPos(1,5)
  126.       print("terminer, retour au point de depart...")
  127.     elseif message == "fin" then
  128.       print("Minage: " .. nbPuit .. " / " .. nbPuitsTotal .. " Puits.")
  129.       term.setCursorPos(1,5)
  130.       print("terminer! En attente de la tortue...")
  131.     end
  132.  
  133.     printCommonInfo()
  134.     -- L'affichage des items commence à la ligne 6 (ou 7 en fonction du message)
  135.     local startLine = 6
  136.     if message == "vidage" or message == "charbon" or message == "retour" then
  137.       startLine = 6
  138.     end
  139.     printItems(startLine)
  140.   end
  141. end
  142.  
  143. --rednet.open("right")
  144. modem = peripheral.find("modem")
  145. affiche_etat()
  146.  
  147. while true do
  148.     modem.open(idChannel)
  149.     event, modemSide, senderChannel, replyChannel, text, senderDistance = os.pullEvent("modem_message")
  150.     --term.setCursorPos(1,20)
  151.     --print("Message reçu : ", text) -- need sleep apres car trop rapide
  152.     local data = textutils.unserialise(text)
  153.     if data then
  154.         items = data
  155.         print("ok")
  156.         --term.setCursorPos(1,1)
  157.         --print("Données reçues de la tortue :")
  158.         --print(text)
  159.     else
  160.         local tab = split(text, ":")
  161.         if tab[1] == "etat" then message = tab[2] end
  162.         if tab[1] == "nbPuitsTotal" then nbPuitsTotal = tonumber(tab[2]) end --if tab[1] == "nbPuitsTotal" then nbPuitsTotal = tonumber(tab[2]) end
  163.         if tab[1] == "nbPuits" then nbPuit = tonumber(tab[2]) end --if tab[1] == "nbPuits" then nbPuit = tonumber(tab[2]) end
  164.         if tab[1] == "profondeur" then profondeur = tonumber(tab[2]) end --if tab[1] == "profondeur" then profondeur = tonumber(tab[2]) end
  165.         if tab[1] == "xPos" then xPosition = tonumber(tab[2]) end
  166.         if tab[1] == "yPos" then zPosition = tonumber(tab[2]) end
  167.         if tab[1] == "fuel" then fuelLevel = tonumber(tab[2]) end --tonumber(tab[2]) end
  168.         if tab[1] == "fuelItem" then fuelItemCount = tonumber(tab[2]) end --tonumber(tab[2]) end
  169.     end
  170.     affiche_etat()
  171.     --modem.close(idChannel)
  172. end
  173.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement