Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Configuration: Set these numbers before running
- local depth = tonumber(10) -- Number of blocks to mine down
- local forwardDistance = tonumber(20) -- Number of blocks to mine forward
- -- Function to dig down
- function mineDown(depth)
- if not depth or depth < 1 then
- print("Error: Invalid depth value.")
- return false
- end
- for i = 1, depth do
- if turtle.detectDown() then
- turtle.digDown()
- end
- if not turtle.down() then
- print("Can't move down! Something is blocking the way.")
- return false
- end
- end
- return true
- end
- -- Function to mine forward
- function mineForward(distance)
- if not distance or distance < 1 then
- print("Error: Invalid forward distance value.")
- return false
- end
- for i = 1, distance do
- if turtle.detect() then
- turtle.dig()
- turtle.digUp()
- end
- if not turtle.forward() then
- print("Can't move forward! Something is blocking the way.")
- return false
- end
- end
- return true
- end
- --Deposit Function
- function depositItems()
- print("Depositing items...")
- for slot = 1, 16 do
- turtle.select(slot) -- Select slot
- if turtle.getItemCount(slot) > 0 then
- turtle.drop() -- Drop into chest (must be in front)
- end
- end
- print("Deposit complete!")
- turtle.select(1) -- Reset selection
- end
- --Return Function
- function backAndDeposit(distance, depth)
- turtle.turnLeft()
- turtle.turnLeft()
- for i=1, distance do
- turtle.forward()
- end
- for i=1, depth do
- turtle.up()
- end
- turtle.turnRight()
- turtle.turnRight()
- depositItems()
- end
- -- Main Execution
- print("Starting mining operation...")
- if mineDown(depth) then
- print("Reached depth of " .. depth .. " blocks.")
- print("Starting forward mining...")
- mineForward(forwardDistance)
- print("Finished mining " .. forwardDistance .. " blocks forward.")
- else
- print("Mining operation stopped due to obstruction.")
- end
- print("Mining complete!")
- backAndDeposit(forwardDistance, depth)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement