Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- forward digger program by Caio "Jabulba" Jabulka 2015
- -- Turtle type: Mining Turtle
- -- Purpose: Turtle moves the specified amount of times forward breaking blocks above and below.
- -- Licensed MIT
- local enderChestId = "EnderStorage:enderChest"
- local inventoryEmptiedCount = 0
- local arg = ...
- arg = tonumber(arg) or 1
- assert(type(arg) == "number", "Expected at most one argument as number.")
- local function turtleMove(direction)
- direction = direction or "forward"
- if direction == "f" or direction == "forward" then
- return turtle.forward()
- elseif direction == "b" or direction == "backward" then
- return turtle.back()
- elseif direction == "d" or direction == "down" then
- return turtle.down()
- elseif direction == "u" or direction == "up" then
- return turtle.up()
- end
- end
- local function emptyInventory()
- clearCobblestone = clearCobblestone or false
- print("Inventory full! Clearing it now...")
- inventoryEmptiedCount = inventoryEmptiedCount + 1
- turtle.select(1)
- while turtle.detect() do
- turtle.dig()
- os.sleep(0.2)
- end
- turtle.place()
- for i = 2, 16, 1 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- turtle.dig()
- print("Inventory cleared for the " .. tostring(inventoryEmptiedCount) .. " time.")
- end
- local function checkInventory()
- local fullSlots = 0
- for i = 1, 16, 1 do
- if turtle.getItemCount(i) > 0 then
- fullSlots = fullSlots + 1
- end
- end
- local data = turtle.getItemDetail(1)
- if fullSlots == 0 or not data or not data.name == enderChestId then
- print("WHERE IS THE ENDER CHEST!?")
- while not data or not data.name == enderChestId do
- os.sleep(0.5)
- data = turtle.getItemDetail(1)
- end
- end
- if fullSlots > 14 then
- emptyInventory()
- end
- end
- local function checkFuel()
- local fuelLevel = turtle.getFuelLevel()
- if fuelLevel < 5 then
- print("CRITICAL: FUEL LEVEL CRITICAL.")
- print("EMERGENCY REFUELING INITIATED.")
- for slot = 1, 16, 1 do
- if turtle.refuel() then
- break
- end
- end
- elseif fuelLevel < 25 then
- print("CRITICAL: FUEL LEVEL EXTREMELY LOW.")
- elseif fuelLevel < 500 then
- print("WARNING: FUEL LEVEL LOW.")
- end
- end
- local function digMove(direction, attempts)
- direction = direction or "forward"
- attempts = attempts or 1
- checkFuel()
- checkInventory()
- if attempts > 30 then
- return false
- end
- turtle.dig()
- if direction == "f" or direction == "forward" then
- turtle.dig()
- if not turtleMove("f") then
- turtle.attack()
- digMove("f", attempts)
- end
- elseif direction == "d" or direction == "down" then
- turtle.digDown()
- if not turtleMove("d") then
- turtle.attackDown()
- digMove("d", attempts)
- end
- elseif direction == "u" or direction == "up" then
- turtle.digUp()
- if not turtleMove("u") then
- turtle.attackUp()
- digMove("u", attempts)
- end
- end
- return true
- end
- for runs = 1, arg, 1 do
- digMove("forward")
- turtle.digUp()
- turtle.digDown()
- end
- -- Clear the inventory
- turtleMove("backward")
- emptyInventory()
Advertisement
Add Comment
Please, Sign In to add comment