Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Robust movement to dig through obstacles
- function safeMoveForward()
- while not turtle.forward() do
- turtle.dig() -- Dig block in front (stone, gravel, etc.)
- os.sleep(0.1) -- Pause for gravel/sand to fall
- end
- end
- -- Dig 3x1 (forward, up, down)
- function digStep()
- turtle.dig() -- Dig forward
- turtle.digUp() -- Dig above
- turtle.digDown() -- Dig below
- safeMoveForward() -- Move forward, digging if needed
- end
- -- Mine a tunnel of given length
- function mineTunnel(length)
- for i = 1, length do
- digStep()
- -- Check fuel and inventory every 10 blocks
- if i % 10 == 0 then
- if turtle.getFuelLevel() < 20 then
- print("Low fuel! Stopping.")
- return false
- end
- if turtle.getItemCount(16) > 0 then
- print("Inventory full! Stopping.")
- return false
- end
- end
- end
- return true
- end
- -- Unload inventory into chest in front
- function unload()
- for i = 1, 16 do
- turtle.select(i)
- turtle.drop() -- Drop into chest
- end
- turtle.select(1)
- end
- -- Main program for multi-turtle setup
- function main()
- print("Starting mining run...")
- -- Mine 32 blocks out (2 chunks)
- if mineTunnel(32) then
- turtle.turnLeft()
- safeMoveForward() -- Shift 1 block left
- turtle.turnLeft() -- Face negative X
- -- Mine 32 blocks back
- if mineTunnel(32) then
- print("Mining complete!")
- -- Face chest at Z=502 (adjust Z if needed)
- -- Turtle is at Z=502/504/506; adjust to Z=502
- local turtleZ = 502 -- Change to your chest's Z
- local steps = turtleZ == 502 and 0 or (turtleZ == 504 and 2) or -2 -- Move to Z=502
- if steps ~= 0 then
- if steps > 0 then
- turtle.turnLeft() -- Face positive Z
- else
- turtle.turnRight() -- Face negative Z
- end
- for i = 1, math.abs(steps) do
- safeMoveForward()
- end
- if steps > 0 then
- turtle.turnRight() -- Face negative X
- else
- turtle.turnLeft() -- Face negative X
- end
- end
- -- Move 1 block to chest (X=505 to X=500)
- safeMoveForward()
- else
- print("Return trip failed. Check fuel/inventory.")
- end
- else
- print("Outbound trip failed. Check fuel/inventory.")
- end
- -- Unload into chest
- unload()
- print("Inventory unloaded.")
- end
- -- Run the program
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement