Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- local distance = tonumber(args[1])
- local fuel = 1
- local torches = 2
- local place_block = 3
- local max_slot = 16
- local function refuel()
- if turtle.getFuelLevel() == 0 then
- local prev = turtle.getSelectedSlot()
- turtle.select(fuel)
- if not turtle.refuel(1) then
- print('Need more fuel')
- while not turtle.refuel(1) do
- sleep(1)
- end
- end
- turtle.select(prev)
- end
- end
- local function smart_dig_forward()
- if turtle.detect() then
- turtle.dig()
- else
- return
- end
- local slot = turtle.getSelectedSlot()
- local i = 0
- if (slot != max_slot) then
- while (turtle.getItemCount() > 0 and slot != max_slot)
- do
- turtle.select(slot + i)
- i = i + 1
- end
- end
- end
- local function smart_dig_up()
- if turtle.detectUp() then
- turtle.digUp()
- else
- return
- end
- local slot = turtle.getSelectedSlot()
- local i = 0
- if (slot != max_slot) then
- while (turtle.getItemCount() > 0 and slot != max_slot)
- do
- turtle.select(slot + i)
- i = i + 1
- end
- end
- end
- local function smart_dig_down()
- if turtle.detectDown() then
- turtle.digDown()
- else
- return
- end
- local slot = turtle.getSelectedSlot()
- local i = 0
- if (slot != max_slot) then
- while (turtle.getItemCount() > 0 and slot != max_slot)
- do
- turtle.select(slot + i)
- i = i + 1
- end
- end
- end
- local function tryForwards()
- refuel()
- while not turtle.forward() do
- if turtle.detect() then
- smart_dig_forward()
- end
- sleep(0.5)
- end
- end
- local function tryDown()
- refuel()
- while not turtle.down() do
- if turtle.detectDown() then
- smart_dig_down()
- end
- sleep(0.5)
- end
- end
- local function tryUp()
- refuel()
- while not turtle.up() do
- if turtle.detectUp() then
- smart_dig_up()
- end
- sleep(0.5)
- end
- end
- local function dig_block_gravel()
- smart_dig_forward()
- sleep(.5)
- while turtle.detect() do
- smart_dig_forward()
- end
- end
- local function placeTorch()
- local prev = turtle.getSelectedSlot()
- turtle.select(torches)
- turtle.place()
- turtle.select(prev)
- end
- local function placeBlock()
- local prev = turtle.getSelectedSlot()
- turtle.select(place_block)
- turtle.placeDown()
- turtle.select(prev)
- end
- local function clearSection(currDistance)
- tryUp()
- tryUp()
- tryForwards()
- turtle.turnLeft()
- dig_block_gravel()
- turtle.turnRight()
- turtle.turnRight()
- dig_block_gravel()
- turtle.turnLeft()
- tryDown()
- turtle.turnLeft()
- smart_dig_forward()
- if currDistance % 6 == 0 then
- turtle.turnRight()
- turtle.turnRight()
- placeTorch()
- turtle.turnRight()
- turtle.turnRight()
- end
- turtle.turnRight()
- turtle.turnRight()
- smart_dig_forward()
- if currDistance % 6 == 0 then
- turtle.turnRight()
- turtle.turnRight()
- placeTorch()
- turtle.turnRight()
- turtle.turnRight()
- end
- turtle.turnLeft()
- tryDown()
- if not turtle.detectDown() then
- placeBlock()
- end
- turtle.turnLeft()
- tryForwards()
- if not turtle.detectDown() then
- placeBlock()
- end
- turtle.turnRight()
- turtle.turnRight()
- tryForwards()
- tryForwards()
- if not turtle.detectDown() then
- placeBlock()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- tryForwards()
- turtle.turnRight()
- end
- turtle.select(1)
- local curr_distance = 1
- while(curr_distance <= distance)
- do
- for i = curr_distance, distance, 1 do
- clearSection(i)
- if (turtle.getSelectedSlot() == 16) then
- break
- end
- end
- turtle.turnRight()
- turtle.turnRight()
- for i = 1, curr_distance, 1 do
- tryForwards()
- end
- for i = 3, 16, 1 do
- turtle.select(i)
- turtle.drop()
- end
- if (curr_distance == distance) then
- break
- end
- for i = 1, curr_distance, 1 do
- tryForwards()
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement