Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- miner.lua
- local startY = 92
- local targetY = 12
- local depth = startY - targetY
- local length = 60
- local maxStrips = 20
- local fuelThreshold = 500
- local stripCount = 0
- local lateralOffset = 0
- turtle.refuel(64)
- local trashList = {
- ["minecraft:stone"] = true,
- ["minecraft:gravel"] = true,
- ["minecraft:dirt"] = true,
- ["minecraft:cobblestone"] = true,
- ["minecraft:sand"] = true,
- ["minecraft:flint"] = true
- }
- function shiftLeft(n)
- print("Shifting left " .. n .. " blocks...")
- turtle.turnLeft()
- for i = 1, n do
- local tries = 0
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- sleep(0.2)
- tries = tries + 1
- if tries >= 10 then
- print("Failed to shift left after 10 tries. Skipping.")
- break
- end
- end
- end
- turtle.turnRight()
- end
- function checkFuel()
- print("Checking fuel...")
- local level = turtle.getFuelLevel()
- if level < fuelThreshold then
- print("Fuel too low. Refueling")
- turtle.back()
- sleep(5)
- turtle.refuel()
- turtle.forward()
- turtle.select(1)
- end
- end
- function shouldTrash(name)
- return trashList[name] or false
- end
- function cleanInventory()
- print("Cleaning inventory...")
- for slot = 1, 16 do
- turtle.select(slot)
- local item = turtle.getItemDetail()
- if item and shouldTrash(item.name) then
- print("Dropping:", item.name)
- turtle.dropDown()
- end
- end
- end
- function goToStripStart()
- print("Returning to mine...")
- -- Move forward to strip depth
- for i = 1, 7 do
- turtle.forward()
- end
- -- Move left to current strip offset
- if lateralOffset > 0 then
- turtle.turnLeft()
- for i = 1, lateralOffset do
- turtle.forward()
- end
- turtle.turnRight()
- end
- end
- function mineDown(d)
- print("Mining down to depth " .. d)
- for i = 1, d do
- turtle.digDown()
- turtle.down()
- end
- end
- function mineForward()
- print("Mining forward...")
- for i = 1, length do
- turtle.dig()
- local tries = 0
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- sleep(0.2)
- tries = tries + 1
- if tries >= 10 then break end
- end
- turtle.turnLeft()
- turtle.dig()
- turtle.turnRight()
- turtle.turnRight()
- turtle.dig()
- turtle.turnLeft()
- end
- turtle.turnLeft()
- turtle.turnLeft()
- for i = 1, length do
- local tries = 0
- while not turtle.forward() do
- turtle.dig()
- turtle.attack()
- sleep(0.2)
- tries = tries + 1
- if tries >= 10 then break end
- end
- end
- turtle.turnLeft()
- turtle.turnLeft()
- end
- function returnToBaseFrom(depth)
- print("Returning to base from depth " .. depth)
- for i = 1, depth do
- turtle.up()
- end
- for i = 1, 7 do
- turtle.back()
- end
- if lateralOffset > 0 then
- turtle.turnRight()
- for i = 1, lateralOffset do
- turtle.forward()
- end
- turtle.turnLeft()
- end
- end
- function dumpInventoryToHopper()
- print("Dumping inventory...")
- for slot = 1, 16 do
- turtle.select(slot)
- turtle.dropDown()
- end
- turtle.select(1)
- end
- -- Main loop
- while stripCount < maxStrips do
- -- Layer 1
- goToStripStart()
- mineDown(depth)
- mineForward()
- cleanInventory()
- returnToBaseFrom(depth)
- dumpInventoryToHopper()
- sleep(3)
- checkFuel()
- -- Layer 2
- goToStripStart()
- mineDown(depth + 1)
- mineForward()
- cleanInventory()
- returnToBaseFrom(depth + 1)
- dumpInventoryToHopper()
- sleep(3)
- checkFuel()
- -- Layer 3
- goToStripStart()
- mineDown(depth + 2)
- mineForward()
- cleanInventory()
- returnToBaseFrom(depth + 2)
- dumpInventoryToHopper()
- sleep(3)
- checkFuel()
- -- Layer 4
- goToStripStart()
- mineDown(depth + 3)
- mineForward()
- cleanInventory()
- returnToBaseFrom(depth + 3)
- dumpInventoryToHopper()
- sleep(3)
- checkFuel()
- -- Layer 5
- goToStripStart()
- mineDown(depth + 4)
- mineForward()
- cleanInventory()
- returnToBaseFrom(depth + 4)
- dumpInventoryToHopper()
- sleep(3)
- checkFuel()
- lateralOffset = lateralOffset + 3
- stripCount = stripCount + 1
- print("Strip #" .. stripCount .. " complete")
- end
- print("Mining operation complete.")
Advertisement
Add Comment
Please, Sign In to add comment