Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local height = 0
- local movedBlocks = 0
- local direction = "up"
- local canMine = true
- local function FetchItems()
- turtle.suck()
- turtle.suckUp()
- turtle.suckDown()
- end
- local function CheckFuel()
- if turtle.getFuelLevel() == 0 then
- turtle.refuel(1)
- end
- end
- local function PlaceTorch()
- if (movedBlocks % 5 == 0) and (height == 2) then
- turtle.select(2)
- turtle.digUp()
- turtle.placeUp()
- turtle.select(1)
- end
- end
- local function CheckBackpack()
- emptySlots = 0
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- emptySlots = emptySlots + 1
- end
- end
- if emptySlots == 0 then
- canMine = false
- end
- end
- local function TryMove(direction)
- attempt = 1
- while true do
- CheckFuel()
- if direction == "up" then
- if turtle.up() == true then
- break
- else
- turtle.digUp()
- end
- elseif direction == "down" then
- if turtle.down() == true then
- break
- else
- turtle.digDown()
- end
- elseif direction == "forward" then
- if turtle.forward() == true then
- break
- else
- turtle.dig()
- end
- elseif direction == "back" then
- if turtle.back() == true then
- break
- end
- end
- if attempt > 5 then
- canMine = false
- end
- attempt = attempt + 1
- end
- end
- local function TryMine(direction)
- while true do
- if direction == "up" then
- if turtle.detectUp() == true then
- turtle.digUp()
- FetchItems()
- end
- elseif direction == "down" then
- if turtle.detectDown() == true then
- turtle.digDown()
- FetchItems()
- end
- elseif direction == "forward" then
- if turtle.detect() == true then
- turtle.dig()
- FetchItems()
- end
- end
- end
- end
- local function Mine()
- while canMine == true do
- if (movedBlocks > 0) and (movedBlocks % 10 == 0) then
- CheckBackpack()
- end
- if turtle.detect() == true then
- TryMine("forward")
- end
- TryMove("forward")
- movedBlocks = movedBlocks + 1
- for i = 1, 2 do
- PlaceTorch()
- if (height < 2) and (direction == "up") then
- if turtle.detectUp() == true then
- TryMine("up")
- end
- TryMove(direction)
- height = height + 1
- if height == 2 then
- direction = "down"
- end
- elseif (height > 0) and (direction == "down") then
- if turtle.detectDown() == true then
- TryMine("down")
- end
- TryMove(direction)
- height = height - 1
- if height == 0 then
- direction = "up"
- end
- end
- end
- end
- end
- CheckFuel()
- Mine()
- for i = 1, height do
- TryMove("down")
- end
- for i = 1, movedBlocks do
- TryMove("back")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement