Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI("posapi")
- os.loadAPI("cookieapi")
- -- Configuration de l'inventaire
- local slot = {}
- slot["torch"] = 16
- slot["chest"] = 15
- -- Direction d'origine (direction des tunnels)
- local startDir = posapi.getDir()
- local startX = posapi.x
- local startY = posapi.y
- local startZ = posapi.z
- -- Longueur des tunnels
- local length = 0
- -- Nombre de paliers
- local nbFloors = 0
- -- Place une torche sur le mur
- function wallTorch()
- turtle.select(slot.torch)
- turtle.place()
- turtle.select(1)
- end
- -- -------------------
- -- Tunnel
- -- -------------------
- -- Mine in a quarry pattern until we hit something we can't dig
- local depth = 0
- local collected = 0
- local function collect()
- collected = collected + 1
- if math.fmod(collected, 25) == 0 then
- print( "Mined "..collected.." items." )
- end
- end
- local function tryDig()
- while turtle.detect() do
- if turtle.dig() then
- collect()
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryDigUp()
- while turtle.detectUp() do
- if turtle.digUp() then
- collect()
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function tryDigDown()
- while turtle.detectDown() do
- if turtle.digDown() then
- collect()
- sleep(0.5)
- else
- return false
- end
- end
- return true
- end
- local function refuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel == "unlimited" or fuelLevel > 0 then
- return
- end
- local function tryRefuel()
- for n=1,14 do -- Edit: slot 15 et 16 réservés
- if turtle.getItemCount(n) > 0 then
- turtle.select(n)
- if turtle.refuel(1) then
- turtle.select(1)
- return true
- end
- end
- end
- turtle.select(1)
- return false
- end
- if not tryRefuel() then
- print( "Add more fuel to continue." )
- while not tryRefuel() do
- sleep(1)
- end
- print( "Resuming Tunnel." )
- end
- end
- local function tryUp()
- refuel()
- while not posapi.tup() do
- if turtle.detectUp() then
- if not tryDigUp() then
- return false
- end
- elseif turtle.attackUp() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function tryDown()
- refuel()
- while not posapi.tdown() do
- if turtle.detectDown() then
- if not tryDigDown() then
- return false
- end
- elseif turtle.attackDown() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function tryForward()
- refuel()
- while not posapi.tforward() do
- if turtle.detect() then
- if not tryDig() then
- return false
- end
- elseif turtle.attack() then
- collect()
- else
- sleep( 0.5 )
- end
- end
- return true
- end
- local function tunnel()
- print( "Tunnelling..." )
- -- Alternateur torches
- local torchAlt = false
- -- 4 = Position de la première torch
- local torchPos = 4
- for n=1,length do
- turtle.placeDown()
- tryDigUp()
- posapi.tleft()
- tryDig()
- tryUp()
- tryDig()
- -- Place une torche à gauche
- if n == torchPos and torchAlt then
- wallTorch()
- torchPos = torchPos + 9
- torchAlt = not torchAlt
- end
- posapi.tright()
- posapi.tright()
- tryDig()
- -- Place une torche à droite
- if n == torchPos and not torchAlt then
- wallTorch()
- torchPos = torchPos + 9
- torchAlt = not torchAlt
- end
- tryDown()
- tryDig()
- posapi.tleft()
- if n<length then
- tryDig()
- if not tryForward() then
- print( "Aborting Tunnel." )
- break
- end
- else
- print( "Tunnel complete." )
- end
- end
- --[[
- print( "Returning to start..." )
- -- Return to where we started
- turtle.turnLeft()
- turtle.turnLeft()
- while depth > 0 do
- if turtle.forward() then
- depth = depth - 1
- else
- turtle.dig()
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- ]]
- depth = 0
- print( "Tunnel complete." )
- print( "Mined "..collected.." items total." )
- end
- -- -------------------------------
- -- Escalier, goto next tunnel (up)
- -- -------------------------------
- local function nextTunnel()
- local alt = ( posapi.getDir() == startDir )
- tryForward()
- turtle.placeDown()
- tryUp()
- tryDigUp()
- if alt then
- posapi.tleft()
- else
- posapi.tright()
- end
- tryForward()
- turtle.placeDown()
- tryUp()
- tryDigUp()
- tryForward()
- turtle.placeDown()
- tryDigUp()
- tryForward()
- turtle.placeDown()
- tryDigUp()
- tryForward()
- turtle.placeDown()
- tryDigUp()
- if alt then
- posapi.tleft()
- else
- posapi.tright()
- end
- end
- -- ------
- -- INIT
- -- ------
- if not posapi.x
- or not posapi.y
- or not posapi.y then
- posapi.calibrate()
- end
- while not length or length <= 0 do
- print("")
- write("Longueur du tunnel ? ")
- local input = read()
- length = tonumber(input)
- end
- while not nbFloors or nbFloors <= 0 do
- print("")
- write("Nombre de paliers ? ")
- local input = read()
- nbFloors = tonumber(input)
- end
- -- Goto Start pos
- for n=1,nbFloors do
- print("Start floor "..n)
- tunnel()
- if n < nbFloors then
- nextTunnel()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment