Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print("Enter length:")
- local length = tonumber(read())
- print("Enter width:")
- local width = tonumber(read())
- print("Enter depth:")
- local depth = tonumber(read())
- -- STATE
- local x, y, z = 0, 0, 0 -- relative coordinates
- local dir = 0 -- 0=N, 1=E, 2=S, 3=W
- local bucketSlot = 16 -- Lava bucket slot
- local lastFuelPercent = -1
- -- === BLACKLIST ===
- local blacklist = {
- ["minecraft:cobbled_deepslate"] = true,
- ["minecraft:cobblestone"] = true
- }
- -- === REFUELING SYSTEM ===
- function getFuelPercent()
- local current = turtle.getFuelLevel()
- local max = 20000 -- Assumed max fuel
- return current / max
- end
- function tryConsumeFuel()
- local percent = getFuelPercent()
- -- Skip fuel consumption if above 5%
- if percent >= 0.05 then return end
- -- After lava refueling, if fuel is still below 5%, consume from inventory
- for i = 1, 15 do
- turtle.select(i)
- while turtle.getItemCount(i) > 0 do
- if turtle.refuel(1) then
- print("Consumed fuel from slot " .. i .. ", current fuel level: " .. turtle.getFuelLevel())
- else
- break
- end
- end
- end
- turtle.select(1)
- end
- -- === LAVA COLLECTION FUNCTION ===
- function tryCollectLava()
- turtle.select(bucketSlot)
- local detail = turtle.getItemDetail(bucketSlot)
- if detail and detail.name == "minecraft:bucket" then
- if turtle.place() then
- sleep(0.2)
- local newDetail = turtle.getItemDetail(bucketSlot)
- if newDetail and newDetail.name == "minecraft:lava_bucket" then
- if turtle.refuel(1) then
- print("Lava bucket consumed for fuel, current fuel level: " .. turtle.getFuelLevel())
- else
- print("Lava bucket not consumed.")
- end
- else
- print("No lava source in front.")
- end
- end
- end
- turtle.select(1)
- end
- -- === BLACKLIST FILTER ===
- function dropBlacklistedItems()
- for i = 1, 15 do
- turtle.select(i)
- local detail = turtle.getItemDetail(i)
- if detail and blacklist[detail.name] then
- turtle.dropDown()
- print("Dropped blacklisted item: " .. detail.name)
- end
- end
- turtle.select(1)
- end
- -- === FUEL PERCENT MONITOR ===
- function monitorFuel()
- local percent = getFuelPercent()
- if lastFuelPercent == -1 then
- lastFuelPercent = percent
- elseif math.abs(percent - lastFuelPercent) >= 0.05 then
- print("Fuel level changed: " .. math.floor(percent * 100) .. "%")
- lastFuelPercent = percent
- end
- end
- -- === MOVEMENT HELPERS ===
- function tryDig() while turtle.detect() do turtle.dig(); sleep(0.4) end end
- function tryDigDown() while turtle.detectDown() do turtle.digDown(); sleep(0.4) end end
- function tryDigUp() while turtle.detectUp() do turtle.digUp(); sleep(0.4) end end
- function forward()
- tryConsumeFuel()
- tryCollectLava()
- tryDig()
- dropBlacklistedItems()
- monitorFuel()
- while not turtle.forward() do sleep(0.2) 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
- function back()
- tryConsumeFuel()
- tryCollectLava()
- tryDig()
- dropBlacklistedItems()
- monitorFuel()
- while not turtle.back() do sleep(0.2) 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
- function down()
- tryConsumeFuel()
- tryCollectLava()
- tryDigDown()
- monitorFuel()
- while not turtle.down() do sleep(0.2) end
- y = y - 1
- end
- function up()
- tryConsumeFuel()
- tryCollectLava()
- tryDigUp()
- monitorFuel()
- while not turtle.up() do sleep(0.2) end
- y = y + 1
- end
- function turnLeft()
- turtle.turnLeft()
- dir = (dir - 1) % 4
- if dir < 0 then dir = dir + 4 end
- end
- function turnRight()
- turtle.turnRight()
- dir = (dir + 1) % 4
- end
- function face(target)
- while dir ~= target do turnRight() end
- end
- -- === GO TO COORDINATE ===
- function goTo(targetX, targetY, targetZ, targetDir)
- while y < targetY do up() end
- while y > targetY do down() end
- if x < targetX then face(1) while x < targetX do forward() end
- elseif x > targetX then face(3) while x > targetX do forward() end end
- if z < targetZ then face(0) while z < targetZ do forward() end
- elseif z > targetZ then face(2) while z > targetZ do forward() end end
- face(targetDir or 0)
- end
- -- === INVENTORY HANDLING ===
- function isInventoryFull()
- for i = 1, 15 do
- if turtle.getItemCount(i) == 0 then return false end
- end
- return true
- end
- function dropItems()
- local saveX, saveY, saveZ, saveDir = x, y, z, dir
- goTo(0, 0, 0, 2)
- for i = 1, 15 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- goTo(saveX, saveY, saveZ, saveDir)
- end
- -- === MINING FUNCTION ===
- function mineLayer()
- for row = 1, width do
- for col = 1, length - 1 do
- forward()
- if isInventoryFull() then dropItems() end
- end
- if row < width then
- if row % 2 == 1 then turnRight(); forward(); turnRight()
- else turnLeft(); forward(); turnLeft() end
- end
- end
- if width % 2 == 1 then face(2) for i = 1, length - 1 do forward() end end
- face(3) for i = 1, width - 1 do forward() end
- face(0)
- dropBlacklistedItems()
- end
- -- === MAIN EXECUTION ===
- print("Starting mining...")
- turtle.digDown()
- down()
- for d = 1, depth do
- mineLayer()
- if d < depth then down() end
- end
- goTo(0, 0, 0, 2)
- for i = 1, 15 do
- turtle.select(i)
- turtle.drop()
- end
- turtle.select(1)
- goTo(0, 0, 0, 0)
- print("Mining complete. Ready to unload into chest.")
Add Comment
Please, Sign In to add comment