Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- chunkminer.lua
- -- Mines a 16x16 chunk, auto-refuels from a chest behind it
- -- === CONFIG ===
- local LENGTH = 16
- local WIDTH = 16
- -- === STATE ===
- local x, y, z = 0, 0, 0 -- Position tracking
- local dir = 0 -- 0=north,1=east,2=south,3=west
- local layer = 0
- -- === HELPERS ===
- local function turnLeft() turtle.turnLeft(); dir = (dir + 3) % 4 end
- local function turnRight() turtle.turnRight(); dir = (dir + 1) % 4 end
- local function forward()
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- sleep(0.4)
- end
- 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
- end
- local function up()
- while not turtle.up() do
- turtle.digUp()
- turtle.attackUp()
- sleep(0.4)
- end
- y = y + 1
- end
- local function down()
- while not turtle.down() do
- turtle.digDown()
- turtle.attackDown()
- sleep(0.4)
- end
- y = y - 1
- end
- -- === REFUELING ===
- local function refuel()
- if turtle.getFuelLevel() == "unlimited" then return end
- if turtle.getFuelLevel() > 100 then return end
- print("Refueling...")
- local turned = false
- -- Turn around to face the chest
- turnLeft()
- turnLeft()
- turned = true
- -- Try to suck fuel from chest
- for slot = 1, 16 do
- local detail = turtle.getItemDetail(slot)
- if detail == nil then
- turtle.suck()
- detail = turtle.getItemDetail(slot)
- end
- if detail and turtle.refuel(1) then
- while turtle.refuel(1) do end
- end
- end
- if turned then
- turnLeft()
- turnLeft()
- end
- print("Fuel Level: " .. turtle.getFuelLevel())
- end
- -- === MINING ===
- local function mineLayer()
- for row = 1, WIDTH do
- for col = 1, LENGTH - 1 do
- refuel()
- turtle.digDown()
- turtle.dig()
- forward()
- end
- if row < WIDTH then
- if row % 2 == 1 then
- turnRight()
- turtle.dig()
- forward()
- turnRight()
- else
- turnLeft()
- turtle.dig()
- forward()
- turnLeft()
- end
- end
- end
- -- Return to start of this layer
- if WIDTH % 2 == 1 then
- turnRight()
- else
- turnLeft()
- end
- for i = 1, WIDTH - 1 do
- forward()
- end
- if WIDTH % 2 == 1 then
- turnRight()
- else
- turnLeft()
- end
- for i = 1, LENGTH - 1 do
- forward()
- end
- end
- -- === MAIN ===
- local function main()
- print("Starting 16x16 chunk mining...")
- refuel()
- -- Go down until solid
- while not turtle.detectDown() do
- down()
- end
- -- Mine layers upward until ceiling hit or full inventory
- while true do
- mineLayer()
- print("Layer complete. Going up...")
- up()
- if turtle.detectUp() then
- print("Ceiling reached, stopping.")
- break
- end
- end
- print("Chunk mining complete!")
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment