Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- names = {'minecraft:chest', 'ComputerCraft:CC-Turtle','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'}
- function is_stone(success, data)
- if success then
- for i = 1, #names do
- if names[i] == data.name then
- return ""
- end
- end
- return data.name
- end
- return ""
- end
- function dig_sides()
- turtle.turnLeft()
- local block_left = is_stone(turtle.inspect())
- if block_left ~= "" then
- print('found: ', block_left)
- dig_vein(1, {}, false)
- print('end of vein')
- end
- turtle.turnRight()
- turtle.turnRight()
- local block_right = is_stone(turtle.inspect())
- if block_right ~= "" then
- print('found: ', block_right)
- dig_vein(1, {}, false)
- print('end of vein')
- end
- turtle.turnLeft()
- end
- function dig_up_down()
- local block_up = is_stone(turtle.inspectUp())
- local block_down = is_stone(turtle.inspectDown())
- if block_up ~= "" then
- print('found: ', block_up)
- dig_vein(1, {}, false)
- print('end of vein')
- end
- if block_down ~= "" then
- print('found: ', block_down)
- dig_vein(1, {}, false)
- print('end of vein')
- end
- end
- function dig_shaft()
- for i = 1, 4 do
- if turtle.detect() then
- turtle.dig()
- end
- for x=0,20 do
- if not turtle.forward() then
- turtle.dig()
- else
- break
- end
- end
- if i ~= 1 then
- dig_sides()
- end
- dig_up_down()
- end
- for i = 1, 4 do
- turtle.back()
- end
- 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
- local block_up = is_stone(turtle.inspectUp())
- if block_up ~= "" then
- path[i][#path[i]+1] = 0
- end
- local block_down = is_stone(turtle.inspectDown())
- if block_down ~= "" then
- path[i][#path[i]+1] = 1
- end
- for j = 1, 4 do--forward, left, back, right
- local block = is_stone(turtle.inspect())
- if block ~= "" then
- path[i][#path[i]+1] = 1 + j
- end
- turtle.turnLeft()
- end
- --print("len: " .. #path[i])
- 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]
- --print("dir: " .. dir)
- 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()
- for k = 1, 16 do
- turtle.select(k)
- turtle.dropDown()
- end
- end
- function hasSpace()
- for slot=1,16 do
- if turtle.getItemDetail(slot) == nil then
- return true
- end
- end
- return false
- end
- function mine(length)
- 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
- 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_up_down()
- dig_sides()
- if turtle.detectDown() then
- turtle.digDown()
- end
- turtle.down()
- dig_sides()
- dig_up_down()
- for x=0,20 do
- if not turtle.up() then
- turtle.digUp()
- else
- break
- end
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 2, 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
- return true
- end
- if mine(100) then
- dropAll()
- print('complete!!!')
- else
- print('ran out of fuel')
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement