Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --number of tunnels (2 blocks in between)
- numTunnels = 20
- --length of single tunnel
- lenTunnel = 30
- --side for the tunnels
- tunnelSide = "left"
- --uses or destroys bordering lava
- bLava = true
- --uses or destroys all connected lava
- bAllLava = true
- --testRun, only Tunnels
- bTest = false
- --Counter for found lava springs
- lavaCnt = 0
- blocksToMine = {
- "minecraft:copper_ore", "minecraft:deepslate_copper_ore",
- "minecraft:coal_ore", "deepslate_coal_ore",
- "minecraft:iron_ore", "minecraft:deepslate_iron_ore",
- "minecraft:gold_ore", "minecraft:deepslate_gold_ore",
- "minecraft:deepslate_diamond_ore", "minecraft:diamond_ore",
- "minecraft:emerald_ore", "minecraft:deepslate_emerald_ore",
- "minecraft:redstone_ore", "minecraft:deepslate_redstone_ore",
- "minecraft:lapis_ore", "minecraft:deepslate_lapis_ore",
- "minecraft:nether_gold_ore", "minecraft:nether_quartz_ore",
- "minecraft:ancient_debris"
- }
- notDroppedBlocks = {
- "minecraft:chest", "minecraft:torch",
- "minecraft:bucket", "minecraft:lava_bucket"
- }
- lavaArray = {"minecraft:lava"}
- bucketList = {"minecraft:bucket", "minecraft:lava_bucket"}
- -- tries to refuel till possible
- function refuelProcess()
- local cnt = 0
- local bFueld = false
- while not bFueld do
- for i = 1, 16, 1 do
- turtle.select(i)
- local item = turtle.getItemDetail()
- if item then
- if not (item.name == "minecraft:chest") then
- local ok, err = turtle.refuel()
- end
- end
- end
- if turtle.getFuelLevel() > 0 then
- print("New fuel level: " .. tostring(turtle.getFuelLevel()))
- return true
- end
- if cnt == 0 then
- print("Pls enter fuel to continue")
- end
- cnt = 1
- end
- return true
- end
- -- Checks if fuel is available or starts refuel process
- function fuelCheck()
- if turtle.getFuelLevel() > 0 then
- return
- else
- refuelProcess()
- end
- end
- -- Digs in given direction till turtle can move
- function moveForward()
- fuelCheck()
- local b = false
- while not b do
- b = turtle.forward()
- if not b then
- turtle.dig()
- end
- end
- end
- function moveUp()
- fuelCheck()
- local b = false
- while not b do
- b = turtle.up()
- if not b then
- turtle.digUp()
- end
- end
- end
- function moveDown()
- fuelCheck()
- local b = false
- while not b do
- b = turtle.down()
- if not b then
- turtle.digDown()
- end
- end
- end
- -- Turn turtle 180°
- function turnBack()
- turtle.turnLeft()
- turtle.turnLeft()
- end
- -- turns into tunnel or back out in starting direction
- function takeTurn()
- if tunnelSide == "left" then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- end
- -- returns true if the block in this directions is in the given array
- function inspectForward(arr)
- local bBlockForward, data = turtle.inspect()
- local blockname = data.name
- if bBlockForward then
- for i = 1, #arr, 1 do
- if blockname == arr[i] then
- if blockname == "minecraft:lava" then
- local level = data.state.level
- if not (level == 0) then
- return false
- end
- end
- return true
- end
- end
- end
- return false
- end
- function inspectUp(arr)
- local bBlockUp, data = turtle.inspectUp()
- local blockname = data.name
- if bBlockUp then
- for i = 1, #arr, 1 do
- if blockname == arr[i] then
- if blockname == "minecraft:lava" then
- local level = data.state.level
- if not (level == 0) then
- return false
- end
- end
- return true
- end
- end
- end
- return false
- end
- function inspectDown(arr)
- local bBlockDown, data = turtle.inspectDown()
- local blockname = data.name
- if bBlockDown then
- for i = 1, #arr, 1 do
- if blockname == arr[i] then
- if blockname == "minecraft:lava" then
- local level = data.state.level
- if not (level == 0) then
- return false
- end
- end
- return true
- end
- end
- end
- return false
- end
- -- selects slot with bucket
- function selectBucket()
- local item = turtle.getItemDetail()
- if item then
- if (item.name == bucketList[1]) then
- return true
- end
- if (item.name == bucketList[2]) then
- return true
- end
- end
- for i=1, 16, 1 do
- turtle.select(i)
- item = turtle.getItemDetail()
- if item then
- if (item.name == bucketList[1]) then
- return true
- end
- if (item.name == bucketList[2]) then
- return true
- end
- end
- end
- return false
- end
- --Returns bool bFullTank and bBucketIsEmpty (if fuel is maximum and if bucket contains nothing)
- function getBucketAndFuelData()
- local fuelLevel = turtle.getFuelLevel()
- local maxFuelLevel = turtle.getFuelLimit()
- local bFullTank = (fuelLevel == maxFuelLevel)
- local bBucketIsEmpty = true
- local item = turtle.getItemDetail()
- if item then
- if (item.name == bucketList[1]) then
- bBucketIsEmpty = true
- end
- if (item.name == bucketList[2]) then
- bBucketIsEmpty = false
- end
- end
- return bFullTank, bBucketIsEmpty
- end
- --collects lava in this direction (tries to use it)
- function collectFrontLava()
- local bFullTank, bEmptyBucket = getBucketAndFuelData()
- local bRefueld = false
- if bEmptyBucket then
- turtle.place()
- end
- if not bFullTank then
- turtle.refuel()
- bRefueld = true
- end
- if not bEmptyBucket then
- turtle.place()
- if not bRefueld then
- turtle.place()
- end
- end
- lavaCnt = lavaCnt + 1
- end
- function collectTopLava()
- local bFullTank, bEmptyBucket = getBucketAndFuelData()
- local bRefueld = false
- if bEmptyBucket then
- turtle.placeUp()
- end
- if not bFullTank then
- turtle.refuel()
- bRefueld = true
- end
- if not bEmptyBucket then
- turtle.placeUp()
- if not bRefueld then
- turtle.placeUp()
- end
- end
- lavaCnt = lavaCnt + 1
- end
- function collectBottomLava()
- local bFullTank, bEmptyBucket = getBucketAndFuelData()
- local bRefueld = false
- if bEmptyBucket then
- turtle.placeDown()
- end
- if not bFullTank then
- turtle.refuel()
- bRefueld = true
- end
- if not bEmptyBucket then
- turtle.placeDown()
- if not bRefueld then
- turtle.placeDown()
- end
- end
- lavaCnt = lavaCnt + 1
- end
- -- collects all valuable blcoks that are connected to start block (+Lava collection/destruction possible)
- function collectAllValuables()
- local bLocLava = bLava
- if not selectBucket() then
- bLocLava = false
- end
- if inspectDown(blocksToMine) then
- moveDown()
- collectAllValuables()
- moveUp()
- elseif inspectDown(lavaArray) and bLocLava then
- collectBottomLava()
- if bAllLava then
- moveDown()
- collectAllValuables()
- moveUp()
- end
- end
- if inspectForward(blocksToMine) then
- moveForward()
- collectAllValuables()
- turnBack()
- moveForward()
- turnBack()
- elseif inspectForward(lavaArray) and bLocLava then
- collectFrontLava()
- if bAllLava then
- moveForward()
- collectAllValuables()
- turnBack()
- moveForward()
- turnBack()
- end
- end
- turtle.turnRight() -- right
- if inspectForward(blocksToMine) then
- moveForward()
- collectAllValuables()
- turnBack()
- moveForward()
- turnBack()
- elseif inspectForward(lavaArray) and bLocLava then
- collectFrontLava()
- if bAllLava then
- moveForward()
- collectAllValuables()
- turnBack()
- moveForward()
- turnBack()
- end
- end
- turtle.turnRight() -- back
- if inspectForward(blocksToMine) then
- moveForward()
- collectAllValuables()
- turnBack()
- moveForward()
- turnBack()
- elseif inspectForward(lavaArray) and bLocLava then
- collectFrontLava()
- if bAllLava then
- moveForward()
- collectAllValuables()
- turnBack()
- moveForward()
- turnBack()
- end
- end
- turtle.turnRight() -- left
- if inspectForward(blocksToMine) then
- moveForward()
- collectAllValuables()
- turnBack()
- moveForward()
- turnBack()
- elseif inspectForward(lavaArray) and bLocLava then
- collectFrontLava()
- if bAllLava then
- moveForward()
- collectAllValuables()
- turnBack()
- moveForward()
- turnBack()
- end
- end
- turtle.turnRight() -- forward
- if inspectUp(blocksToMine) then
- moveUp()
- collectAllValuables()
- moveDown()
- elseif inspectUp(lavaArray) and bLocLava then
- collectTopLava()
- if bAllLava then
- moveUp()
- collectAllValuables()
- moveDown()
- end
- end
- return true
- end
- -- Drops all slots except items from list in above storage
- function dropALLUp()
- local bDrop = true
- for i = 1, 16, 1 do
- turtle.select(i)
- for j = 1, #notDroppedBlocks, 1 do
- itemDetail = turtle.getItemDetail()
- if itemDetail then
- if itemDetail.name == notDroppedBlocks[j] then
- bDrop = False
- end
- end
- end
- if bDrop then
- turtle.dropUp()
- end
- bDrop = true
- end
- end
- -- places chest on top of turtle
- function placeChest()
- for i = 1, 16, 1 do
- turtle.select(i)
- itemDetail = turtle.getItemDetail()
- if itemDetail then
- if itemDetail.name == "minecraft:chest" then
- moveUp()
- moveDown()
- turtle.placeUp()
- return true
- end
- end
- end
- if bLava then
- if not (lavaCnt == 0) then
- print(tostring(lavaCnt).." Lavablocks were collected/destroyed")
- lavaCnt = 0
- end
- end
- return false
- end
- -- places torch NOT WRITTEN YET
- function placeTorch()
- return true
- end
- -- mines one tunnel and comes back out
- function mineTunnel (remainingLength)
- if not (remainingLength == 0) then
- moveForward()
- if not bTest then
- collectAllValuables()
- end
- moveUp()
- if not bTest then
- collectAllValuables()
- end
- moveDown()
- mineTunnel(remainingLength - 1)
- moveForward()
- else
- turnBack()
- end
- end
- -- Digs and mines all tunnels
- function runTunnelMiner()
- for i=1, numTunnels, 1 do
- takeTurn()
- mineTunnel(lenTunnel)
- if placeChest() then
- dropALLUp()
- end
- takeTurn()
- if not (i == numTunnels) then
- moveForward()
- moveForward()
- moveForward()
- end
- end
- end
- runTunnelMiner()
Add Comment
Please, Sign In to add comment