Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local pos = 0
- local fuel = "minecraft:coal"
- local keep = {
- [fuel] = true,
- ["minecraft:ancient_debris"] = true,
- ["tconstruct:cobalt_ore"] = true,
- ["minecraft:netherrack"] = true
- }
- local badFluid = "minecraft:lava"
- local tunnelLength = 30 -- How long the tunnel should be
- -- Refuel from chest behind at start
- local function refuel()
- if pos > 0 then
- turtle.turnLeft()
- turtle.turnLeft() -- Face back toward start
- for i = 1, pos do
- while turtle.detect() do turtle.dig() end
- turtle.forward()
- end
- end
- -- At start, chest is behind
- for i = 1, 16 do
- local item = turtle.getItemDetail(i, false)
- if item and item.name == fuel then
- turtle.select(i)
- break
- end
- end
- while turtle.getFuelLevel() < 160 do
- turtle.suck() -- Pull fuel from chest behind
- turtle.refuel(1)
- end
- -- Return to mining position
- if pos > 0 then
- turtle.turnLeft()
- turtle.turnLeft() -- Face forward again
- for i = 1, pos do
- while turtle.detect() do turtle.dig() end
- turtle.forward()
- end
- end
- end
- -- Check if inventory is full (excluding kept items)
- local function isInventoryFull()
- for i = 1, 16 do
- if turtle.getItemCount(i) == 0 then
- return false -- Found an empty slot
- end
- end
- return true -- No empty slots
- end
- -- Deposit unwanted items into chest behind at start
- local function depositJunk()
- if pos > 0 then
- turtle.turnLeft()
- turtle.turnLeft() -- Face back toward start
- for i = 1, pos do
- while turtle.detect() do turtle.dig() end
- turtle.forward()
- end
- end
- -- At start, deposit into chest behind
- for i = 1, 16 do
- local item = turtle.getItemDetail(i, false)
- if item and not keep[item.name] then
- turtle.select(i)
- turtle.drop() -- Drop into chest behind
- end
- end
- -- Return to mining position
- if pos > 0 then
- turtle.turnLeft()
- turtle.turnLeft() -- Face forward again
- for i = 1, pos do
- while turtle.detect() do turtle.dig() end
- turtle.forward()
- end
- end
- end
- -- Select netherrack to place for lava
- local function selectPlaceable()
- for i = 1, 16 do
- local item = turtle.getItemDetail(i, false)
- if item and item.name == "minecraft:netherrack" then
- turtle.select(i)
- return true
- end
- end
- return false
- end
- -- Handle lava in the 3x3 area
- local function handleLava()
- local directions = {
- {check = turtle.inspect, place = turtle.place},
- {check = turtle.inspectUp, place = turtle.placeUp},
- {check = turtle.inspectDown, place = turtle.placeDown}
- }
- for _, dir in ipairs(directions) do
- local success, block = dir.check()
- if success and block.name == "minecraft:lava" and selectPlaceable() then
- dir.place()
- end
- end
- end
- -- Mine a 3x3 section
- local function mineSection()
- -- Mine forward (middle row)
- while turtle.detect() do turtle.dig() end
- -- Mine up (top row)
- while turtle.detectUp() do turtle.digUp() end
- -- Mine down (bottom row)
- while turtle.detectDown() do turtle.digDown() end
- -- Move up to clear top layer
- turtle.up()
- while turtle.detect() do turtle.dig() end
- turtle.down()
- -- Move down to clear bottom layer
- turtle.down()
- while turtle.detect() do turtle.dig() end
- turtle.up()
- handleLava()
- turtle.forward()
- end
- -- Main loop
- while true do
- if turtle.getFuelLevel() < 100 then
- refuel()
- end
- if isInventoryFull() then
- depositJunk()
- end
- if pos < tunnelLength then
- mineSection()
- pos = pos + 1
- else
- depositJunk() -- End of tunnel, reset
- pos = 0 -- Reset position to start a new tunnel
- end
- end
Add Comment
Please, Sign In to add comment