Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- variables
- local junkBlock = {"minecraft:stone","minecraft:sand","minecraft:dirt"}
- local isJunk = false
- local rawLenth = 1
- local rawNumber = 1
- local turtleOrientation = "n"
- local turtleXPos = 0
- local turtleYPos = 0
- local turtleZPos = 0
- -------------------------------------------
- -- Fonctions pour miner
- -------------------------------------------
- -- Fonction comparaison de block en face
- function compareBlockFront()
- if turtle.detect() == true then
- local isDetect, inspectedBlock = turtle.inspect()
- if isDetect == true then
- for i=1, table.getn(junkBlock) do
- if junkBlock[i] == inspectedBlock.name then
- isJunk = true
- return isJunk
- end
- end
- isJunk = false
- return isJunk
- end
- end
- end
- -- Fonction comparaison de block en haut
- function compareBlockUp()
- if turtle.detectUp() == true then
- local isDetect, inspectedBlock = turtle.inspectUp()
- if isDetect == true then
- for i=1, table.getn(junkBlock) do
- if junkBlock[i] == inspectedBlock.name then
- isJunk = true
- return isJunk
- end
- end
- isJunk = false
- return isJunk
- end
- end
- end
- -- Fonction comparaison de block en bas
- function compareBlockDown()
- if turtle.detectDown() == true then
- local isDetect, inspectedBlock = turtle.inspectDown()
- if isDetect == true then
- for i=1, table.getn(junkBlock) do
- if junkBlock[i] == inspectedBlock.name then
- isJunk = true
- return isJunk
- end
- end
- isJunk = false
- return isJunk
- end
- end
- end
- -- Fonction pour boucher les fuites en face
- function leakPluggingFront()
- if turtle.detect() == false then
- turtle.select(1)
- turtle.place()
- return true
- else
- return false
- end
- end
- -- Fonction pour boucher les fuites en haut
- function leakPluggingUp()
- if turtle.detectUp() == false then
- turtle.select(1)
- turtle.placeUp()
- return true
- else
- return false
- end
- end
- -- Fonction pour boucher les fuites en bas
- function leakPluggingDown()
- if turtle.detectDown() == false then
- turtle.select(1)
- turtle.placeDown()
- return true
- else
- return false
- end
- end
- -- Fonction pour miner en face
- function digFront()
- turtle.dig()
- turtle.select(2)
- turtle.place()
- end
- -- Fonction pour miner en haut
- function digUp()
- turtle.digUp()
- turtle.select(2)
- turtle.placeUp()
- end
- -- Fonction pour miner en bas
- function digDown()
- turtle.digDown()
- turtle.select(2)
- turtle.placeDown()
- end
- -- Changement de ligne de minage
- function newRaw()
- moveDown(1)
- turnLeft(1)
- moveForward(3)
- turnLeft(1)
- end
- -- Ligne de minage
- function digRaw(lenth)
- for i=1, lenth do
- moveForward(1)
- turnLeft(1)
- if compareBlockFront() == false then
- digFront()
- end
- turnRight(2)
- if compareBlockFront() == false then
- digFront()
- end
- turnLeft(1)
- if compareBlockDown() == false then
- digDown()
- end
- i=i+1
- end
- leakPluggingFront()
- moveUp(1)
- leakPluggingFront()
- turnRight(1)
- leakPluggingFront()
- turnLeft(2)
- leakPluggingFront()
- turnLeft(1)
- for i=1, lenth do
- moveForward(1)
- turnLeft(1)
- if compareBlockFront() == false then
- digFront()
- end
- turnRight(2)
- if compareBlockFront() == false then
- digFront()
- end
- turnLeft(1)
- if compareBlockUp() == false then
- digUp()
- end
- i=i+1
- end
- end
- -------------------------------------------
- -- Fonctions de positionnement
- -------------------------------------------
- -- Fonction de maj de l'orientation
- function setOrientTurtle(c)
- if c == "l" then
- if turtleOrientation == "n" then
- turtleOrientation = "w"
- elseif turtleOrientation == "e" then
- turtleOrientation = "n"
- elseif turtleOrientation == "s" then
- turtleOrientation = "e"
- elseif turtleOrientation == "w" then
- turtleOrientation = "s"
- end
- elseif c == "r" then
- if turtleOrientation == "n" then
- turtleOrientation = "e"
- elseif turtleOrientation == "e" then
- turtleOrientation = "s"
- elseif turtleOrientation == "s" then
- turtleOrientation = "w"
- elseif turtleOrientation == "w" then
- turtleOrientation = "n"
- end
- end
- print("new orientation : " .. turtleOrientation)
- end
- -- Fonction position courante
- function setCurrentPosition(d)
- if d == "f" and turtleOrientation == "n" then
- -- code moving north
- -- z-
- turtleZPos = turtleZPos - 1
- elseif d == "f" and turtleOrientation == "e" then
- -- code moving east
- -- x+
- turtleXPos = turtleXPos + 1
- elseif d == "f" and turtleOrientation == "s" then
- -- code moving south
- -- z+
- turtleZPos = turtleZPos + 1
- elseif d == "f" and turtleOrientation == "w" then
- -- code moving west
- -- x-
- turtleXPos = turtleXPos - 1
- elseif d == "u" then
- -- code moving up
- --y+
- turtleYPos = turtleYPos + 1
- elseif d == "d" then
- -- code moving down
- -- y-
- turtleYPos = turtleYPos - 1
- end
- print("new position : x=" .. turtleXPos .. ", y=" .. turtleYPos .. ", z=" .. turtleZPos)
- end
- -------------------------------------------
- -- Fonctions pour le deplacement
- -------------------------------------------
- -- Fonction pour se deplacer en avant
- function moveForward(lenth)
- floor = floor or false
- for i=1, lenth do
- if turtle.detect() == false then
- while turtle.forward() == false do
- turtle.attack()
- os.sleep(0.5)
- end
- else
- while turtle.forward() == false do
- turtle.dig()
- os.sleep(0.5)
- end
- end
- setCurrentPosition("f")
- i=i+1
- end
- end
- -- Fonction pour se deplacer en haut
- function moveUp(lenth)
- for i=1, lenth do
- if turtle.detectUp() == false then
- while turtle.up() == false do
- turtle.attack()
- os.sleep(0.5)
- end
- else
- while turtle.up() == false do
- turtle.digUp()
- os.sleep(0.5)
- end
- end
- setCurrentPosition("u")
- i=i+1
- end
- end
- -- Fonction pour se deplacer en bas
- function moveDown(lenth)
- for i=1, lenth do
- if turtle.detectDown() == false then
- while turtle.down() == false do
- turtle.attackDown()
- os.sleep(0.5)
- end
- else
- while turtle.down() == false do
- turtle.dig()
- os.sleep(0.5)
- end
- end
- setCurrentPosition("d")
- i=i+1
- end
- end
- -- Fonction pour tourner a droite
- function turnRight(nb)
- for i=1, nb do
- turtle.turnRight()
- setOrientTurtle("r")
- i=i+1
- end
- end
- -- Fonction pour tourner a gauche
- function turnLeft(nb)
- for i=1, nb do
- turtle.turnLeft()
- setOrientTurtle("l")
- i=i+1
- end
- end
- -------------------------------------------
- -- Inventaire
- -------------------------------------------
- -- placer un block en face
- function place(slot)
- slot = slot or turtle.getSelectedSlot()
- turtle.select(slot)
- turtle.place()
- end
- -- placer un block en haut
- function placeUp(slot)
- slot = slot or turtle.getSelectedSlot()
- turtle.select(slot)
- turtle.placeUp()
- end
- -- placer un block en bas
- function placeDown(slot)
- slot = slot or turtle.getSelectedSlot()
- turtle.select(slot)
- turtle.placeDown()
- end
- -- gestion des slots rΓ©servΓ©s
- -------------------------------------------
- -- Gestion du carburant
- -------------------------------------------
- -- Controle du niveau de carburant
- function fuelLevel(lenth)
- fuelLevel = turtle.getFuelLevel()
- if fuelLevel <= lenth + 5 then
- goRefuel()
- end
- end
- -- Retour pour faire le plein de carburant
- function goRefuel()
- oldPosX = turtleXPos
- oldPosY = turtleYPos
- oldPosZ = turtleZPos
- moveXgo = turtleXPos * -1
- moveYgo = turtleYPos * -1
- moveZgo = turtleZPos * -1
- if moveXgo < 0 then
- while turtleOrientation ~= "w" do
- turnRight(1)
- end
- moveForward(math.abs(moveXgo))
- elseif 0 < moveXgo then
- while turtleOrientation ~= "e" do
- turnLeft(1)
- end
- moveForward(moveXgo)
- elseif moveZgo < 0 then
- while turtleOrientation ~= "s" do
- turnRight(1)
- end
- moveForward(math.abs(moveZgo))
- elseif 0 < moveZgo then
- while turtleOrientation ~= "n" do
- turnLeft(1)
- end
- moveForward(moveZgo)
- elseif moveYgo < 0 then
- moveUp(1)
- elseif 0 < moveYgo
- moveDown(1)
- end
- -- orienter la turtle vers le coffre de carburant
- -- vider l'inventaire au passage
- -- renvoyer la turtle au point de minage
- end
- -- Recharger en carburant
- -------------------------------------------
- -- Mise en route
- -------------------------------------------
- -- Initialisation du minage
- print("I am in what direction ?")
- print("n = north")
- print("e = east")
- print("s = south")
- print("w = west")
- turtleOrientation = read()
- -- saisie des dimentions de minage
- print("Lenth of eatch raw ?")
- rawLenth = read()
- print("Number of raw ?")
- rawNumber = read()
- for i=1, rawNumber do
- digRaw(rawLenth)
- newRaw()
- end
- turnLeft(1)
- moveUp(1)
- moveForward(rawNumber*3)
- turnLeft(1)
- moveDown(1)
- moveForward(1)
- -- vider l'inventaire
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement