Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local id = 6 -- id du monitor qui recois
- local c = "Cobalt" --1.12.2 1.16.5
- local cnb = 0
- local a = "Ardite" -- 1.12.2
- local anb = 0
- local v = "Vibranium" -- 1.16.5
- local vnb = 0
- local d = "Debris" -- 1.16.5
- local dnb = 0
- local ligne = 0
- local colonne = 0
- local profondeur = 0
- local premierSlot = 1
- local dernierSlot = 13
- local chestNetherrack = 14
- local chestCharbon = 15
- local charbonSlot = 16
- local dir = 0
- local ligneEnCour = 0
- local idChannel = 8899 -- n'est pas utiliser
- local esquive = 0
- local EnvoieRednet = {}
- local Etat = "En cours"
- local Mob = "Pas de Mob"
- local z = 0 -- 0
- local y = 0 -- 0
- local tourne = ""
- local descend = ""
- local MAX_ITEMS_TO_SUCK = 30
- local MIN_ITEMS_TO_KEEP = 5
- local version = "1.12.2"
- local modem = peripheral.find("modem") -- Remplacez "modem" par le nom de votre modem
- modem.open(1)
- -- initialiser le tableau des blocs minés
- local blocks = {}
- --fonction pour afficher les blocs et leur quantité avec pagination
- local function displayBlocks(blocks)
- local page = 1
- local pageSize = 10
- local blockList = {}
- for block, count in pairs(blocks) do
- local colonIndex = string.find(block, ":", 1, true)
- local name = string.sub(block, colonIndex + 1)
- table.insert(blockList, name .. " x" .. count)
- end
- while true do
- --afficher la page courante
- term.clear()
- term.setCursorPos(1,1)
- print("Blocks Mined (Page " .. page .. "):")
- for i = (page-1)*pageSize+1,page*pageSize do
- if blockList[i] then
- print("- " .. blockList[i])
- else
- break
- end
- end
- --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
- else
- break
- end
- end
- end
- -- fonction pour afficher les blocs et leur quantité sans pagination
- -- local function displayBlocks(blocks)
- -- print("Blocks Mined:")
- -- for block, count in pairs(blocks) do
- -- local colonIndex = string.find(block, ":", 1, true)
- -- local name = string.sub(block, colonIndex + 1)
- -- print("-" .. name .. " x" .. count)
- -- end
- -- end
- -- fonction pour envoyer les données au moniteur
- local function sendBlocks(blocks)
- local message = textutils.serializeJSON(blocks)
- modem.transmit(1, 1, message)
- end
- function envoie()
- while true do
- EnvoieRednet = {Tourne=tourne,Descend=descend,NivFuel=turtle.getFuelLevel(),Monstre=Mob,
- Cobalt=cnb,Ardite=anb,Vibranium=vnb,Debris=dnb,LigneEnCour=ligneEnCour,Colonne=z,Profondeur=y,Etat=Etat,
- ProfondeurMax=profondeur,colonneMax=colonne,ligneMax=ligne,Charbon=turtle.getItemCount(charbonSlot),slot=scantest()}
- rednet.send(id,textutils.serialise(EnvoieRednet))
- sleep(0.5)
- end
- end
- -- Table des minerais à éviter
- -- local oresToAvoid = {
- -- ["tconstruct:ore"] = {
- -- [0] = "cobalt_ore", -- 1.12.2
- -- [1] = "ardite_ore" -- 1.12.2
- -- },
- -- ["minecraft:ancient_debris"] = true, -- 1.16.5
- -- ["allthemodium:vibranium_ore"] = true -- 1.16.5
- -- }
- -- Fonction pour vérifier si un minerai doit être évité
- -- function shouldAvoidOre(oreName, oreMetadata)
- -- if not oresToAvoid[oreName] then
- -- return false
- -- end
- -- if type(oresToAvoid[oreName]) == "boolean" then
- -- return true
- -- end
- -- return oresToAvoid[oreName][oreMetadata] ~= nil
- -- end
- function esquive()
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- ligneEnCour = ligneEnCour +2
- end
- function scantest()
- local items ={}
- for i = premierSlot,dernierSlot do
- local data = turtle.getItemDetail(i)
- if data then
- items[i]={name=data.name,count=data.count}
- end
- end
- return items
- end
- function refuel()
- if turtle.getFuelLevel() < 10 then
- turtle.select(charbonSlot)
- turtle.refuel(5)
- rechargeCharbon()
- end
- turtle.select(premierSlot)
- end
- function ifItemCharbonSlot()
- if turtle.getItemCount() >= 1 then
- turtle.drop()
- end
- end
- -- Fonctions
- local function checkInventory()
- if turtle.getItemCount() <= MIN_ITEMS_TO_KEEP then
- return true
- end
- return false
- end
- local function suckItems(direction, maxItems)
- for i = 1, maxItems do
- if not turtle.suck(direction) then
- break
- end
- end
- end
- function rechargeCharbon()
- Etat = "rechargeCharbon"
- turtle.select(charbonSlot)
- if checkInventory() then
- if not turtle.digUp() then
- turtle.digDown()
- turtle.select(chestCharbon)
- turtle.placeDown()
- turtle.select(charbonSlot)
- ifItemCharbonSlot()
- turtle.suckDown(MAX_ITEMS_TO_SUCK)
- turtle.select(chestCharbon)
- turtle.digDown()
- turtle.select(premierSlot) -- pas obliger a voir
- sleep(0.5)
- else
- turtle.select(chestCharbon)
- turtle.placeUp()
- turtle.select(charbonSlot)
- ifItemCharbonSlot()
- turtle.suckUp(MAX_ITEMS_TO_SUCK)
- turtle.select(chestCharbon)
- turtle.digUp()
- turtle.select(premierSlot) -- pas obliger a voir
- sleep(0.5)
- end
- end
- refuel() -- pas obliger a voir
- Etat = "En cours"
- end
- -- Chat gpt
- -- function Attack()
- -- local hasAttacked = false
- -- while not hasAttacked do
- ----Move forward and attempt to attack any mobs in the way
- -- if turtle.detect() then
- -- turtle.attack()
- -- hasAttacked = true
- -- elseif not turtle.forward() then
- ----If turtle cannot move forward, stop attacking
- -- hasAttacked = true
- -- end
- -- end
- -- print(ligneEnCour)
- -- print(z)
- -- print(y)
- -- getFuelLevel()
- -- end
- function Attack()
- if turtle.attack() then
- turtle.attack()
- sleep(0.5)
- turtle.attack()
- sleep(0.5)
- turtle.attack()
- sleep(0.5)
- turtle.attack()
- sleep(0.5)
- turtle.attack()
- sleep(0.5)
- turtle.attack()
- sleep(0.5)
- turtle.attack()
- sleep(0.5)
- turtle.attack()
- sleep(0.5)
- turtle.attack()
- sleep(0.5)
- turtle.attack()
- sleep(0.5)
- turtle.attack()
- sleep(0.5)
- turtle.attack()
- sleep(0.5)
- else
- print("je ne peut pas attaquer")
- sleep(1)
- end
- print("menace eliminer")
- refuel() -- pas obliger a voir
- end
- function forward()
- turtle.select(premierSlot)
- turtle.dig()
- --print("je creuse")
- if not turtle.forward() then
- Mob = "Il y a un mob"
- Attack()
- Mob = "Plus de Mob"
- --turtle.forward()
- else
- return true
- end
- end
- function videInventaire()
- Etat = "videInventaire"
- turtle.select(chestNetherrack)
- if not turtle.placeUp() then
- print("Je ne peux pas enlever en haut je place en bas")
- turtle.digDown()
- turtle.placeDown()
- vidageDown()
- else
- print("Je peux placer en haut")
- vidageUp()
- end
- end
- function vidageUp()
- local slot
- for slot=premierSlot,dernierSlot do
- turtle.select(slot)
- while turtle.getItemCount(slot) > 0 do
- turtle.dropUp(turtle.getItemCount(slot))
- end
- end
- turtle.select(chestNetherrack)
- sleep(0.5)
- print("je recupere la turtle")
- turtle.digUp()
- Etat = "En cours"
- end
- function vidageDown()
- local slot
- for slot=premierSlot,dernierSlot do
- turtle.select(slot)
- while turtle.getItemCount(slot) > 0 do
- turtle.dropDown(turtle.getItemCount(slot))
- end
- end
- turtle.select(chestNetherrack)
- sleep(0.5)
- print("je recupere la turtle")
- turtle.digDown()
- Etat = "En cours"
- end
- function scan()
- local success,i = turtle.inspect()
- if success then
- local block = i.name
- blocks[block] = (blocks[block] or 0) + 1
- end
- -- Code pour vérifier si un minerai doit être évité et appeler la fonction esquive() si nécessaire
- -- if shouldAvoidOre(i.name, i.metadata) then
- -- print(i.name .. " : je ne le mine pas")
- -- esquive()
- if i.name == "tconstruct:ore" and i.metadata == 0 then --1.12.2
- --if i.name == "tconstruct:cobalt_ore" then -- 1.16.5
- print(c,i.name)
- print("je mine pas le cobalt")
- cnb = cnb + 1
- esquive()
- elseif i.name == "tconstruct:ore" and i.metadata == 1 then --1.12.2
- print(a,i.name)
- print("je mine pas l'ardite")
- anb = anb + 1
- esquive()
- elseif i.name == "minecraft:ancient_debris" then --1.16.5
- print(d,i.name)
- print("je mine pas l'ancien debris")
- dnb = dnb + 1
- esquive()
- elseif i.name == "allthemodium:vibranium_ore" then -- 1.16.5
- print(v,i.name)
- print("je mine pas le vibranium")
- vnb = vnb + 1
- esquive()
- else
- forward()
- if turtle.getItemCount(dernierSlot) >= 1 then
- print("videInventaire")
- videInventaire()
- end
- ligneEnCour = ligneEnCour +1
- end
- end
- function changeDir()
- if dir == 0 then
- turtle.turnRight()
- turtle.dig()
- turtle.forward()
- turtle.turnRight()
- dir = dir+1
- tourne = "je vais a droite"
- --sleep(2)
- tourne = "Je fais rien"
- elseif dir == 1 then
- turtle.turnLeft()
- turtle.dig()
- turtle.forward()
- turtle.turnLeft()
- dir = dir-1
- tourne = "je vais a gauche"
- --sleep(2)
- tourne = "Je fais rien"
- end
- end
- function changeDirBottom()
- turtle.turnRight()
- turtle.turnRight()
- turtle.digDown()
- turtle.down()
- descend = "je descend"
- --sleep(2)
- descend = "Je fais rien"
- end
- -- function videInventaire()
- -- Etat = "videInventaire"
- -- local slot
- -- turtle.select(chestNetherrack)
- -- while not turtle.placeUp() do
- -- sleep(0.1)
- -- print("je peut pas placer en haut")
- -- if not turtle.attackUp() then turtle.digUp() end
- -- end
- -- for slot=premierSlot,dernierSlot do
- -- turtle.select(slot)
- -- while turtle.getItemCount(slot) > 0 do
- -- turtle.dropUp(turtle.getItemCount(slot))
- -- if turtle.getItemCount(slot) > 0 then
- -- sleep(0.5)
- -- end
- -- end
- -- end
- -- turtle.select(chestNetherrack)
- -- turtle.digUp()
- -- Etat = "En cours"
- -- end
- function deplacement()
- if turtle.getFuelLevel() == 0 then -- check if we ran out of fuel
- rechargeCharbon()
- end
- turtle.inspect()
- turtle.dig()
- turtle.forward()
- for i=1, profondeur do
- --print("debut while profondeur")
- for j=1, colonne do
- z = j
- --print("debut while colonne")
- ligneEnCour = 1
- while ligneEnCour <= ligne-1 do
- --print('debut while ligne')
- refuel()
- --print("Fuel: " ..turtle.getFuelLevel())
- scan()
- --print('fin du scan')
- end
- -- print('fin while ligne')
- if j ~= colonne then
- changeDir()
- --print("Colonne: " ..j)
- --print('fin while colonne')
- end
- --print('je tourne')
- end
- rechargeCharbon()
- y = i
- changeDirBottom()
- --print("Profondeur: " ..i)
- --print("je dessens")
- end
- --print("debut while profondeur")
- for j=1, colonne do
- z = j
- --print("debut while colonne")
- ligneEnCour = 1
- while ligneEnCour <= ligne-1 do
- --print('debut while ligne')
- refuel()
- --print("Fuel: " ..turtle.getFuelLevel())
- scan()
- --print('fin du scan')
- end
- --print('fin while ligne')
- if j ~= colonne then
- changeDir()
- --print("Colonne :" ..j)
- --print('fin while colonne')
- end
- --print('je tourne')
- end
- rechargeCharbon()
- end
- --while not turtle.detect() do
- -- if not turtle.forward() then
- -- if turtle.attack() then -- check if a mob is in the way
- -- while turtle.attack() do end -- attack it until it is gone
- -- elseif turtle.getFuelLevel() == 0 then -- check if we ran out of fuel
- -- end
- -- end
- --end
- 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 printDoubleText(txt1, color1, txt2, color2)
- local oldColor = term.getTextColor() -- sauvegarde de la couleur courante
- term.setTextColor(color1)
- term.write(txt1)
- term.setTextColor(color2)
- term.write(txt2)
- term.setTextColor(oldColor) -- restauration de la couleur courante
- end
- --------------------------------------------
- --------------- Programme ------------------
- --------------------------------------------
- function prog()
- term.setBackgroundColor(colors.gray)
- term.clear()
- term.setCursorPos(1,1)
- if version == "1.12.2" then
- --print("La version est : " ..version)
- printDoubleText("La version est : ", colors.yellow, version, colors.green)
- else
- printDoubleText("La version est : ", colors.yellow, version, colors.green)
- end
- paintutils.drawFilledBox(2,2,2,2,colors.white)
- paintutils.drawFilledBox(3,2,3,2,colors.white)
- paintutils.drawFilledBox(4,2,4,2,colors.white)
- paintutils.drawFilledBox(5,2,5,2,colors.white)
- paintutils.drawFilledBox(2,3,2,3,colors.white)
- paintutils.drawFilledBox(3,3,3,3,colors.white)
- paintutils.drawFilledBox(4,3,4,3,colors.white)
- paintutils.drawFilledBox(5,3,5,3,colors.white)
- paintutils.drawFilledBox(2,4,2,4,colors.white)
- paintutils.drawFilledBox(3,4,3,4,colors.white)
- paintutils.drawFilledBox(4,4,4,4,colors.white)
- paintutils.drawFilledBox(5,4,5,4,colors.white)
- paintutils.drawFilledBox(2,5,2,5,colors.white)
- paintutils.drawFilledBox(3,5,3,5,colors.white)
- paintutils.drawFilledBox(4,5,4,5,colors.white)
- paintutils.drawFilledBox(5,5,5,5,colors.white)
- term.setBackgroundColor(colors.gray)
- local items ={}
- for i = 14,16 do
- local data = turtle.getItemDetail(i)
- if data then
- if turtle.getItemCount(14) >= 1 then
- items[i]={name=data.name,count=data.count}
- if data.name == "minecraft:coal" then -- test
- paintutils.drawFilledBox(5,5,5,5,colors.black)
- term.setBackgroundColor(colors.gray)
- --term.setCursorPos(1,6)
- --name = "coal x" .. data.count -- test
- --print(name)
- elseif data.name == "enderstorage:ender_storage" then -- test
- paintutils.drawFilledBox(3,5,3,5,colors.yellow)
- paintutils.drawFilledBox(4,5,4,5,colors.brown)
- term.setBackgroundColor(colors.gray)
- --term.setCursorPos(1,7)
- --name = "ender chest x" .. data.count -- test
- --print(name)
- else
- term.setCursorPos(2,6)
- print(data.name .. " x" .. data.count)
- paintutils.drawFilledBox(5,5,5,5,colors.red)
- end
- end
- else
- paintutils.drawFilledBox(5,5,5,5,colors.white)
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(1,7)
- printText("mettre les items:", colors.red)
- printText("enderchest dans slot 14", colors.red)
- printText("enderChestCharbon dans slot 15", colors.red)
- printText("coal dans slot 16", colors.red)
- sleep(10)
- os.reboot()
- end
- end
- term.setBackgroundColor(colors.gray)
- term.setCursorPos(1,8)
- printText("Entrez les dimensions de la zone a miner:", colors.yellow)
- print("")
- printText("ligne (en face): ", colors.yellow)
- ligne = tonumber(read())
- printText("colonne (vers la droite): ", colors.yellow)
- colonne = tonumber(read())
- printText("profondeur (en dessous): ", colors.yellow)
- profondeur = tonumber(read())
- printText("lignes: "..ligne.." colonne: "..colonne.." profondeur: "..profondeur, colors.yellow)
- local sum = (ligne * colonne * profondeur)
- printText("cube de " ..sum.. " m3", colors.red)
- printText("Valider les données? (oui/non) : ", colors.yellow)
- local valider = read()
- if valider == "oui" or valider == "Oui" then
- -- local data = turtle.getItemDetail(chestNetherrack,chestCharbon)
- -- if data then
- -- items[chestNetherrack,chestCharbon]={name=data.name}
- -- if data.name == "enderstorage:ender_chest" or data.name == "enderchests:ender_chest" then
- -- else
- -- print("il faut un enderchest dans le slot " ..chestNetherrack.. " et " ..chestCharbon)
- -- end
- -- end
- else os.reboot()
- end
- rechargeCharbon()
- if turtle.getFuelLevel() >= 64 then -- (profondeur*ligne*colonne)
- deplacement()
- else
- print("je reprend du charbon")
- rechargeCharbon()
- print("Fuel: " ..turtle.getFuelLevel())
- deplacement()
- if turtle.getItemCount(dernierSlot) >= 1 then
- videInventaire()
- end
- end
- print("fin while profondeur")
- videInventaire()
- Etat = "Terminer"
- turtle.select(premierSlot)
- sleep(1)
- end
- parallel.waitForAny(prog,envoie)
- -- envoyer les données au moniteur
- sendBlocks(blocks)
- -- afficher les blocs et leur quantité
- displayBlocks(blocks)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement