Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --digs 2x2 with 3d search
- --globals
- local input = {...}
- DISTANCE = input[1]
- moves = {}
- index = 1
- DIR = 1
- M_vectors = {3, 4, 1, 2, 6, 5}
- --main functions
- function tunnel()
- turtle.dig()
- dig()
- turtle.forward()
- inspect_d(1)
- change_d('left')
- turtle.dig()
- dig()
- turtle.forward()
- inspect_d(1)
- inspect_d(2)
- turtle.digUp()
- digUp()
- turtle.up()
- inspect_d(2)
- inspect_d(3)
- change_d('right')
- change_d('right')
- turtle.dig()
- dig()
- turtle.forward()
- inspect_d(3)
- inspect_d(2)
- turtle.down()
- inspect_d(2)
- change_d('left')
- end
- function dig()
- while turtle.detect() == true do
- turtle.dig()
- end
- end
- function digUp()
- while turtle.detectUp() == true do
- turtle.digUp()
- end
- end
- function check(dir)
- local found = false
- if dir == 1 then
- is_block, data = turtle.inspectDown()
- elseif dir == 2 then
- is_block, data = turtle.inspect()
- elseif dir == 3 then
- is_block, data = turtle.inspectUp()
- end
- if is_block and data.name == 'minecraft:diamond_ore' then
- found = true
- end
- return found
- end
- function change_d(dir)
- if dir == 'left' then
- turtle.turnLeft()
- if DIR == 1 then
- DIR = 4
- else
- DIR = DIR -1
- end
- elseif dir == 'right' then
- turtle.turnRight()
- if DIR == 4 then
- DIR = 1
- else
- DIR = DIR + 1
- end
- end
- end
- function inspect_base(dir)
- local success = check(dir)
- if success and dir == 2 then
- turtle.dig()
- turtle.forward()
- moves[index] = DIR
- index = index + 1
- elseif success and dir == 1 then
- turtle.digDown()
- turtle.down()
- moves[index] = 5
- index = index + 1
- elseif success and dir == 3 then
- turtle.digUp()
- turtle.up()
- moves[index] = 6
- index = index + 1
- end
- return success
- end
- function inspect_loop()
- i = 1
- j = 2
- while moves[1] ~= nil do
- local found = inspect_base(j)
- if not found and j == 2 then
- change_d('right')
- i = i + 1
- if i == 5 then
- j = 1
- end
- elseif not found and j == 1 then
- j = 3
- elseif not found and j == 3 then
- reverse()
- i = 1
- j = 2
- else
- i = 1
- j = 2
- end
- end
- end
- function turn(goal)
- while DIR ~= goal do
- change_d('right')
- end
- end
- function reverse()
- index = index - 1
- i = moves[index]
- goal = M_vectors[i]
- if goal < 5 then
- turn(goal)
- turtle.forward()
- moves[index] = nil
- else
- if goal == 5 then
- turtle.down()
- moves[index] = nil
- elseif goal == 6 then
- turtle.up()
- moves[index] = nil
- end
- end
- end
- function inspect_d(dir)
- local current_d = DIR
- local found = inspect_base(dir)
- if found then
- inspect_loop()
- turn(current_d)
- end
- end
- --aux functions
- function refuel()
- if turtle.getFuelLevel() < 80 then
- turtle.select(1)
- turtle.refuel(1)
- end
- end
- function eject()
- for i = 1, 16 do
- turtle.select(i)
- local data = turtle.getItemDetail()
- if data ~= nil and data.name == 'minecraft:cobblestone' then
- turtle.drop()
- end
- end
- end
- --main
- function main()
- refuel()
- for i = 1, DISTANCE do
- tunnel()
- if (i % 10) == 0 then
- refuel()
- eject()
- end
- print(i)
- end
- turtle.turnRight()
- turtle.turnRight()
- eject()
- for i = 1, DISTANCE do
- turtle.forward()
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement