Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function veinMine() --vein mines ores that are adjasent to each other
- --list of unwanted blocks
- unwanted = {['minecraft:cobblestone']=true,['minecraft:stone']=true,['minecraft:dirt']=true,['minecraft:gravel']=true,['minecraft:sandstone']=true,['minecraft:sand']=true,['minecraft:torch']=true}
- for i = 1, 4 do
- success, data = turtle.inspect()
- if success and unwanted[data.name] == nil and data.state.level == nil then
- turtle.dig()
- turtle.forward()
- veinMine()
- turtle.back()
- end
- turtle.turnRight()
- end
- success, data = turtle.inspectUp()
- if success and unwanted[data.name] == nil and data.state.level == nil then
- turtle.digUp()
- turtle.up()
- veinMine()
- turtle.down()
- end
- success, data = turtle.inspectDown()
- if success and unwanted[data.name] == nil and data.state.level == nil then
- turtle.digDown()
- turtle.down()
- veinMine()
- turtle.up()
- end
- end
- function clearInv() --clears the players inventory of useless blocks that are not needed
- --drop all non essential items [cobble, diorite, andesite ect..]
- for n=1,15 do
- p = turtle.getItemDetail(n)
- if p ~= nil then
- if p.name == "minecraft:cobblestone" or p.name == "minecraft:stone" then
- turtle.select(n)
- turtle.dropDown()
- end
- end
- end
- turtle.select(16)
- end
- function miniTunnel(len, blocks, torches, ore_collect) --mini tunnels that are 1 wide
- sinceLastTorch = 0
- for i=1,len do
- if blocks then
- while turtle.detect() do
- turtle.dig()
- os.sleep(0.5)
- end
- end
- --if needed check for ores before placing torch
- --move down
- --look left -> if ore mine
- --look right -> if ore mine
- --move up -> repeat 1 - 3 x2
- if ore_collect and i >= 3 then
- turtle.down()
- veinMine()
- turtle.up()
- veinMine()
- turtle.up()
- veinMine()
- turtle.down()
- end
- if i % 13 == 3 and torches then
- turtle.select(16)
- turtle.placeDown()
- sinceLastTorch = 0
- clearInv()
- end
- turtle.forward()
- sinceLastTorch = sinceLastTorch + 1
- if blocks then
- --mine block above and below turtle [height of 3]
- while turtle.detectUp() or turtle.detectDown() do
- turtle.digUp()
- turtle.digDown()
- end
- end
- end
- if sinceLastTorch >= 7 and torches then
- turtle.select(16)
- turtle.placeDown()
- sinceLastTorch = 0
- end
- end
- function checkSpace(moved)--check how much space is in the inventory, if more than threshold[set to 10/16] clear items
- clearInv()
- storage = 0
- for i=1,15 do
- details = turtle.getItemDetail(i)
- if details ~= nil then
- storage = storage + 1
- end
- end
- if storage >= 10 then
- --move back to start to drop off items if not at end
- if length ~= 1 then
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1,m do
- turtle.forward()
- end
- for i=1,15 do
- turtle.select(i)
- turtle.dropDown()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1,moved do
- turtle.forward()
- end
- end
- end
- end
- function Tunnel(len, side_tunnels) --the main 3x3 tunnel function
- local length = tonumber(len)
- local tunnelLength = length
- local sideTunnels = tonumber(side_tunnels) + 1
- local moved = 1
- while (turtle.detect() and length >= 1) or length >= 1 do
- --main tunnel section
- miniTunnel(1,true, false, false)
- turtle.turnLeft()
- miniTunnel(1,true, false, false)
- turtle.turnRight()
- turtle.turnRight()
- miniTunnel(1, false, false, false)
- miniTunnel(1, true, false, false)
- turtle.turnLeft()
- turtle.turnLeft()
- miniTunnel(1, false, false, false)
- turtle.turnRight()
- --check if torch needed
- if length % 3 == 1 then
- turtle.turnLeft()
- miniTunnel(sideTunnels, true, true, true)
- turtle.turnRight()
- turtle.turnRight()
- miniTunnel(sideTunnels, false, false, false)
- turtle.turnLeft()
- checkSpace(moved)
- turtle.turnRight()
- miniTunnel(sideTunnels, true, true, true)
- turtle.turnLeft()
- turtle.turnLeft()
- miniTunnel(sideTunnels, false, false, false)
- turtle.turnRight()
- checkSpace(moved)
- end
- length = length - 1
- moved = moved + 1
- end
- returnHome(tunnelLength)
- end
- function returnHome(l) --after everything is done return the turtle to the chest
- clearInv()
- turtle.turnRight()
- turtle.turnRight()
- for i=1,l do
- turtle.forward()
- end
- for i=1,15 do
- turtle.select(n)
- turtle.dropDown()
- end
- end
- local tArgs = { ... } --getting arguments
- local size = tonumber( tArgs[1] )
- if #tArgs ~= 2 then --checking argument size
- print( "Usage: mine <length> <strip's length>" )
- return
- end
- local size = tonumber( tArgs[1] ) --checking tunnel size
- if size < 1 then
- print( "Mine length must be positive" )
- return
- end
- size = tonumber( tArgs[2] ) --checking strip size
- if size < 1 then
- print( "Strip length must be positive" )
- return
- end
- Tunnel(tArgs[1], tArgs[2]) --start the program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement