Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- 🐢 Smart Strip Miner: Mines 3-high, Snakes, Tracks Fuel + Inventory
- -- Chest behind turtle. Coal in slot 16.
- -- === Interactive Setup ===
- print("📐 Set up your mining area:")
- write("Enter width (X axis): ") width = tonumber(read())
- write("Enter length (Z axis): ") length = tonumber(read())
- write("Enter total depth to mine downward (in blocks): ") totalDepth = tonumber(read())
- if not width or not length or not totalDepth then
- error("❌ Invalid input. Please enter numbers only.")
- end
- local layers = math.floor(totalDepth / 3)
- -- === State ===
- local x, y, z = 0, 0, 0
- local dir = 0 -- 0=N, 1=E, 2=S, 3=W
- -- === Fuel Logic ===
- function fillFuelTank()
- local maxFuel = turtle.getFuelLimit()
- local currentFuel = turtle.getFuelLevel()
- local needed = maxFuel - currentFuel
- turtle.select(16)
- local coalCount = turtle.getItemCount(16)
- local perCoal = 80
- local coalToUse = math.min(math.ceil(needed / perCoal), coalCount)
- if coalToUse > 0 then
- print("⛽ Filling fuel with "..coalToUse.." coal...")
- turtle.refuel(coalToUse)
- print("✅ Fuel: "..turtle.getFuelLevel().."/"..maxFuel)
- else
- error("❌ No coal in slot 16.")
- end
- end
- function calculateFuelTo(xT, yT, zT)
- return math.abs(x - xT) + math.abs(y - yT) + math.abs(z - zT)
- end
- function ensureFuel(required)
- if turtle.getFuelLevel() < required then
- turtle.select(16)
- if not turtle.refuel(1) then
- print("⛽ Insert coal in slot 16 to continue...")
- while not turtle.refuel(1) do sleep(5) end
- end
- print("✅ Refueled to "..turtle.getFuelLevel())
- end
- end
- -- === Position & Direction ===
- function updatePosition(move)
- if move == "forward" then
- 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
- elseif move == "back" then
- 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
- elseif move == "down" then y = y - 1
- elseif move == "up" then y = y + 1 end
- end
- function turnLeft() dir = (dir - 1) % 4; turtle.turnLeft() end
- function turnRight() dir = (dir + 1) % 4; turtle.turnRight() end
- function face(targetDir) while dir ~= targetDir do turnRight() end end
- -- === Movement ===
- function smartForward()
- ensureFuel(1)
- while not turtle.forward() do
- turtle.dig()
- sleep(0.3)
- end
- updatePosition("forward")
- end
- function smartDown()
- ensureFuel(1)
- while not turtle.down() do
- turtle.digDown()
- sleep(0.3)
- end
- updatePosition("down")
- end
- function smartUp()
- ensureFuel(1)
- while not turtle.up() do
- turtle.digUp()
- sleep(0.3)
- end
- updatePosition("up")
- end
- function descendThree()
- for i = 1, 3 do smartDown() end
- end
- -- === Dig Helper ===
- function dig3Column()
- turtle.digUp()
- turtle.dig()
- turtle.digDown()
- end
- -- === Inventory ===
- function isInventoryFull()
- for i = 1, 15 do if turtle.getItemCount(i) == 0 then return false end end
- return true
- end
- function dumpInventory()
- for i = 1, 15 do
- turtle.select(i)
- turtle.drop()
- end
- end
- -- === Navigation ===
- function goTo(xT, yT, zT)
- while y > yT do smartDown() end
- while y < yT do smartUp() end
- if x > xT then face(3) elseif x < xT then face(1) end
- while x ~= xT do smartForward() end
- if z > zT then face(0) elseif z < zT then face(2) end
- while z ~= zT do smartForward() end
- end
- -- === MAIN ===
- fillFuelTank()
- for layer = 1, layers do
- print("⛏️ Mining layer "..layer.." at Y="..y)
- for row = 1, width do
- for col = 1, length - 1 do
- dig3Column()
- if turtle.getFuelLevel() < calculateFuelTo(0, 0, 0) + 10 then
- print("⚠️ Returning to refuel.")
- local sx, sy, sz, sd = x, y, z, dir
- goTo(0, 0, 0)
- face(2)
- dumpInventory()
- ensureFuel(calculateFuelTo(sx, sy, sz))
- goTo(sx, sy, sz)
- face(sd)
- end
- if isInventoryFull() then
- print("📦 Inventory full. Returning.")
- local sx, sy, sz, sd = x, y, z, dir
- goTo(0, 0, 0)
- face(2)
- dumpInventory()
- goTo(sx, sy, sz)
- face(sd)
- end
- smartForward()
- end
- -- Snake turn
- if row < width then
- local turnFunc = row % 2 == 1 and turnRight or turnLeft
- turnFunc(); smartForward(); dig3Column(); turnFunc()
- end
- end
- -- End-of-layer dump and descend
- goTo(0, 0, 0)
- local returnDir = dir
- face(2) -- face South to chest
- dumpInventory()
- face(returnDir)
- if layer < layers then descendThree() end
- end
- print("✅ Done mining all layers.")
- goTo(0, 0, 0)
- face(2)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement