Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- move program by Caio "Jabulba" Jabulka 2015
- -- Turtle type: Mining Turtle
- -- Purpose: Turtle moves the specified amount of times forward.
- -- Licensed MIT
- local enderChestId = "EnderStorage:enderChest"
- local inventoryEmptiedCount = 0
- local args = {...}
- args[1] = tonumber(args[1]) or 1
- assert(type(args[1]) == "number", "Expected at most one argument as number.")
- if not(args[2] == "f" or args[2] == "b" or args[2] == "d" or args[2] == "u" or args[2] == "forward" or args[2] == "backward" or args[2] == "down" or args[2] == "up") then
- args[1] = 0
- error("Provided direction " .. args[2] .. " is invalid. Try 'f', 'b', 'u' or 'd'")
- end
- 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 true
- 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
- if not clearCobblestone then
- local data = turtle.getItemDetail(i)
- if data and data.name == cobblestoneId then
- clearCobblestone = true
- end
- else
- turtle.select(i)
- turtle.drop()
- end
- 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
- elseif direction == "b" or direction == "back" or direction == "backward" then
- turtleMove("b")
- end
- return true
- end
- for runs = 1, args[1], 1 do
- digMove(args[2])
- end
Advertisement
Add Comment
Please, Sign In to add comment