Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Modified for mirrored dual-turtle deployment
- print("Enter length:")
- local length = tonumber(read())
- print("Enter width:")
- local width = tonumber(read())
- print("Enter depth:")
- local depth = tonumber(read())
- print("Is this the LEFT turtle? (y/n)")
- local isLeft = read():lower() == "y"
- local fuelSlot = 16
- -- STATE
- local x, y, z = 0, 0, 0 -- relative coordinates
- local dir = 0 -- 0=N, 1=E, 2=S, 3=W
- -- === MOVEMENT HELPERS ===
- function refuel()
- if turtle.getFuelLevel() < 10 then
- turtle.select(fuelSlot)
- if not turtle.refuel(1) then
- print("⚠️ Low fuel and no coal in slot 16!")
- sleep(5)
- end
- end
- end
- function tryDig() while turtle.detect() do turtle.dig(); sleep(0.4) end end
- function tryDigDown() while turtle.detectDown() do turtle.digDown(); sleep(0.4) end end
- function tryDigUp() while turtle.detectUp() do turtle.digUp(); sleep(0.4) end end
- function forward()
- refuel()
- tryDig()
- while not turtle.forward() do sleep(0.2) end
- if dir == 0 then z = z + 1
- elseif dir == 1 then x = x + 1
- elseif dir == 2 then z = z - 1
- elseif dir == 3 then x = x - 1 end
- end
- function back()
- refuel()
- while not turtle.back() do sleep(0.2) end
- if dir == 0 then z = z - 1
- elseif dir == 1 then x = x - 1
- elseif dir == 2 then z = z + 1
- elseif dir == 3 then x = x + 1 end
- end
- function down()
- refuel()
- tryDigDown()
- while not turtle.down() do sleep(0.2) end
- y = y - 1
- end
- function up()
- refuel()
- tryDigUp()
- while not turtle.up() do sleep(0.2) end
- y = y + 1
- end
- function turnLeft()
- turtle.turnLeft()
- dir = (dir - 1) % 4
- if dir < 0 then dir = dir + 4 end
- end
- function turnRight()
- turtle.turnRight()
- dir = (dir + 1) % 4
- end
- function face(target)
- while dir ~= target do turnRight() end
- end
- -- === GO TO COORDINATE ===
- function goTo(targetX, targetY, targetZ, targetDir)
- while y < targetY do up() end
- while y > targetY do down() end
- if x < targetX then face(1) while x < targetX do forward() end
- elseif x > targetX then face(3) while x > targetX do forward() end end
- if z < targetZ then face(0) while z < targetZ do forward() end
- elseif z > targetZ then face(2) while z > targetZ do forward() end end
- face(targetDir or 0)
- end
- -- === INVENTORY HANDLING ===
- function isInventoryFull()
- for i = 1, 15 do
- if turtle.getItemCount(i) == 0 then return false end
- end
- return true
- end
- function sortAndDropItems()
- for i = 1, 15 do
- if i ~= fuelSlot then
- turtle.select(i)
- local item = turtle.getItemDetail()
- if item then
- if item.name == "minecraft:coal" then
- turtle.transferTo(fuelSlot)
- else
- turtle.drop()
- end
- end
- end
- end
- turtle.select(1)
- end
- -- === MINING FUNCTION ===
- function mineLayer()
- local primary = isLeft and length or width
- local secondary = isLeft and width or length
- for row = 1, secondary do
- for col = 1, primary - 1 do
- forward()
- if isInventoryFull() then sortAndDropItems() end
- end
- if row < secondary then
- if row % 2 == 1 then
- if isLeft then turnRight(); forward(); turnRight()
- else turnLeft(); forward(); turnLeft() end
- else
- if isLeft then turnLeft(); forward(); turnLeft()
- else turnRight(); forward(); turnRight() end
- end
- end
- end
- if secondary % 2 == 1 then face(isLeft and 2 or 0) for i = 1, primary - 1 do forward() end end
- face(isLeft and 3 or 1) for i = 1, secondary - 1 do forward() end
- face(0)
- end
- -- === MAIN EXECUTION ===
- print("Starting mining...")
- turtle.digDown()
- down()
- for d = 1, depth do
- mineLayer()
- if d < depth then down() end
- end
- -- Final sort and drop of remaining unwanted blocks
- sortAndDropItems()
- -- Final return to origin
- goTo(0, 0, 0, 0)
- print("Mining complete.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement