Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local slots=16
- local stopSlot=1
- local torchSlot=2
- local firstNonOreSlot=3
- local firstCargoSlot=3
- local lastNonOreSlot=firstCargoSlot - 1
- local allFullUp=false
- -- MoveUp, digging if necessary, but not removing the item in slot 2 (torches)
- function MoveUp()
- if turtle.detectUp() then
- turtle.select(torchSlot)
- 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(torchSlot)
- if not turtle.compare() then
- turtle.dig()
- else
- break
- end
- end
- return turtle.forward()
- end
- function DetectAllFull()
- allFullUp=true
- for n=firstCargoSlot, 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(stopSlot)
- 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 MineOreForward()
- isOre = false
- for junk = NonOreStartSlot, lastNonOreSlot, 1 do
- print("Checking forward for junk")
- turtle.select(junk)
- isOre = turtle.compare()
- if isOre then break end
- end
- if not isOre then
- print("Just junk here")
- else
- print("Should mine forward")
- end
- end
- function MineOreUp()
- isOre = false
- for junk = NonOreStartSlot, lastNonOreSlot, 1 do
- print("Checking up for junk")
- turtle.select(junk)
- isOre = turtle.compareUp()
- if isOre then break end
- end
- if not isOre then
- print("Just junk here")
- else
- print("Should mine up")
- end
- end
- function MineOreDown()
- isOre = false
- for junk = NonOreStartSlot, lastNonOreSlot, 1 do
- print("Checking down for junk")
- turtle.select(junk)
- isOre = turtle.compareDown()
- if isOre then break end
- end
- if not isOre then
- print("Just junk here")
- else
- print("Should mine down")
- end
- end
- function MineOre()
- MineOreUp()
- turtle.turnLeft()
- MineOreForward()
- turtle.turnLeft()
- turtle.turnLeft()
- MineOreForward()
- turtle.turnLeft()
- MineOreDown()
- 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()
- MineOre()
- end
- if allFullUp then
- turtle.up()
- ReturnBecauseAllFullUp()
- end
- end
- function ReturnBecauseAlreadyDone()
- print("Demarcation! Running home")
- while not OnStopBlock() and turtle.forward() do
- -- just keep going man
- end
- if not OnStopBlock() then
- print("Something's blocking me; halting")
- end
- end
- function DumpIntoChestBelow()
- Result = true
- for n=firstCargoSlot, slots, 1 do
- turtle.select(n)
- Result = Result and turtle.dropDown()
- end
- return Result
- end
- function MakeTunnel()
- local keepMining = true
- while not ShouldStop() and turtle.forward() do
- print("Hi Ho, hi ho...")
- -- detect torches here
- end
- if turtle.detectDown() then
- print("It's up to work I go")
- MoveUp()
- while not turtle.detect() do
- turtle.forward()
- end
- repeat
- MoveForward()
- MineOre()
- until GoneFarEnough()
- 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()
- ReturnBecauseAlreadyDone()
- end
- keepMining = DumpIntoChestBelow()
- -- reset to normal starting position
- turtle.turnRight()
- turtle.turnRight()
- turtle.forward()
- return chestFull
- end
- MakeTunnel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement