Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Straight Staircase Miner — Simpler Turtle Program
- -- === CONFIG ===
- local TORCH_INTERVAL = 10
- local TORCH_SLOT = 16
- local FUEL_BUFFER = 100
- -- === STATE ===
- local stepCount = 0
- local dir = 1 -- 1 = East
- local x, y, z = 0, 0, 0
- local startX, startY, startZ, startDir = 0, 0, 0, dir
- -- === HELPERS ===
- local function update(dx, dy, dz) x, y, z = x + dx, y + dy, z + dz end
- 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 tryDown()
- while not turtle.down() do
- turtle.digDown()
- sleep(0.2)
- end
- update(0, -1, 0)
- end
- local function tryUp()
- while not turtle.up() do
- turtle.digUp()
- sleep(0.2)
- end
- update(0, 1, 0)
- end
- local function face(d)
- while dir ~= d do turtle.turnRight(); dir = (dir + 1) % 4 end
- end
- 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 unloadInventory()
- print("📦 Inventory full. Returning to unload...")
- 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("🔋 Fuel low. Returning to refuel...")
- 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
- -- === TORCH ===
- local function placeTorch()
- if stepCount % TORCH_INTERVAL == 0 then
- turtle.select(TORCH_SLOT)
- turtle.placeUp()
- print("🕯️ Placed torch.")
- end
- end
- -- === BEDROCK ===
- local function isBedrockBelow()
- local ok, data = turtle.inspectDown()
- return ok and data.name == "minecraft:bedrock"
- end
- -- === MAIN ===
- print("Enter depth to dig (or 'bedrock'):")
- local input = read()
- input = input:lower()
- local toBedrock = (input == "bedrock")
- local targetY = tonumber(input)
- if not toBedrock and (not targetY or targetY <= 0) then print("❌ Invalid input.") return end
- startX, startY, startZ, startDir = x, y, z, dir
- print("⛏️ Starting straight staircase...")
- while true do
- if toBedrock and isBedrockBelow() then print("🪨 Bedrock reached."); break end
- if not toBedrock and y >= targetY then print("📉 Reached target depth."); break end
- turtle.dig()
- tryForward()
- turtle.digDown()
- tryDown()
- stepCount = stepCount + 1
- placeTorch()
- if isFull() then unloadInventory() end
- refuelIfNeeded()
- end
- returnToOrigin()
- print("✅ Staircase complete. Turtle returned to start.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement