Advertisement
Vodka51200

miningnether 1.12.2 / 1.16.5

Jul 4th, 2017 (edited)
398
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 16.27 KB | None | 0 0
  1. local id = 6 -- id du monitor qui recois
  2. local c = "Cobalt" --1.12.2 1.16.5
  3. local cnb = 0
  4. local a = "Ardite" -- 1.12.2
  5. local anb = 0
  6. local v = "Vibranium" -- 1.16.5
  7. local vnb = 0
  8. local d = "Debris" -- 1.16.5
  9. local dnb = 0
  10. local ligne = 0
  11. local colonne = 0
  12. local profondeur = 0
  13. local premierSlot = 1
  14. local dernierSlot = 13
  15. local chestNetherrack = 14
  16. local chestCharbon = 15
  17. local charbonSlot = 16
  18. local dir = 0
  19. local ligneEnCour = 0
  20. local idChannel = 8899 -- n'est pas utiliser
  21. local esquive = 0
  22. local EnvoieRednet = {}
  23. local Etat = "En cours"
  24. local Mob = "Pas de Mob"
  25. local z = 0 -- 0
  26. local y = 0 -- 0
  27. local tourne = ""
  28. local descend = ""
  29. local MAX_ITEMS_TO_SUCK = 30
  30. local MIN_ITEMS_TO_KEEP = 5
  31.  
  32. local version = "1.12.2"
  33. local modem = peripheral.find("modem") -- Remplacez "modem" par le nom de votre modem
  34. modem.open(1)
  35.  
  36. -- initialiser le tableau des blocs minés
  37. local blocks = {}
  38.  
  39. --fonction pour afficher les blocs et leur quantité avec pagination
  40. local function displayBlocks(blocks)
  41.   local page = 1
  42.   local pageSize = 10
  43.   local blockList = {}
  44.   for block, count in pairs(blocks) do
  45.     local colonIndex = string.find(block, ":", 1, true)
  46.     local name = string.sub(block, colonIndex + 1)
  47.     table.insert(blockList, name .. " x" .. count)
  48.   end
  49.   while true do
  50.     --afficher la page courante
  51.     term.clear()
  52.     term.setCursorPos(1,1)
  53.     print("Blocks Mined (Page " .. page .. "):")
  54.     for i = (page-1)*pageSize+1,page*pageSize do
  55.       if blockList[i] then
  56.         print("- " .. blockList[i])
  57.       else
  58.         break
  59.       end
  60.     end
  61.     --attendre une entrée clavier pour passer à la page suivante ou précédente
  62.     local event, key = os.pullEvent("key")
  63.     if key == keys.right and #blockList > page*pageSize then
  64.       page = page + 1
  65.     elseif key == keys.left and page > 1 then
  66.       page = page - 1
  67.     else
  68.       break
  69.     end
  70.   end
  71. end
  72.  
  73. -- fonction pour afficher les blocs et leur quantité sans pagination
  74. -- local function displayBlocks(blocks)
  75. --   print("Blocks Mined:")
  76. --   for block, count in pairs(blocks) do
  77. --     local colonIndex = string.find(block, ":", 1, true)
  78. --  local name = string.sub(block, colonIndex + 1)
  79. --  print("-" .. name .. " x" .. count)
  80. --   end
  81. -- end
  82.  
  83.  -- fonction pour envoyer les données au moniteur
  84. local function sendBlocks(blocks)
  85.   local message = textutils.serializeJSON(blocks)
  86.   modem.transmit(1, 1, message)
  87. end
  88.  
  89. function envoie()
  90.   while true do
  91.     EnvoieRednet = {Tourne=tourne,Descend=descend,NivFuel=turtle.getFuelLevel(),Monstre=Mob,
  92.     Cobalt=cnb,Ardite=anb,Vibranium=vnb,Debris=dnb,LigneEnCour=ligneEnCour,Colonne=z,Profondeur=y,Etat=Etat,
  93.     ProfondeurMax=profondeur,colonneMax=colonne,ligneMax=ligne,Charbon=turtle.getItemCount(charbonSlot),slot=scantest()}
  94.  
  95.     rednet.send(id,textutils.serialise(EnvoieRednet))
  96.     sleep(0.5)
  97.   end
  98. end
  99.  
  100. -- Table des minerais à éviter
  101. -- local oresToAvoid = {
  102. --   ["tconstruct:ore"] = {
  103. --     [0] = "cobalt_ore", -- 1.12.2
  104. --     [1] = "ardite_ore"  -- 1.12.2
  105. --   },
  106. --   ["minecraft:ancient_debris"] = true, -- 1.16.5
  107. --   ["allthemodium:vibranium_ore"] = true -- 1.16.5
  108. -- }
  109.  
  110. -- Fonction pour vérifier si un minerai doit être évité
  111. -- function shouldAvoidOre(oreName, oreMetadata)
  112. --   if not oresToAvoid[oreName] then
  113. --     return false
  114. --   end
  115. --   if type(oresToAvoid[oreName]) == "boolean" then
  116. --     return true
  117. --   end
  118. --   return oresToAvoid[oreName][oreMetadata] ~= nil
  119. -- end
  120.  
  121. function esquive()
  122.     turtle.turnRight()
  123.     turtle.dig()
  124.     turtle.forward()
  125.     turtle.turnLeft()
  126.     turtle.dig()
  127.     turtle.forward()
  128.     turtle.dig()
  129.     turtle.forward()
  130.     turtle.turnLeft()
  131.     turtle.dig()
  132.     turtle.forward()
  133.     turtle.turnRight()
  134.     ligneEnCour = ligneEnCour +2   
  135. end
  136.  
  137. function scantest()
  138. local items ={}
  139.     for i = premierSlot,dernierSlot do
  140. local data = turtle.getItemDetail(i)
  141.         if data then
  142.             items[i]={name=data.name,count=data.count}
  143.         end
  144.     end
  145.     return items
  146. end
  147.  
  148. function refuel()
  149.     if turtle.getFuelLevel() < 10 then
  150.       turtle.select(charbonSlot)
  151.           turtle.refuel(5)
  152.           rechargeCharbon()
  153.     end
  154.     turtle.select(premierSlot)
  155. end
  156.  
  157. function ifItemCharbonSlot()
  158.     if turtle.getItemCount() >= 1 then
  159.     turtle.drop()
  160.     end
  161. end
  162.  
  163. -- Fonctions
  164. local function checkInventory()
  165.     if turtle.getItemCount() <= MIN_ITEMS_TO_KEEP then
  166.         return true
  167.     end
  168.     return false
  169. end
  170.  
  171. local function suckItems(direction, maxItems)
  172.     for i = 1, maxItems do
  173.         if not turtle.suck(direction) then
  174.             break
  175.         end
  176.     end
  177. end
  178.  
  179. function rechargeCharbon()
  180. Etat = "rechargeCharbon"
  181. turtle.select(charbonSlot)
  182.     if checkInventory() then
  183.         if not turtle.digUp() then
  184.             turtle.digDown()
  185.             turtle.select(chestCharbon)
  186.             turtle.placeDown()
  187.             turtle.select(charbonSlot)
  188.             ifItemCharbonSlot()
  189.             turtle.suckDown(MAX_ITEMS_TO_SUCK)
  190.             turtle.select(chestCharbon)
  191.             turtle.digDown()
  192.             turtle.select(premierSlot) -- pas obliger a voir
  193.             sleep(0.5)
  194.         else
  195.             turtle.select(chestCharbon)
  196.             turtle.placeUp()
  197.             turtle.select(charbonSlot)
  198.             ifItemCharbonSlot()
  199.             turtle.suckUp(MAX_ITEMS_TO_SUCK)
  200.             turtle.select(chestCharbon)
  201.             turtle.digUp()
  202.             turtle.select(premierSlot) -- pas obliger a voir
  203.             sleep(0.5)
  204.         end
  205.     end
  206.     refuel() -- pas obliger a voir
  207.   Etat = "En cours"
  208. end
  209.  
  210. -- Chat gpt
  211. -- function Attack()
  212.   -- local hasAttacked = false
  213.   -- while not hasAttacked do
  214.     ----Move forward and attempt to attack any mobs in the way
  215.     -- if turtle.detect() then
  216.       -- turtle.attack()
  217.       -- hasAttacked = true
  218.     -- elseif not turtle.forward() then
  219.       ----If turtle cannot move forward, stop attacking
  220.       -- hasAttacked = true
  221.     -- end
  222.   -- end
  223.   -- print(ligneEnCour)
  224.   -- print(z)
  225.   -- print(y)
  226.   -- getFuelLevel()
  227. -- end
  228.  
  229.  function Attack()
  230.     if turtle.attack() then
  231.         turtle.attack()
  232.         sleep(0.5)
  233.         turtle.attack()
  234.         sleep(0.5)
  235.         turtle.attack()
  236.         sleep(0.5)
  237.         turtle.attack()
  238.         sleep(0.5)
  239.         turtle.attack()
  240.         sleep(0.5)
  241.         turtle.attack()
  242.         sleep(0.5)
  243.         turtle.attack()
  244.         sleep(0.5)
  245.         turtle.attack()
  246.         sleep(0.5)
  247.         turtle.attack()
  248.         sleep(0.5)
  249.         turtle.attack()
  250.         sleep(0.5)
  251.         turtle.attack()
  252.         sleep(0.5)
  253.         turtle.attack()
  254.         sleep(0.5)
  255.     else
  256.     print("je ne peut pas attaquer")
  257.     sleep(1)
  258.     end
  259.     print("menace eliminer")
  260.     refuel() -- pas obliger a voir
  261.  end
  262.  
  263.  
  264. function forward()
  265.   turtle.select(premierSlot)
  266.   turtle.dig()
  267.   --print("je creuse")
  268.     if not turtle.forward() then
  269.       Mob = "Il y a un mob"
  270.       Attack()
  271.       Mob = "Plus de Mob"
  272.       --turtle.forward()
  273.     else
  274.         return true
  275.     end
  276. end
  277.  
  278. function videInventaire()
  279.     Etat = "videInventaire"
  280.     turtle.select(chestNetherrack)
  281.     if not turtle.placeUp() then
  282.         print("Je ne peux pas enlever en haut je place en bas")
  283.         turtle.digDown()
  284.         turtle.placeDown()
  285.         vidageDown()
  286.     else
  287.         print("Je peux placer en haut")
  288.         vidageUp()
  289.     end
  290. end
  291.  
  292. function vidageUp()
  293. local slot
  294.     for slot=premierSlot,dernierSlot do
  295.         turtle.select(slot)
  296.         while turtle.getItemCount(slot) > 0 do
  297.             turtle.dropUp(turtle.getItemCount(slot))
  298.         end
  299.     end
  300.     turtle.select(chestNetherrack)
  301.     sleep(0.5)
  302.     print("je recupere la turtle")
  303.     turtle.digUp()
  304.     Etat = "En cours"
  305. end
  306.  
  307. function vidageDown()
  308. local slot
  309.     for slot=premierSlot,dernierSlot do
  310.         turtle.select(slot)
  311.         while turtle.getItemCount(slot) > 0 do
  312.             turtle.dropDown(turtle.getItemCount(slot))
  313.         end
  314.     end
  315.     turtle.select(chestNetherrack)
  316.     sleep(0.5)
  317.     print("je recupere la turtle")
  318.     turtle.digDown()
  319.     Etat = "En cours"
  320. end
  321.  
  322. function scan()
  323.   local success,i = turtle.inspect()
  324.     if success then
  325.         local block = i.name
  326.         blocks[block] = (blocks[block] or 0) + 1
  327.     end
  328.     -- Code pour vérifier si un minerai doit être évité et appeler la fonction esquive() si nécessaire
  329.     -- if shouldAvoidOre(i.name, i.metadata) then
  330.     --  print(i.name .. " : je ne le mine pas")
  331.     --  esquive()
  332.     if i.name == "tconstruct:ore" and i.metadata == 0 then --1.12.2
  333.   --if i.name == "tconstruct:cobalt_ore" then -- 1.16.5
  334.     print(c,i.name)
  335.     print("je mine pas le cobalt")
  336.     cnb = cnb + 1
  337.     esquive()
  338.   elseif i.name == "tconstruct:ore" and i.metadata == 1 then --1.12.2
  339.     print(a,i.name)
  340.     print("je mine pas l'ardite")
  341.     anb = anb + 1
  342.     esquive()
  343.   elseif i.name == "minecraft:ancient_debris" then --1.16.5
  344.     print(d,i.name)
  345.     print("je mine pas l'ancien debris")
  346.     dnb = dnb + 1
  347.     esquive()
  348.   elseif i.name == "allthemodium:vibranium_ore" then -- 1.16.5
  349.     print(v,i.name)
  350.     print("je mine pas le vibranium")
  351.     vnb = vnb + 1
  352.     esquive()
  353.     else
  354.     forward()
  355.     if turtle.getItemCount(dernierSlot) >= 1 then
  356.       print("videInventaire")
  357.       videInventaire()
  358.     end
  359.     ligneEnCour = ligneEnCour +1
  360.   end
  361. end
  362.  
  363. function changeDir()
  364.   if dir == 0 then
  365.     turtle.turnRight()
  366.     turtle.dig()
  367.     turtle.forward()
  368.     turtle.turnRight()
  369.     dir = dir+1
  370.     tourne = "je vais a droite"
  371.     --sleep(2)
  372.     tourne = "Je fais rien"
  373.   elseif dir == 1 then
  374.     turtle.turnLeft()
  375.     turtle.dig()
  376.     turtle.forward()
  377.     turtle.turnLeft()
  378.     dir = dir-1
  379.     tourne = "je vais a gauche"
  380.     --sleep(2)
  381.     tourne = "Je fais rien"
  382.   end
  383. end
  384.  
  385. function changeDirBottom()
  386.     turtle.turnRight()
  387.     turtle.turnRight()
  388.     turtle.digDown()
  389.     turtle.down()
  390.     descend = "je descend"
  391.     --sleep(2)
  392.     descend = "Je fais rien"
  393. end
  394.  
  395. -- function videInventaire()
  396.   -- Etat = "videInventaire"
  397.   -- local slot
  398.   -- turtle.select(chestNetherrack)
  399.   -- while not turtle.placeUp() do
  400.     -- sleep(0.1)
  401.     -- print("je peut pas placer en haut")
  402.     -- if not turtle.attackUp() then turtle.digUp() end
  403.   -- end
  404.   -- for slot=premierSlot,dernierSlot do
  405.     -- turtle.select(slot)
  406.     -- while turtle.getItemCount(slot) > 0 do
  407.       -- turtle.dropUp(turtle.getItemCount(slot))
  408.       -- if turtle.getItemCount(slot) > 0 then
  409.         -- sleep(0.5)
  410.       -- end
  411.     -- end
  412.   -- end
  413.   -- turtle.select(chestNetherrack)
  414.   -- turtle.digUp()
  415.   -- Etat = "En cours"
  416. -- end
  417.  
  418. function deplacement()
  419. if turtle.getFuelLevel() == 0 then -- check if we ran out of fuel
  420.     rechargeCharbon()
  421. end
  422. turtle.inspect()
  423. turtle.dig()
  424. turtle.forward()
  425.   for i=1, profondeur do
  426.     --print("debut while profondeur")
  427.     for j=1, colonne do
  428.     z = j
  429.       --print("debut while colonne")
  430.       ligneEnCour = 1
  431.       while ligneEnCour <= ligne-1 do
  432.         --print('debut while ligne')
  433.         refuel()
  434.         --print("Fuel: " ..turtle.getFuelLevel())
  435.         scan()
  436.         --print('fin du scan')
  437.       end
  438.      -- print('fin while ligne')
  439.       if j ~= colonne then
  440.         changeDir()
  441.         --print("Colonne: " ..j)
  442.         --print('fin while colonne')
  443.       end
  444.       --print('je tourne')
  445.     end
  446.     rechargeCharbon()
  447.     y = i
  448.     changeDirBottom()
  449.     --print("Profondeur: " ..i)
  450.     --print("je dessens")
  451.   end
  452.     --print("debut while profondeur")
  453.     for j=1, colonne do
  454.     z = j
  455.       --print("debut while colonne")
  456.       ligneEnCour = 1
  457.       while ligneEnCour <= ligne-1 do
  458.         --print('debut while ligne')
  459.         refuel()
  460.         --print("Fuel: " ..turtle.getFuelLevel())
  461.         scan()
  462.         --print('fin du scan')
  463.       end
  464.       --print('fin while ligne')
  465.       if j ~= colonne then
  466.         changeDir()
  467.         --print("Colonne :" ..j)
  468.         --print('fin while colonne')
  469.       end
  470.       --print('je tourne')
  471.     end
  472.     rechargeCharbon()
  473. end
  474.  
  475. --while not turtle.detect() do
  476. --  if not turtle.forward() then
  477. --    if turtle.attack() then -- check if a mob is in the way
  478. --      while turtle.attack() do end -- attack it until it is gone
  479. --    elseif turtle.getFuelLevel() == 0 then -- check if we ran out of fuel
  480. --    end
  481. --  end
  482. --end
  483.  
  484. function printText(txt1, color1)
  485. local oldColor = term.getTextColor() -- sauvegarde de la couleur courante
  486.   term.setTextColor(color1)
  487.   print(txt1)
  488.   term.setTextColor(oldColor) -- restauration de la couleur courante
  489. end
  490.  
  491. function printDoubleText(txt1, color1, txt2, color2)
  492. local oldColor = term.getTextColor() -- sauvegarde de la couleur courante
  493.   term.setTextColor(color1)
  494.   term.write(txt1)
  495.   term.setTextColor(color2)
  496.   term.write(txt2)
  497.   term.setTextColor(oldColor) -- restauration de la couleur courante
  498. end
  499. --------------------------------------------
  500. --------------- Programme ------------------
  501. --------------------------------------------
  502. function prog()
  503. term.setBackgroundColor(colors.gray)
  504. term.clear()
  505. term.setCursorPos(1,1)
  506. if version == "1.12.2" then
  507.     --print("La version est : " ..version)
  508.     printDoubleText("La version est : ", colors.yellow, version, colors.green)
  509. else
  510.     printDoubleText("La version est : ", colors.yellow, version, colors.green)
  511. end
  512. paintutils.drawFilledBox(2,2,2,2,colors.white)
  513. paintutils.drawFilledBox(3,2,3,2,colors.white)
  514. paintutils.drawFilledBox(4,2,4,2,colors.white)
  515. paintutils.drawFilledBox(5,2,5,2,colors.white)
  516.  
  517. paintutils.drawFilledBox(2,3,2,3,colors.white)
  518. paintutils.drawFilledBox(3,3,3,3,colors.white)
  519. paintutils.drawFilledBox(4,3,4,3,colors.white)
  520. paintutils.drawFilledBox(5,3,5,3,colors.white)
  521.  
  522. paintutils.drawFilledBox(2,4,2,4,colors.white)
  523. paintutils.drawFilledBox(3,4,3,4,colors.white)
  524. paintutils.drawFilledBox(4,4,4,4,colors.white)
  525. paintutils.drawFilledBox(5,4,5,4,colors.white)
  526.  
  527. paintutils.drawFilledBox(2,5,2,5,colors.white)
  528. paintutils.drawFilledBox(3,5,3,5,colors.white)
  529. paintutils.drawFilledBox(4,5,4,5,colors.white)
  530. paintutils.drawFilledBox(5,5,5,5,colors.white)
  531. term.setBackgroundColor(colors.gray)
  532.  
  533. local items ={}
  534.     for i = 14,16 do
  535. local data = turtle.getItemDetail(i)
  536.     if data then
  537.         if turtle.getItemCount(14) >= 1 then
  538.             items[i]={name=data.name,count=data.count}
  539.             if data.name == "minecraft:coal" then -- test
  540.                 paintutils.drawFilledBox(5,5,5,5,colors.black)
  541.                 term.setBackgroundColor(colors.gray)
  542.                 --term.setCursorPos(1,6)
  543.                 --name = "coal x" .. data.count -- test
  544.                 --print(name)
  545.             elseif data.name == "enderstorage:ender_storage" then -- test
  546.                 paintutils.drawFilledBox(3,5,3,5,colors.yellow)
  547.                 paintutils.drawFilledBox(4,5,4,5,colors.brown)
  548.                 term.setBackgroundColor(colors.gray)
  549.                 --term.setCursorPos(1,7)
  550.                 --name = "ender chest x" .. data.count -- test
  551.                 --print(name)
  552.            
  553.             else
  554.                 term.setCursorPos(2,6)
  555.                 print(data.name .. " x" .. data.count)
  556.                 paintutils.drawFilledBox(5,5,5,5,colors.red)
  557.             end
  558.         end
  559.     else
  560.     paintutils.drawFilledBox(5,5,5,5,colors.white)
  561.     term.setBackgroundColor(colors.gray)
  562.     term.setCursorPos(1,7)
  563.     printText("mettre les items:", colors.red)
  564.     printText("enderchest dans slot 14", colors.red)
  565.     printText("enderChestCharbon dans slot 15", colors.red)
  566.     printText("coal dans slot 16", colors.red)
  567.     sleep(10)
  568.     os.reboot()
  569.     end
  570. end
  571.  
  572. term.setBackgroundColor(colors.gray)
  573. term.setCursorPos(1,8)
  574. printText("Entrez les dimensions de la zone a miner:", colors.yellow)
  575. print("")
  576. printText("ligne (en face): ", colors.yellow)
  577. ligne = tonumber(read())
  578. printText("colonne (vers la droite): ", colors.yellow)
  579. colonne = tonumber(read())
  580. printText("profondeur (en dessous): ", colors.yellow)
  581. profondeur = tonumber(read())
  582.  
  583. printText("lignes: "..ligne.."  colonne: "..colonne.."  profondeur: "..profondeur, colors.yellow)
  584. local sum = (ligne * colonne * profondeur)
  585. printText("cube de " ..sum.. " m3", colors.red)
  586. printText("Valider les données? (oui/non) : ", colors.yellow)
  587.  
  588. local valider = read()
  589. if valider == "oui" or valider == "Oui" then
  590. -- local data = turtle.getItemDetail(chestNetherrack,chestCharbon)
  591.     -- if data then
  592.         -- items[chestNetherrack,chestCharbon]={name=data.name}
  593.         -- if data.name == "enderstorage:ender_chest" or data.name == "enderchests:ender_chest" then
  594.         -- else
  595.         -- print("il faut un enderchest dans le slot " ..chestNetherrack.. " et " ..chestCharbon)
  596.         -- end
  597.     -- end
  598. else os.reboot()
  599. end
  600.  
  601. rechargeCharbon()
  602.  
  603. if turtle.getFuelLevel() >= 64 then -- (profondeur*ligne*colonne)
  604.     deplacement()
  605. else
  606.     print("je reprend du charbon")
  607.     rechargeCharbon()
  608.     print("Fuel: " ..turtle.getFuelLevel())
  609.     deplacement()
  610.     if turtle.getItemCount(dernierSlot) >= 1 then
  611.         videInventaire()
  612.     end
  613. end
  614.     print("fin while profondeur")
  615.     videInventaire()
  616.     Etat = "Terminer"
  617.     turtle.select(premierSlot)
  618.     sleep(1)
  619. end
  620. parallel.waitForAny(prog,envoie)
  621.  
  622. -- envoyer les données au moniteur
  623. sendBlocks(blocks)
  624. -- afficher les blocs et leur quantité
  625. displayBlocks(blocks)
  626.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement