Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- === CONFIG ===
- local CHUNK_SIZE = 16
- local LAYER_HEIGHT = 3
- local FUEL_BUFFER = 100
- local SAVE_FILE = "resume.dat"
- -- Whitelist mode: only keep these blocks
- local WHITELISTED_BLOCKS = {
- ["minecraft:coal_ore"] = true,
- ["minecraft:iron_ore"] = true,
- ["minecraft:copper_ore"] = true,
- ["minecraft:gold_ore"] = true,
- ["minecraft:redstone_ore"] = true,
- ["minecraft:lapis_ore"] = true,
- ["minecraft:diamond_ore"] = true,
- ["minecraft:emerald_ore"] = true,
- ["minecraft:deepslate_coal_ore"] = true,
- ["minecraft:deepslate_iron_ore"] = true,
- ["minecraft:deepslate_copper_ore"] = true,
- ["minecraft:deepslate_gold_ore"] = true,
- ["minecraft:deepslate_redstone_ore"] = true,
- ["minecraft:deepslate_lapis_ore"] = true,
- ["minecraft:deepslate_diamond_ore"] = true,
- ["minecraft:deepslate_emerald_ore"] = true
- }
- -- === STATE ===
- local x, y, z = 0, 0, 0
- local dir = 1
- local layer = 1
- local startX, startY, startZ, startDir = x, y, z, dir
- -- === SAVE / LOAD ===
- local function saveState()
- local f = fs.open(SAVE_FILE, "w")
- f.write(textutils.serialize({x=x, y=y, z=z, dir=dir, layer=layer}))
- f.close()
- end
- local function loadState()
- if not fs.exists(SAVE_FILE) then return false end
- local f = fs.open(SAVE_FILE, "r")
- local data = textutils.unserialize(f.readAll())
- f.close()
- x, y, z = data.x, data.y, data.z
- dir = data.dir
- layer = data.layer
- startX, startY, startZ, startDir = 0, 0, 0, 1
- return true
- end
- local function clearState()
- if fs.exists(SAVE_FILE) then fs.delete(SAVE_FILE) end
- end
- -- === DIRECTION HELPERS ===
- local function turnRight() turtle.turnRight(); dir = (dir + 1) % 4 end
- local function turnLeft() turtle.turnLeft(); dir = (dir - 1) % 4 end
- local function face(target) while dir ~= target do turnRight() end end
- local function faceExact(targetDir) while dir ~= targetDir do turnRight() end end
- local function updatePosition(dx, dy, dz) x, y, z = x + dx, y + dy, z + dz; saveState() end
- -- === INVENTORY ===
- local function isFull()
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then return false end
- end
- return true
- end
- local function dropUnlistedBlocks()
- for i = 1, 16 do
- turtle.select(i)
- local item = turtle.getItemDetail()
- if item and not WHITELISTED_BLOCKS[item.name] then
- turtle.drop()
- end
- end
- end
- -- === POSITIONING ===
- local function goTo(xT, yT, zT)
- while y < yT do turtle.down(); updatePosition(0, 1, 0) end
- while y > yT do turtle.up(); updatePosition(0, -1, 0) end
- face(1) while x < xT do turtle.forward(); updatePosition(1, 0, 0) end
- face(3) while x > xT do turtle.forward(); updatePosition(-1, 0, 0) end
- face(2) while z < zT do turtle.forward(); updatePosition(0, 0, 1) end
- face(0) while z > zT do turtle.forward(); updatePosition(0, 0, -1) end
- end
- -- === UNLOAD AT ORIGIN ===
- local function returnToStartAndUnload()
- goTo(startX, startY, startZ)
- faceExact(startDir)
- turnLeft(); turnLeft()
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- turnLeft(); turnLeft()
- end
- -- === FUEL ===
- local function refuelFromInventory()
- for i = 1, 16 do
- turtle.select(i)
- if turtle.refuel(0) then
- turtle.refuel()
- return true
- end
- end
- return false
- end
- local function refuelFromLeftChest()
- turnLeft()
- for i = 1, 16 do
- turtle.select(i)
- if turtle.getFuelLevel() < turtle.getFuelLimit() then
- turtle.suck()
- if turtle.refuel(0) then
- turtle.refuel()
- else
- turtle.drop()
- end
- end
- end
- turnRight()
- end
- local function checkFuel()
- local dist = math.abs(x - startX) + math.abs(y - startY) + math.abs(z - startZ)
- if turtle.getFuelLevel() < dist + FUEL_BUFFER then
- local sx, sy, sz, sd = x, y, z, dir
- returnToStartAndUnload()
- if not refuelFromInventory() then refuelFromLeftChest() end
- goTo(sx, sy, sz)
- faceExact(sd)
- end
- end
- -- === BEDROCK CHECK ===
- local function reachedBedrock()
- local success, data = turtle.inspectDown()
- return success and data.name == "minecraft:bedrock"
- end
- -- === MOVEMENT ===
- local function tryForward()
- if isFull() then
- local sx, sy, sz, sd = x, y, z, dir
- returnToStartAndUnload()
- checkFuel()
- goTo(sx, sy, sz)
- faceExact(sd)
- end
- checkFuel()
- while not turtle.forward() do
- turtle.dig()
- sleep(0.3)
- end
- turtle.digUp()
- turtle.digDown()
- dropUnlistedBlocks()
- if dir == 0 then updatePosition(0, 0, -1)
- elseif dir == 1 then updatePosition(1, 0, 0)
- elseif dir == 2 then updatePosition(0, 0, 1)
- elseif dir == 3 then updatePosition(-1, 0, 0) end
- end
- local function tryDown()
- checkFuel()
- while not turtle.down() do
- turtle.digDown()
- sleep(0.3)
- end
- updatePosition(0, 1, 0)
- end
- -- === DIG LAYER ===
- local function digLayer()
- print("⛏ Digging layer " .. layer .. " at y=" .. y)
- for row = 1, CHUNK_SIZE do
- for col = 1, CHUNK_SIZE - 1 do
- tryForward()
- end
- if row < CHUNK_SIZE then
- if row % 2 == 1 then turnRight(); tryForward(); turnRight()
- else turnLeft(); tryForward(); turnLeft() end
- end
- end
- -- Return to origin column
- if x > 0 then face(3) while x > 0 do turtle.forward(); updatePosition(-1, 0, 0) end end
- if x < 0 then face(1) while x < 0 do turtle.forward(); updatePosition(1, 0, 0) end end
- if z > 0 then face(0) while z > 0 do turtle.forward(); updatePosition(0, 0, -1) end end
- if z < 0 then face(2) while z < 0 do turtle.forward(); updatePosition(0, 0, 1) end end
- face(1)
- end
- -- === MAIN ===
- if fs.exists(SAVE_FILE) then
- print("Resume previous run? (y/n)")
- local input = read()
- if input:lower() == "y" then
- loadState()
- print("📍 Resumed at: x="..x.." y="..y.." z="..z.." dir="..dir.." layer="..layer)
- else
- clearState()
- x, y, z = 0, 0, 0
- dir = 1
- layer = 1
- end
- end
- print("📦 Starting Chunk Eater. Will stop at bedrock.")
- while true do
- digLayer()
- layer = layer + LAYER_HEIGHT
- saveState()
- if reachedBedrock() then
- print("🛑 Bedrock detected. Stopping dig.")
- break
- end
- print("⬇️ Descending to next layer...")
- for i = 1, LAYER_HEIGHT do
- if not reachedBedrock() then
- tryDown()
- else
- print("🛑 Bedrock reached during descent.")
- break
- end
- end
- end
- returnToStartAndUnload()
- clearState()
- print("✅ Chunk excavation complete.")
Advertisement
Add Comment
Please, Sign In to add comment