Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Excavator turtle reporting for duty!")
- print("How many 6x6 chunks should I excavate?")
- local max_excavations = tonumber(io.read())
- local z_pos = 0
- local fuel_limit = 20000
- local dump_to_chest
- local find_fuel
- local refuel
- local try_down
- local move_to_next_layer
- local dig_forward
- local dig_layer
- local try_up
- local excavate
- local finished
- dump_to_chest = function()
- -- dig above to ensure chest placement. Will continue to dig until detectUp() yields false.
- repeat
- turtle.digUp()
- sleep(0.6)
- until not turtle.detectUp()
- -- place Ender Chest
- turtle.select(1)
- turtle.placeUp()
- -- consume all fuel items up to max fuel limit
- refuel()
- -- dump to Ender Chest
- for slot = 2, 16 do
- turtle.select(slot)
- turtle.dropUp()
- end
- -- reclaim Ender Chest
- sleep(0.2)
- turtle.select(1)
- turtle.digUp()
- end
- -- Look for and consume fuel sources, starting with slot 2
- find_fuel = function()
- for slot = 2, 16 do
- turtle.select(slot)
- if turtle.refuel(1) then
- return true
- end
- end
- return false
- end
- -- Consume all fuel in inventory up to max limit
- refuel = function()
- while turtle.getFuelLevel() < fuel_limit do
- if not find_fuel() then
- break
- end
- end
- turtle.select(1)
- end
- -- handles detecting finished condition (bedrock) and digging, attacking while moving down
- -- will return true if movement occurs, will return false if bedrock detected below
- try_down = function()
- if not turtle.down() then -- try moving down, if you can't
- if turtle.detectDown() then -- check for a block, if there's a block
- if not turtle.digDown() then -- try digging it, if you can't dig it
- return false
- else
- return try_down() -- try moving down now
- end
- else -- attack until whatever is there is dead or moved
- while turtle.attackDown() do
- sleep(0.5)
- end
- return try_down() -- then move down
- end
- end
- z_pos = z_pos + 1
- return true
- end
- -- Proceed to mine next layer down
- move_to_next_layer = function()
- down_count = 0
- for try = 1, 3 do -- try moving down three times
- if try_down() then
- down_count = down_count + 1
- end
- end
- if down_count == 0 or down_count == 1 then -- if it can't move down enough to dig, call completion function
- finished()
- else
- dig_layer()
- end
- end
- -- Dig and move forward, attacking and redigging if necessary
- dig_forward = function()
- if turtle.detect() then -- dig if there's a block in front
- turtle.dig()
- if turtle.getItemCount(16) > 0 then
- dump_to_chest()
- end
- end
- if turtle.detectUp() then -- dig up if there's a block up
- turtle.digUp()
- if turtle.getItemCount(16) > 0 then
- dump_to_chest()
- end
- end
- if turtle.detectDown() then -- dig down if there's a block down
- turtle.digDown()
- if turtle.getItemCount(16) > 0 then
- dump_to_chest()
- end
- end
- while turtle.detect() do -- keep digging and waiting if there's gravel/sand in front
- turtle.dig()
- sleep(0.6)
- end
- if turtle.getItemCount(16) > 0 then
- dump_to_chest()
- end
- while not turtle.forward() do -- if you can't move forward it's because of mobs (probably)
- turtle.attack()
- turtle.dig()
- sleep(0.5)
- end
- end
- -- Dig a 6x6x3 layer
- dig_layer = function()
- for j = 1, 3 do
- for i = 1, 5 do
- dig_forward()
- end
- turtle.turnRight()
- end
- dig_forward()
- turtle.turnRight()
- for i = 1, 4 do
- dig_forward()
- end
- turtle.turnLeft()
- dig_forward()
- turtle.turnLeft()
- for i = 1, 4 do
- dig_forward()
- end
- turtle.turnRight()
- dig_forward()
- turtle.turnRight()
- for i = 1, 4 do
- dig_forward()
- end
- turtle.turnLeft()
- dig_forward()
- turtle.turnLeft()
- for i = 1, 4 do
- dig_forward()
- end
- turtle.turnRight()
- dig_forward()
- turtle.turnRight()
- move_to_next_layer()
- end
- try_up = function()
- if not turtle.up() then -- try moving up, if you can't
- if turtle.detectUp() then -- check for a block, if there's a block
- if not turtle.digUp() then -- try digging it, if you can't dig it (shouldn't happen going up)
- return false
- else
- return try_up() -- try moving up now
- end
- else -- attack until whatever is there is dead or moved
- while turtle.attackUp() do
- sleep(0.5)
- end
- return try_up() -- then move up
- end
- end
- return true
- end
- excavate = function()
- -- move down twice to get below surface for first dig
- try_down()
- try_down()
- -- start digging, will keep moving to next layers
- dig_layer()
- end
- finished = function()
- --dump to chest
- dump_to_chest()
- -- move back to origin
- for i = 1, z_pos do
- try_up()
- end
- if max_excavations > 1 then
- max_excavations = max_excavations - 1
- -- move forward for next iteration
- for i = 1, 6 do
- dig_forward()
- end
- z_pos = 0
- excavate()
- end
- for i = 1, 6 do -- move forward to be at next starting point
- dig_forward()
- end
- end
- print("Fueling up!")
- refuel()
- print("Excavating...")
- excavate()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement