Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Predefine enum
- local DIRECTION = {
- left = 1,
- right = 2
- }
- -- Predefine variables
- local version = "0.1"
- local accepted_fuels = {"minecraft:coal_block", "minecraft:coal", "minecraft:charcoal"}
- local inventory_size = 16
- local check_inventory_every = 20
- local depth = nil
- local width = nil
- local height = nil
- local currentDepth = 1
- local currentWidth = 1
- local currentHeight = 1
- local direction;
- -- Read arguments
- local args = {...}
- -- Check arguments. Possible arguments are:
- -- -h, --help: Print this help message
- -- -v, --version: Print version information
- -- --depth <depth>: Set the depth of the square
- -- --width <width>: Set the width of the square
- -- --height <height>: Set the height of the square
- for i = 1, #args do
- if args[i] == "-h" or args[i] == "--help" then
- print("Usage: mine_tutrle_square.lua [OPTIONS]")
- print("Options:")
- print("-h, --help: Print this help message")
- print("-v, --version: Print version information")
- print("--depth <depth>: Set the depth of the square")
- print("--width <width>: Set the width of the square")
- print("--height <height>: Set the height of the square")
- return
- elseif args[i] == "-v" or args[i] == "--version" then
- print("mine_tutrle_square.lua " .. version)
- return
- elseif args[i] == "--depth" and args[i + 1] then
- depth = tonumber(args[i + 1])
- if not depth then
- print("Error: Invalid depth")
- return
- end
- elseif args[i] == "--width" and args[i + 1] then
- width = tonumber(args[i + 1])
- if not width then
- print("Error: Invalid width")
- return
- end
- elseif args[i] == "--height" and args[i + 1] then
- height = tonumber(args[i + 1])
- if not height then
- print("Error: Invalid height")
- return
- end
- end
- end
- -- Create the refill function
- function Refill()
- print("Refueling...")
- for i = 1, inventory_size do
- for j = 1, #accepted_fuels do
- if turtle.getItemDetail(i) and turtle.getItemDetail(i).name == accepted_fuels[j] then
- turtle.select(i)
- turtle.refuel()
- break
- end
- end
- end
- end
- -- Create the mining function
- function Mine()
- print("Mining...")
- for i = 1, height do
- print("Mining height " .. i .. " of " .. height)
- -- Move up if height > 1
- if height > 1 then
- if turtle.detectUp() then
- turtle.up()
- else
- turtle.digUp()
- turtle.up()
- end
- i = i + 1
- print("Mining layer " .. i .. " of " .. height)
- end
- for j = 1, width do
- print("Mining width " .. j .. " of " .. width)
- for k = 1, depth do
- print("Mining depth " .. k .. " of " .. depth)
- -- Dig below if heigh > 1 and there is a block below
- if height > 1 and turtle.detectDown() then
- turtle.digDown()
- end
- -- Dig above if height is i - 1 and there is a block above
- if height > 1 and i == height - 1 and turtle.detectUp() then
- turtle.digUp()
- end
- -- Dig infront of the turtle
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- end
- -- Turn around
- if j % 2 == 1 then -- Odd = Start to end, ebven = end to start
- if direction == DIRECTION.left then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- if direction == DIRECTION.left then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- else
- if direction == DIRECTION.left then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- if turtle.detect() then
- turtle.dig()
- end
- turtle.forward()
- if direction == DIRECTION.left then
- turtle.turnRight()
- else
- turtle.turnLeft()
- end
- end
- end
- end
- end
- -- Create the main function
- function Main()
- -- Check direction
- turtle.turnLeft()
- if turtle.detect() then
- direction = DIRECTION.right
- else
- direction = DIRECTION.left
- end
- turtle.turnRight()
- -- Measure depth if not set
- if depth == nil or depth < 1 then
- print("Depth not set. Measuring depth...")
- depth = 1
- -- Move forward until we hit a wall
- while turtle.detect() == false do
- turtle.forward()
- depth = depth + 1
- end
- -- Turn around and move back
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, depth do
- turtle.forward()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- print("Depth: " .. depth)
- end
- -- Measure width if not set
- if width == nil or width < 1 then
- print("Width not set. Measuring width...")
- -- Rotate to "direction"
- if direction == DIRECTION.left then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- width = 1
- -- Move forward until we hit a wall
- while turtle.detect() == false do
- turtle.forward()
- width = width + 1
- end
- -- Turn around and move back
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, width do
- turtle.forward()
- end
- if direction == DIRECTION.left then
- turtle.turnLeft()
- else
- turtle.turnRight()
- end
- print("Width: " .. width)
- end
- -- Measure height if not set
- if height == nil or height < 1 then
- print("Height not set. Measuring height...")
- height = 1
- -- Move up until we hit a wall
- while turtle.detectUp() == false do
- turtle.up()
- height = height + 1
- end
- -- Move down
- for i = 1, height do
- turtle.down()
- end
- print("Height: " .. height)
- end
- print("Starting...")
- while true do
- if turtle.getFuelLevel() < 100 then
- Refill()
- end
- Mine()
- end
- end
- -- Run the main function
- Main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement