Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local tArgs = { ... }
- if #tArgs == 0 then
- print("Usage: <distance>")
- return
- end
- blocks = 0
- totalDist = 0
- local function refuel()
- slot = turtle.getSelectedSlot()
- turtle.select(1)
- if (turtle.getItemCount(1) == 1) then
- return false
- end
- turtle.refuel(turtle.getItemCount(1) - 1)
- turtle.select(slot)
- return true
- end
- local function printStatus()
- term.clear()
- print("Status: {")
- print(" Distance Covered: " .. totalDist)
- print(" Blocks excavated: " .. blocks)
- print(" Fuel Remaining: " .. turtle.getFuelLevel())
- print("}")
- end
- local function moveForward()
- if (turtle.forward() == false) then
- while turtle.dig() do
- blocks = blocks+1
- printStatus()
- end
- if (turtle.forward() == false) then
- if (turtle.getFuelLevel() == 0 and refuel() == false) then
- print("The turtle is out of fuel.")
- return false
- else
- print("The turtle is blocked.")
- return false
- end
- end
- end
- printStatus()
- return true
- end
- local function moveUp()
- if (turtle.up() == false) then
- while turtle.digUp() do
- end
- if (turtle.up() == false) then
- if (turtle.getFuelLevel() == 0 and refuel() == false) then
- print("The turtle has ran out of fuel.")
- return false
- else
- print("The turtle is blocked.")
- return false
- end
- end
- end
- return true
- end
- local function digForward()
- while turtle.dig() do
- blocks=blocks+1
- printStatus()
- end
- end
- local function full()
- for i = 1, 16 do
- if (turtle.getItemCount(i) == 0) then
- return false
- end
- end
- return true
- end
- local function unload()
- for i = 2, 16 do
- turtle.select(i)
- turtle.dropDown()
- end
- end
- local function startUnload()
- for i = 1, totalDist do
- turtle.back()
- end
- unload()
- end
- local function digSides()
- turtle.turnLeft()
- digForward(blocks)
- if (turtle.digDown()) then blocks=blocks+1 end
- turtle.down()
- printStatus()
- digForward(blocks)
- if (turtle.digDown()) then blocks=blocks+1 end
- turtle.down()
- printStatus()
- digForward(blocks)
- turtle.turnLeft()
- turtle.turnLeft()
- digForward(blocks)
- turtle.up()
- printStatus()
- digForward(blocks)
- turtle.up()
- printStatus()
- digForward(blocks)
- turtle.turnLeft()
- end
- local function mine(distance)
- for i=1,distance do
- if (full()) then startUnload() end
- moveForward(blocks)
- totalDist = totalDist+1
- digSides(blocks)
- end
- printStatus()
- startUnload(distance)
- end
- local distance = tonumber(tArgs[1])
- while distance > 0 do
- for i=1,totalDist do turtle.forward() end
- mine(distance, totalDist)
- print("Enter the new Distance: ")
- distance = tonumber(read())
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement