Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ********************************************************************************** --
- -- ** ** --
- -- ** Mining selected area turtle v1.5 by omr___ ** --
- -- ** (Add support of negative height and width) ** --
- -- ** ---------------------------------------------------- ** --
- -- ** ** --
- -- ** How to use: ** --
- -- ** Download: rom/programs/http/pastebin get 0XqzVUPM dig ** --
- -- ** !IMPORTANT! Place a chest above the turtle ** --
- -- ** Start position: Bottom Left before area ** --
- -- ** Fuel slot: 16, Bottom Right ** --
- -- ** ** --
- -- ** Change Log: ** --
- -- ** 27th Aug 2018: [v1.5] Add support of negative height and width ** --
- -- ** [v1.5] Fix items drop when no chest above ** --
- -- ** 26th Aug 2018: [v1.4] Type parameters after init ** --
- -- ** 26th Aug 2018: [v1.3] Unload items in chest when done ** --
- -- ** [v1.3] Return to start after finishing ** --
- -- ** 25th Aug 2018: [v1.2] Mining performance improvements ** --
- -- ** [v1.2] Fixed falling blocks issue ** --
- -- ** ** --
- -- ** TODO: ** --
- -- ** - Auto resume ** --
- -- ** - Unload when full ** --
- -- ** - Allow trash cobble ** --
- -- ** ** --
- -- ********************************************************************************** --
- local args = { ... }
- local direction = {FORWARD = 0, LEFT = 1, BACK = 2, RIGHT = 3, UP = 4, DOWN = 5}
- local axis = {x = -1, y = -1}
- local invertPos
- local width
- local height
- local length
- function rotate(invert)
- if invert == 1 then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- function turn(invert)
- if axis.x == 1 then
- rotate(invert)
- else
- rotate(-invert)
- end
- end
- function unloadToChest()
- for slot = 1, 16 do
- turtle.select(slot)
- if turtle.detectUp() then
- turtle.dropUp()
- end
- end
- turtle.select(1)
- print("Items were unloaded")
- end
- function returnToStart()
- if (axis.x == 1) and not (invertPos == true) then
- rotate()
- for i = 1, width - 1 do
- move(direction.FORWARD)
- end
- rotate(1)
- end
- if (axis.y == 1) and not (invertPos == true) then
- for i = 1, height - 1 do
- move(direction.DOWN)
- end
- end
- for i = 1, length do
- move(direction.BACK)
- end
- print("Return complete")
- end
- function verifyFuel()
- if turtle.getFuelLevel() < 10 then
- print("Fuel level is low, put fuel in slot 16")
- local selectedSlot = turtle.getSelectedSlot()
- turtle.select(16)
- turtle.refuel()
- turtle.select(selectedSlot)
- end
- end
- function dig(dir)
- function try(detectFn, digFn)
- while detectFn() do
- verifyFuel()
- digFn()
- os.sleep(0.5)
- end
- end
- if dir == direction.UP then
- try(turtle.detectUp, turtle.digUp)
- elseif dir == direction.DOWN then
- try(turtle.detectDown, turtle.digDown)
- elseif dir == direction.BACK then
- turtle.turnLeft()
- turtle.turnLeft()
- try(turtle.detect, turtle.dig)
- turtle.turnRight()
- turtle.turnRight()
- else
- try(turtle.detect, turtle.dig)
- end
- end
- function move(dir)
- function try(moveFn)
- dig(dir)
- moveFn()
- end
- if dir == direction.FORWARD then
- try(turtle.forward)
- elseif dir == direction.UP then
- try(turtle.up)
- elseif dir == direction.DOWN then
- try(turtle.down)
- elseif dir == direction.BACK then
- try(turtle.back)
- end
- end
- function digRow(w)
- turn(-1)
- for i = 1, w do
- dig()
- move(direction.FORWARD)
- end
- turn(1)
- axis.x = -axis.x
- end
- function digWall()
- for i = 1, height do
- digRow(width - 1)
- if (i < tonumber(height)) then
- if axis.y == 1 then
- dig(direction.DOWN)
- move(direction.DOWN)
- else
- dig(direction.UP)
- move(direction.UP)
- end
- end
- end
- end
- function digArea()
- local blocks = width * height * length
- print("Fuel level: "..turtle.getFuelLevel())
- print("Area size: "..width.."x"..height.."x"..length.." ("..blocks.." blocks)")
- for i = 1, length do
- dig()
- move(direction.FORWARD)
- digWall()
- axis.y = -axis.y
- end
- end
- if #args ~= 3 then
- print("Usage: dig <Length> <Width> <Height>")
- print("Length?")
- length = tonumber(read())
- print("Width?")
- width = tonumber(read())
- print("Height?")
- height = tonumber(read())
- else
- length = tonumber(args[1])
- width = tonumber(args[2])
- height = tonumber(args[3])
- end
- if height < 0 then
- axis.y = 1
- height = -height
- end
- if width < 0 then
- axis.x = 1
- width = -width
- invertPos = true
- end
- if length < 1 then
- print("Length must be positive")
- return
- end
- digArea()
- returnToStart()
- unloadToChest()
Add Comment
Please, Sign In to add comment