Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- ✅ FINAL CHUNK EATER: Mines 16x16, returns to start to unload/refuel
- -- === CONFIG ===
- local CHUNK_SIZE = 16
- local LAYER_HEIGHT = 3
- local FUEL_BUFFER = 100
- -- === POSITION TRACKING ===
- local x, y, z = 0, 0, 0
- local dir = 1 -- 0=north, 1=east, 2=south, 3=west
- local startX, startY, startZ, startDir = x, y, z, dir
- -- === 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 end
- -- === INVENTORY CHECK ===
- local function isFull()
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then return false end
- end
- return true
- end
- -- === GO TO COORDINATES ===
- 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
- -- === RETURN TO START AND UNLOAD BEHIND ===
- local function returnToStartAndUnload()
- print("📦 Returning to original start point to dump items...")
- goTo(startX, startY, startZ)
- faceExact(startDir)
- -- Dump behind
- turnLeft(); turnLeft()
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop()
- end
- turnLeft(); turnLeft()
- print("✅ Dump complete. Returning to work...")
- end
- -- === REFUELING ===
- 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 checkFuel()
- local estReturn = math.abs(x - startX) + math.abs(y - startY) + math.abs(z - startZ) + FUEL_BUFFER
- if turtle.getFuelLevel() < estReturn then
- local sx, sy, sz, sd = x, y, z, dir
- print("⚠️ Low fuel. Returning to refuel...")
- returnToStartAndUnload()
- while not refuelFromInventory() do
- print("⌛ Waiting for fuel in inventory...")
- sleep(2)
- end
- goTo(sx, sy, sz)
- faceExact(sd)
- end
- end
- -- === MOVEMENT ===
- local function tryForward()
- if isFull() then
- print("📦 Inventory full before move. Returning to dump...")
- 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()
- 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 tryUp()
- checkFuel()
- while not turtle.up() do
- turtle.digUp()
- sleep(0.3)
- end
- updatePosition(0, -1, 0)
- 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()
- 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 ===
- startX, startY, startZ, startDir = x, y, z, dir
- print("Enter depth to dig:")
- local depth = tonumber(read())
- if not depth or depth <= 0 then
- print("❌ Invalid depth.")
- return
- end
- for layer = 1, depth, LAYER_HEIGHT do
- digLayer()
- if layer + LAYER_HEIGHT <= depth then
- print("⬇️ Descending to next layer...")
- for i = 1, LAYER_HEIGHT do tryDown() end
- end
- end
- returnToStartAndUnload()
- print("✅ Chunk excavation complete. Turtle returned to start.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement