Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local slots=16
- local allFullUp=false
- -- MoveUp, digging if necessary, but not removing the item in slot 2 (torches)
- function MoveUp()
- if turtle.detectUp() then
- turtle.select(2)
- if not turtle.compareUp() then
- turtle.digUp()
- end
- end
- turtle.up()
- end
- -- MoveForward, digging if necessary, but not removing the item in slot 2 (torches)
- function MoveForward()
- while turtle.detect() do
- turtle.select(2)
- if not turtle.compare() then
- turtle.dig()
- else
- break
- end
- end
- return turtle.forward()
- end
- function DetectAllFull()
- allFullUp=true
- for n=1, slots, 1 do
- if turtle.getItemCount(n) == 0 then
- allFullUp=false
- end
- end
- return allFullUp
- end
- function GoneFarEnough()
- local Result=true
- if turtle.detectDown() then
- Result = DetectAllFull()
- end
- if Result then
- print("Return to base")
- end
- return Result
- end
- function OnStopBlock()
- turtle.select(1)
- return turtle.compareDown()
- end
- -- We should stop if we've moved out into the air or we're on top of the stop block (in slot 1)
- function ShouldStop()
- return not turtle.detectDown() or OnStopBlock()
- end
- function ReturnBecauseAllFullUp()
- print("So much stuff!")
- while not turtle.detectDown() and turtle.forward() do
- end
- turtle.down()
- print("Nearly home")
- while not OnStopBlock() and turtle.forward() do
- end
- end
- function ReturnBecauseEndOfRun()
- print("My work here is done")
- while not DetectAllFull() and not OnStopBlock() do
- MoveForward()
- end
- if allFullUp then
- turtle.up()
- ReturnBecauseAllFullUp()
- end
- end
- while not ShouldStop() and turtle.forward() do
- print("Hi Ho, hi ho...")
- end
- if turtle.detectDown() then
- print("It's up to work I go")
- MoveUp()
- while not turtle.detect() do
- turtle.forward()
- end
- while not GoneFarEnough() do
- MoveForward()
- end
- turtle.turnRight()
- turtle.turnRight()
- if allFullUp then
- ReturnBecauseAllFullUp()
- else
- turtle.digDown() -- Just to be sure
- turtle.down()
- ReturnBecauseEndOfRun()
- end
- else
- print("Weird, this one's already done!")
- turtle.turnRight()
- turtle.turnRight()
- ReturnBecauseEndOfRun()
- end
- -- reset to normal starting position
- turtle.turnRight()
- turtle.turnRight()
- turtle.forward()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement