Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Quarry program with stairs, custom dimensions, and inventory management
- -- User input for quarry dimensions
- local length, width
- local currentX, currentY, currentZ = 0, 0, 0 -- Position of the turtle relative to the starting point
- local dir = 0 -- Direction: 0 = forward, 1 = right, 2 = backward, 3 = left
- -- Input the dimensions
- print("Enter quarry length:")
- length = tonumber(read())
- print("Enter quarry width:")
- width = tonumber(read())
- -- Fuel Management
- local function refuelIfNeeded()
- if turtle.getFuelLevel() < (length * width * 2) then -- Arbitrary number; adjust as needed for distance
- turtle.select(16)
- turtle.suckUp()
- turtle.refuel()
- end
- end
- -- Inventory Management: Return to the start, unload, refuel, then return to digging
- local function returnToStartAndUnload()
- -- Return to starting position
- while dir ~= 2 do -- Ensure turtle faces "backward" (towards starting point)
- turtle.turnRight()
- dir = (dir + 1) % 4
- end
- for i = 1, currentX do
- turtle.forward()
- end
- for i = 1, currentZ do
- turtle.up()
- end
- -- Unload items in chest above
- for i = 1, 15 do -- Leave slot 16 for fuel
- turtle.select(i)
- turtle.dropUp()
- end
- -- Refuel if needed
- refuelIfNeeded()
- -- Return to digging position
- for i = 1, currentZ do
- turtle.down()
- end
- for i = 1, currentX do
- turtle.back()
- end
- turtle.turnLeft() -- Return to facing forward
- dir = 0
- end
- -- Check if the inventory is full
- local function isInventoryFull()
- for i = 1, 15 do
- if turtle.getItemCount(i) == 0 then
- return false
- end
- end
- return true
- end
- -- Move forward safely (handle block detection)
- local function safeForward()
- while not turtle.forward() do
- turtle.dig()
- end
- currentX = currentX + 1
- end
- -- Turn right and update direction
- local function turnRight()
- turtle.turnRight()
- dir = (dir + 1) % 4
- end
- -- Turn left and update direction
- local function turnLeft()
- turtle.turnLeft()
- dir = (dir + 3) % 4
- end
- -- Move down and dig stairs
- local function digDown()
- turtle.digDown()
- turtle.down()
- currentZ = currentZ + 1
- if currentX % 2 == 0 then -- Every second block, dig a stair block
- turtle.dig()
- safeForward()
- end
- end
- -- Main quarry function
- local function quarry()
- for z = 1, math.huge do -- Keep going until bedrock
- for w = 1, width do
- for l = 1, length - 1 do
- if isInventoryFull() then
- returnToStartAndUnload()
- end
- turtle.digDown() -- Quarry digs down each block it moves over
- safeForward()
- end
- -- Check if the turtle needs to move to the next row
- if w < width then
- if w % 2 == 1 then
- turnRight()
- if isInventoryFull() then
- returnToStartAndUnload()
- end
- turtle.digDown()
- safeForward()
- turnRight()
- else
- turnLeft()
- if isInventoryFull() then
- returnToStartAndUnload()
- end
- turtle.digDown()
- safeForward()
- turnLeft()
- end
- end
- end
- -- When a full layer is done, dig down to the next layer
- if turtle.detectDown() then -- If bedrock or no block below
- print("Reached bedrock or obstruction")
- break
- else
- digDown()
- if z % 2 == 0 then
- turtle.dig() -- Digging stair every second layer
- safeForward()
- end
- end
- end
- -- Return to starting position when done
- returnToStartAndUnload()
- end
- -- Run the quarry function
- quarry()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement