Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Define starting position (replace with your coordinates)
- local startX, startY, startZ = 0, 0, 0
- -- Ask for excavation distance
- local distance = redstone.getInput("Distance?")
- -- Function to check if inventory is full
- function isInventoryFull()
- for slot = 2, #turtle.getItemCount() do
- if turtle.getItemCount(slot) == 0 then
- return false
- end
- end
- return true
- end
- -- Function to deposit inventory (except coal)
- function depositInventory()
- for slot = 2, #turtle.getItemCount() do
- turtle.suckUp(slot)
- end
- end
- -- Function to refuel
- function refuelTurtle()
- local chest = turtle.getFront()
- if chest.getInventory() then
- local coalSlot = chest.getItemSlot("coal")
- if coalSlot then
- turtle.suckUpFromSlot(chest, coalSlot)
- turtle.selectSlot(1)
- turtle.insertItem(1)
- end
- end
- end
- -- Main program loop
- while distance > 0 do
- -- Check fuel before digging
- local fuelLevel = turtle.getItemCount(1)
- if fuelLevel <= 0 then
- refuelTurtle()
- if turtle.getItemCount(1) == 0 then
- break -- Pause program if no fuel available
- end
- end
- -- Dig and move forward
- turtle.dig()
- turtle.forward()
- distance = distance - 1
- -- Check for completion or full inventory
- if distance == 0 then
- turtle.back() -- Return one block after completion
- elseif isInventoryFull() then
- turtle.goto(startX, startY, startZ) -- Return to starting point
- depositInventory()
- end
- end
- -- Print message upon program completion/pause
- if distance == 0 then
- print("Excavation complete!")
- else
- print("Refueling required. Program paused.")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement