Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Branch Mining Turtle Program
- -- Digs 2-high main tunnel with branches every 2 blocks
- -- Ignores cobblestone, returns to refuel/unload at origin
- -- === CONFIG ===
- local MAIN_TUNNEL_LENGTH = 50 -- Length of the main tunnel
- local BRANCH_LENGTH = 6 -- How far each side branch goes
- local BRANCH_SPACING = 2 -- How often to branch
- local TORCH_INTERVAL = 10
- local TORCH_SLOT = 16
- local FUEL_BUFFER = 100
- -- === STATE ===
- local step = 0
- local x, y, z, dir = 0, 0, 0, 1 -- Assume facing East
- local startX, startY, startZ, startDir = 0, 0, 0, 1
- local cobbleNames = {
- ["minecraft:cobblestone"] = true,
- ["minecraft:stone"] = true,
- ["minecraft:gravel"] = true
- }
- -- === DIRECTION ===
- local function update(dx, dy, dz) x, y, z = x + dx, y + dy, z + dz end
- local function turnRight() turtle.turnRight(); dir = (dir + 1) % 4 end
- local function turnLeft() turtle.turnLeft(); dir = (dir - 1) % 4 end
- local function face(d) while dir ~= d do turnRight() end end
- -- === MOVEMENT ===
- local function tryForward()
- while not turtle.forward() do turtle.dig(); sleep(0.2) end
- if dir == 0 then update(0, 0, -1)
- elseif dir == 1 then update(1, 0, 0)
- elseif dir == 2 then update(0, 0, 1)
- elseif dir == 3 then update(-1, 0, 0) end
- end
- local function tryUp()
- while not turtle.up() do turtle.digUp(); sleep(0.2) end
- update(0, 1, 0)
- end
- local function tryDown()
- while not turtle.down() do turtle.digDown(); sleep(0.2) end
- update(0, -1, 0)
- end
- -- === POSITIONING ===
- local function goTo(tx, ty, tz)
- while y > ty do tryUp() end
- while y < ty do tryDown() end
- if x < tx then face(1) while x < tx do tryForward() end end
- if x > tx then face(3) while x > tx do tryForward() end end
- if z < tz then face(2) while z < tz do tryForward() end end
- if z > tz then face(0) while z > tz do tryForward() end end
- end
- local function returnToOrigin()
- goTo(startX, startY, startZ)
- face(startDir)
- end
- -- === INVENTORY ===
- local function isFull()
- for i = 1, 15 do
- if turtle.getItemCount(i) == 0 then return false end
- end
- return true
- end
- local function dropCobble()
- for i = 1, 15 do
- local detail = turtle.getItemDetail(i)
- if detail and cobbleNames[detail.name] then
- turtle.select(i)
- turtle.drop()
- end
- end
- end
- local function unloadInventory()
- print("📦 Unloading...")
- local ox, oy, oz, od = x, y, z, dir
- returnToOrigin()
- face((startDir + 2) % 4)
- for i = 1, 15 do turtle.select(i); turtle.drop() end
- face(startDir)
- goTo(ox, oy, oz); face(od)
- end
- -- === FUEL ===
- local function refuelIfNeeded()
- if turtle.getFuelLevel() == "unlimited" or turtle.getFuelLevel() > FUEL_BUFFER then return end
- print("🔋 Refueling...")
- local ox, oy, oz, od = x, y, z, dir
- returnToOrigin()
- face((startDir - 1) % 4)
- for i = 1, 16 do
- turtle.select(i)
- if turtle.suck() and turtle.refuel() then break end
- end
- face(startDir)
- goTo(ox, oy, oz); face(od)
- end
- -- === DIGGING ===
- local function digTunnelSection()
- turtle.dig()
- tryForward()
- turtle.digUp()
- tryUp()
- placeTorch()
- tryDown()
- end
- -- === TORCH ===
- local function placeTorch()
- if step % TORCH_INTERVAL == 0 then
- turtle.select(TORCH_SLOT)
- turtle.placeUp()
- print("🕯️ Torch placed")
- end
- end
- local function digBranch(dirOffset)
- local originalDir = dir
- if dirOffset == "left" then turnLeft() else turnRight() end
- for i = 1, BRANCH_LENGTH do
- turtle.dig()
- tryForward()
- turtle.digUp()
- tryUp()
- tryDown()
- end
- -- Turn around and return
- turnRight(); turnRight()
- for i = 1, BRANCH_LENGTH do tryForward() end
- face(originalDir)
- end
- -- === MAIN ===
- startX, startY, startZ, startDir = x, y, z, dir
- print("🚜 Starting branch mining...")
- for i = 1, MAIN_TUNNEL_LENGTH do
- digTunnelSection()
- step = step + 1
- if step % BRANCH_SPACING == 0 then
- digBranch("left")
- digBranch("right")
- end
- dropCobble()
- if isFull() then unloadInventory() end
- refuelIfNeeded()
- end
- returnToOrigin()
- print("✅ Mining complete. Returned to start.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement