Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local args = {...}
- if #args ~= 3 then
- print("Usage: quarry <width> <length> <height>")
- error()
- end
- width = args[1]
- length = args[2]
- height = args[3]
- y = height
- --[[--------Setup----------------------
- 1. Dig out a 5x5 square to work in
- (The turtle will not dig this area!)
- 2. Place the turtle facing out at the
- center of any edge
- 3. Place a chest of coal/charcoal
- to the left of the turtle
- 4. Place a chest of vanilla wood items
- (logs, planks, sticks) or
- torches to the right.
- 5. Place storage chests facing
- the turtle to the left
- and the right of the
- center of the 5x5
- You can place the chests as high
- as you like for more storage
- ---Example---
- t = turtle
- c = chest
- x = empty spot
- O = center of the area to dig
- x c t c x
- x x x x x
- c c O c c
- x x x x x
- x x x x x
- --]]
- --[[ Enter Starting Position ]]
- StartingRadius = 3
- StartingHeight = 1
- --[[ Defaults ]]
- --StartingRadius = 3
- --StartingHeight = 1
- --------------------------------------------------------
- dir = "z"
- facing = 1
- x = 0
- z = 2
- y = 1
- xmax = math.floor(width/2)
- xmin = 0-math.floor(width/2)
- zmax = math.floor(length/2)
- zmin = 0-math.floor(length/2)
- stop = 0
- returning = 0
- function refuel()
- if turtle.getFuelLevel() < ((width + length + height) * 2) then
- turtle.select(16)
- if turtle.refuel(1) then
- if turtle.getItemCount(16) < 2 then
- print "Low on Fuel. Restocking..."
- home()
- restock()
- goBack()
- end
- else
- print "Low on Fuel. Restocking..."
- home()
- restock()
- goBack()
- end
- turtle.select(1)
- end
- end
- function forward()
- local dig = 1
- torch = false
- if returning == 0 then
- refuel()
- end
- if (z % 7) == 0 and (x % 7) == 0 then
- torch = true
- turnLeft()
- turnLeft()
- turtle.dig()
- turnLeft()
- turnLeft()
- if turtle.getItemCount(15) < 5 and returning == 0 then
- home()
- restock()
- goBack()
- end
- end
- if dir == "x" then
- if facing == 1 and x == xmax then
- dig = 0
- end
- if facing == -1 and x == xmin then
- dig = 0
- end
- end
- if dir == "z" then
- if facing == 1 and z == zmax then
- dig = 0
- end
- if facing == -1 and z == zmin then
- dig = 0
- end
- end
- while not turtle.forward() and dig == 1 do
- turtle.dig()
- turtle.attack()
- end
- if torch == true and y == 1 then
- turnLeft()
- turnLeft()
- turtle.select(15)
- turtle.place()
- turtle.select(1)
- turnLeft()
- turnLeft()
- torch = false
- end
- if dir == "z" then
- z = z + facing
- elseif dir == "x" then
- x = x + facing
- end
- if y == 1 then
- turtle.select(1)
- turtle.placeDown()
- end
- if y == height then
- turtle.placeUp()
- end
- if returning == 0 then
- if turtle.getItemCount(14) > 0 then
- print "Inventory Full. Dropping off Items..."
- home()
- restock()
- goBack()
- end
- end
- end
- function turnRight()
- turtle.turnRight()
- if dir == "z" then
- dir = "x"
- elseif dir == "x" then
- dir = "z"
- if facing == 1 then
- facing = -1
- elseif facing == -1 then
- facing = 1
- end
- end
- end
- function turnLeft()
- turtle.turnLeft()
- if dir == "z" then
- dir = "x"
- if facing == 1 then
- facing = -1
- elseif facing == -1 then
- facing = 1
- end
- elseif dir == "x" then
- dir = "z"
- end
- end
- function up()
- while turtle.up() == false do
- turtle.digUp()
- end
- y = y + 1
- end
- function down()
- while turtle.down() == false do
- turtle.digDown()
- end
- y = y - 1
- end
- function dig()
- if y < height then
- if inspectUp("minecraft:flowing_water") or inspectUp("minecraft:water") or inspectUp("minecraft:lava") or inspectUp("minecraft:flowing_lava") then
- up()
- if inspectUp("minecraft:flowing_water") or inspectUp("minecraft:water") or inspectUp("minecraft:lava") or inspectUp("minecraft:flowing_lava") then
- turtle.placeUp()
- end
- for i=1,4 do
- if inspect("minecraft:flowing_water") or inspect("minecraft:water") or inspect("minecraft:lava") or inspect("minecraft:flowing_lava") then
- turtle.place()
- turtle.dig()
- end
- turnRight()
- end
- down()
- end
- while turtle.digUp() do
- end
- if inspectUp("minecraft:gravel") or inspectUp("minecraft:sand") then
- while turtle.digUp() do
- sleep(1)
- end
- end
- end
- end
- function home()
- oldx = x
- oldz = z
- oldy = y
- olddir = dir
- oldfacing = facing
- returning = 1
- while y > 1 do
- down()
- end
- if dir == "z" then
- if facing == 1 then
- if z > 3 then
- turnRight()
- turnRight()
- while z > 3 do
- forward()
- end
- turnLeft()
- while x < 0 do
- forward()
- end
- turnRight()
- forward()
- elseif z < 3 then
- turnRight()
- forward()
- turnLeft()
- while z < 3 do
- forward()
- end
- turnRight()
- while x < 0 do
- forward()
- end
- turnRight()
- forward()
- elseif z == 3 then
- turnRight()
- while x < 0 do
- forward()
- end
- turnRight()
- forward()
- end
- elseif facing == -1 then
- if z < 3 then
- turnRight()
- turnRight()
- while z < 3 do
- forward()
- end
- turnLeft()
- while x > 0 do
- forward()
- end
- turnLeft()
- forward()
- elseif z > 3 then
- turnRight()
- forward()
- turnLeft()
- while z > 3 do
- forward()
- end
- turnRight()
- while x > 0 do
- forward()
- end
- turnLeft()
- forward()
- elseif z == 3 then
- turnLeft()
- while x < 0 do
- forward()
- end
- turnLeft()
- forward()
- end
- end
- elseif dir == "x" then
- if facing == 1 then
- if x > 0 then
- turnRight()
- turnRight()
- while x > 0 do
- forward()
- end
- turnLeft()
- while z > 2 do
- forward()
- end
- elseif x < 0 then
- turnRight()
- forward()
- turnLeft()
- while x < 0 do
- forward()
- end
- turnRight()
- while z > 2 do
- forward()
- end
- elseif x == 0 then
- turnRight()
- while z > 2 do
- forward()
- end
- end
- elseif facing == -1 then
- if x > 3 then
- turnRight()
- forward()
- turnLeft()
- while x > 3 do
- forward()
- end
- turnRight()
- while z < 3 do
- forward()
- end
- turnLeft()
- while x > 0 do
- forward()
- end
- turnLeft()
- forward()
- elseif x < 3 then
- turnRight()
- turnRight()
- while x < 3 do
- forward()
- end
- turnLeft()
- while z < 3 do
- forward()
- end
- turnLeft()
- while x > 0 do
- forward()
- end
- turnLeft()
- forward()
- end
- end
- end
- turnLeft()
- turnLeft()
- returning = 0
- end
- function dropoff()
- for i=2,14 do
- turtle.select(i)
- if turtle.drop() == false and turtle.getItemCount() > 0 then
- return false
- end
- end
- return true
- end
- function inspect(block)
- p1, p2 = turtle.inspect()
- if p1 == true then
- for k,v in pairs(p2) do
- if v == block then
- return true
- else
- return false
- end
- end
- else
- return false
- end
- end
- function inspectUp(block)
- p1, p2 = turtle.inspectUp()
- if p1 == true then
- for k,v in pairs(p2) do
- if v == block then
- return true
- else
- return false
- end
- end
- else
- return false
- end
- end
- function detail(item)
- local data = turtle.getItemDetail()
- if data then
- if data.name == item then
- return true
- else
- return false
- end
- else
- return false
- end
- end
- function stick()
- turtle.select(1)
- turtle.transferTo(5)
- turnLeft()
- turnLeft()
- turtle.suck()
- turtle.craft()
- if detail("minecraft:coal") or detail("minecraft:charcoal") then
- turtle.drop()
- turtle.select(2)
- turtle.transferTo(1)
- turtle.select(1)
- end
- turnLeft()
- turnLeft()
- turtle.transferTo(15)
- end
- function planks()
- turtle.select(1)
- turtle.transferTo(5,(math.floor(turtle.getItemCount()/2)))
- turtle.craft()
- if detail("minecraft:planks") then
- turtle.drop()
- turtle.select(5)
- turtle.drop()
- turtle.select(2)
- turtle.transferTo(1)
- end
- stick()
- end
- function log()
- turtle.select(1)
- turtle.craft()
- if detail("minecraft:log") then
- turtle.drop()
- turtle.select(2)
- turtle.transferTo(1)
- end
- planks()
- end
- function restock()
- local empty = 0
- returning = 1
- turnLeft()
- turnLeft()
- forward()
- turnRight()
- forward()
- turnLeft()
- while inspect("minecraft:chest") == true and empty == 0 do
- if dropoff() == true then
- empty = 1
- else
- up()
- end
- end
- if empty == 0 then
- while y > 1 do
- down()
- end
- turnLeft()
- forward()
- forward()
- turnRight()
- while inspect("minecraft:chest") == true and empty == 0 do
- if dropoff() == true then
- empty = 1
- else
- up()
- end
- end
- end
- if empty == 1 then
- while y > 1 do
- down()
- end
- if x > 0 then
- turnRight()
- forward()
- turnRight()
- else
- turnLeft()
- forward()
- turnLeft()
- end
- forward()
- end
- if empty == 0 then
- shell.exit()
- print "WARNING! No more storage: Shutting down..."
- print "Press any key to end."
- end
- if turtle.getItemCount(15) < 60 then
- turnLeft()
- turtle.select(16)
- turtle.drop()
- turnRight()
- turtle.select(1)
- turtle.drop()
- turtle.select(15)
- turnRight()
- turtle.drop()
- turtle.select(1)
- while turtle.getItemCount(15) < 60 do
- turtle.select(15)
- turtle.drop()
- turtle.select(1)
- turtle.suck()
- if detail("minecraft:torch") then
- turtle.transferTo(15)
- elseif detail("minecraft:stick") then
- stick()
- elseif detail("minecraft:planks") then
- planks()
- elseif detail("minecraft:log") then
- log()
- end
- end
- dropoff()
- turnLeft()
- turtle.select(1)
- turtle.suck()
- end
- if turtle.getItemCount(16) < 60 then
- turnLeft()
- turtle.select(16)
- while turtle.getItemCount() < 60 do
- turtle.suck(5)
- end
- turnRight()
- turtle.select(1)
- end
- returning = 0
- end
- function goBack()
- returning = 1
- forward()
- turtle.select(1)
- turtle.suck()
- if oldx > 0 then
- turnRight()
- while x < oldx do
- forward()
- end
- turnLeft()
- elseif oldx < 0 then
- turnLeft()
- while x > oldx do
- forward()
- end
- turnRight()
- end
- if x > -3 and x < 3 and oldz < 3 then
- turnRight()
- while x < 3 do
- forward()
- end
- turnLeft()
- end
- if oldz > 0 then
- while z < oldz do
- forward()
- end
- elseif oldz < 0 then
- turnLeft()
- turnLeft()
- while z > oldz do
- forward()
- end
- turnLeft()
- turnLeft()
- end
- if x > oldx then
- turnLeft()
- while x > oldx do
- forward()
- end
- turnRight()
- end
- while dir ~= olddir or facing ~= oldfacing do
- turnRight()
- end
- while y < oldy do
- up()
- end
- returning = 0
- end
- levels = math.ceil(height/2)
- goback = 0
- for i=1,levels do
- while y < StartingHeight do
- up()
- end
- while y < ((i*2)-1) do
- up()
- end
- ring = 6
- if StartingRadius > 3 then
- if goback == 0 then
- goback = 1
- print "Starting Radius set higher than 3"
- print "Moving to new start"
- ring = StartingRadius * 2
- while z < StartingRadius and z < zmax do
- forward()
- dig()
- end
- turnRight()
- dig()
- while x < StartingRadius and x < xmax do
- forward()
- dig()
- end
- turnRight()
- end
- else
- dig()
- forward()
- dig()
- turnLeft()
- forward()
- dig()
- forward()
- dig()
- turnRight()
- turnRight()
- while x < 3 do
- forward()
- dig()
- end
- turnRight()
- end
- while z < zmax or x > xmin or stop == 0 do
- for i=1,(ring) do
- if z > zmin then
- forward()
- dig()
- end
- end
- turnRight()
- for i=1,(ring) do
- if x > xmin then
- forward()
- dig()
- end
- end
- turnRight()
- ring = ring + 1
- for i=1,(ring) do
- if z < zmax then
- forward()
- dig()
- end
- end
- turnRight()
- if x == xmin and z == zmax then
- stop = 1
- end
- for i=1,(ring) do
- if x < xmax and stop == 0 then
- forward()
- dig()
- end
- end
- turnRight()
- ring = ring + 1
- end
- turnLeft()
- turnLeft()
- home()
- restock()
- end
- print ("Finished Clearing Area!")
- print ("Mined an area " .. length .. " by " .. width .. " by " .. height .. ".")
- print ("Mined a total area of " .. (length * width * height) .. " blocks!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement