Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- NAMES = {'TConstruct:SearedBrick','chisel:marble','chisel:granite','chisel:diorite','minecraft:chest', 'ComputerCraft:CC-TurtleExpanded','minecraft:obsidian','minecraft:flowing_lava','minecraft:flowing_water','minecraft:lava','minecraft:water','chisel:andesite','chisel:limestone','minecraft:dirt','minecraft:stone','minecraft:granite','minecraft:diorite','minecraft:andesite','minecraft:gravel', 'minecraft:sand', 'minecraft:cobblestone'}
- PROTOCOL = 'mine'
- HOSTNAME = 'mineman'
- function is_stone(success, data)
- if success then
- for i = 1, #NAMES do
- if NAMES[i] == data.name then
- return ""
- end
- end
- local id = rednet.lookup(PROTOCOL, HOSTNAME)
- if id then
- rednet.send(id, data.name, PROTOCOL)
- end
- return false
- end
- return true
- end
- function dig_vein(i, path, moving_back)
- if path[i] == nil then
- path[i] = {}
- end
- --check up down and forward first,
- if not moving_back then
- if #path[i] == 0 then
- if not is_stone(turtle.inspectUp()) then
- path[i][#path[i]+1] = 0
- end
- if not is_stone(turtle.inspectDown()) then
- path[i][#path[i]+1] = 1
- end
- for j = 1, 4 do--forward, left, back, right
- if not is_stone(turtle.inspect()) then
- path[i][#path[i]+1] = 1 + j
- end
- turtle.turnLeft()
- end
- end
- if #path[i] == 0 then--go back from the path you started
- return dig_vein(i, path, true)
- else
- local dir = path[i][1]
- if dir == 0 then
- turtle.digUp()
- for x=0,20 do
- if not turtle.up() then
- turtle.digUp()
- else
- break
- end
- end
- elseif dir == 1 then
- turtle.digDown()
- turtle.down()
- elseif dir == 2 then
- turtle.dig()
- for x=0,20 do
- if not turtle.forward() then
- turtle.dig()
- else
- break
- end
- end
- elseif dir == 3 then
- turtle.turnLeft()
- turtle.dig()
- for x=0,20 do
- if not turtle.forward() then
- turtle.dig()
- else
- break
- end
- end
- elseif dir == 4 then
- turtle.turnLeft()
- turtle.turnLeft()
- turtle.dig()
- for x=0,20 do
- if not turtle.forward() then
- turtle.dig()
- else
- break
- end
- end
- elseif dir == 5 then
- turtle.turnRight()
- turtle.dig()
- for x=0,20 do
- if not turtle.forward() then
- turtle.dig()
- else
- break
- end
- end
- end
- i = i + 1
- return dig_vein(i, path, false)
- end
- else--moving back
- i = i - 1
- if i == 0 then
- return 0
- elseif #path[i] > 0 then
- local dir = path[i][1]
- if dir == 0 then
- turtle.down()
- elseif dir == 1 then
- for x=0,20 do
- if not turtle.up() then
- turtle.digUp()
- else
- break
- end
- end
- elseif dir == 2 then
- turtle.back()
- elseif dir == 3 then
- turtle.back()
- turtle.turnRight()
- elseif dir == 4 then
- turtle.back()
- turtle.turnLeft()
- turtle.turnLeft()
- elseif dir == 5 then
- turtle.back()
- turtle.turnLeft()
- end
- table.remove(path[i], 1)
- if #path[i] > 0 then
- return dig_vein(i, path, false)
- else
- return dig_vein(i, path, true)
- end
- end
- end
- end
- function refuel(f)
- for k = 1, 16 do
- turtle.select(k)
- if turtle.refuel(f) then
- return true
- end
- end
- end
- function dropAll()
- foundcoal = false
- for k = 1, 16 do
- turtle.select(k)
- local data = turtle.getItemDetail()
- if not foundcoal and data and data.name == 'minecraft:coal' then
- foundcoal = true
- else
- turtle.dropDown()
- end
- end
- end
- function hasSpace()
- for slot=1,16 do
- if turtle.getItemDetail(slot) == nil then
- return true
- end
- end
- return false
- end
- function split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={} ; i=1
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- t[i] = str
- i = i + 1
- end
- return t
- end
- function mine(height, length)
- for i=1,height do
- turtle.digUp()
- turtle.up()
- end
- for i=1,length do
- if i == 100 then
- break
- end
- if turtle.getFuelLevel() < (length*1.2) then
- if not refuel(2) then
- return false
- end
- end
- if not hasSpace() then
- for k = 2, i do
- turtle.back()
- end
- for i=1,height do
- turtle.digDown()
- turtle.down()
- end
- refuel(5)
- dropAll()
- if turtle.getFuelLevel() < (i*1.2) then
- return false
- end
- for k = 2, i do
- for x=0,20 do
- if not turtle.forward() then
- turtle.dig()
- else
- break
- end
- end
- end
- end
- if turtle.detect() then
- turtle.dig()
- end
- for x=0,20 do
- if not turtle.forward() then
- turtle.dig()
- else
- break
- end
- end
- dig_vein(1,{},false)
- if turtle.detectDown() then
- turtle.digDown()
- end
- turtle.down()
- dig_vein(1,{},false)
- for x=0,20 do
- if not turtle.up() then
- turtle.digUp()
- else
- break
- end
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, length do
- for x=0,20 do
- if not turtle.forward() then
- turtle.dig()
- else
- break
- end
- end
- if turtle.getFuelLevel() == 0 then
- return false
- end
- end
- for i=1,height do
- turtle.digDown()
- turtle.down()
- end
- dropAll()
- turtle.turnLeft()
- turtle.turnLeft()
- return true
- end
- rednet.open('right')
- while true do
- local id, msg, prot = rednet.receive()
- local id1 = rednet.lookup(PROTOCOL, HOSTNAME)
- if id1 and id == id1 and prot == PROTOCOL then
- print('got cmd')
- tokens = split(msg, ' ')
- if #tokens == 2 and tokens[1] == 'mine' then
- print('got mine cmd')
- h = 0
- while mine(h,tonumber(tokens[2])) do
- h = h + 4
- if h > 50 then
- break
- end
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement