Advertisement
Guest User

strip ore miner v2

a guest
Feb 28th, 2015
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.26 KB | None | 0 0
  1. local slots=16
  2. local stopSlot=1
  3. local torchSlot=2
  4. local firstNonOreSlot=3
  5. local firstCargoSlot=3
  6. local lastNonOreSlot=firstCargoSlot - 1
  7. local allFullUp=false
  8.  
  9. -- MoveUp, digging if necessary, but not removing the item in slot 2 (torches)
  10. function MoveUp()
  11.   if turtle.detectUp() then
  12.     turtle.select(torchSlot)
  13.     if not turtle.compareUp() then
  14.       turtle.digUp()
  15.     end
  16.   end
  17.   turtle.up()
  18. end
  19.  
  20. -- MoveForward, digging if necessary, but not removing the item in slot 2 (torches)
  21. function MoveForward()
  22.   while turtle.detect() do
  23.     turtle.select(torchSlot)
  24.     if not turtle.compare() then
  25.       turtle.dig()
  26.     else
  27.       break
  28.     end
  29.   end
  30.   return turtle.forward()
  31. end
  32.  
  33. function DetectAllFull()
  34.   allFullUp=true
  35.   for n=firstCargoSlot, slots, 1 do
  36.     if turtle.getItemCount(n) == 0 then
  37.       allFullUp=false
  38.     end
  39.   end
  40.   return allFullUp
  41. end
  42.  
  43. function GoneFarEnough()
  44.   local Result=true
  45.   if turtle.detectDown() then
  46.     Result = DetectAllFull()
  47.   end
  48.   if Result then
  49.     print("Return to base")
  50.   end
  51.   return Result
  52. end
  53.  
  54. function OnStopBlock()
  55.   turtle.select(stopSlot)
  56.   return turtle.compareDown()
  57. end
  58.  
  59. -- We should stop if we've moved out into the air or we're on top of the stop block (in slot 1)
  60. function ShouldStop()
  61.   return not turtle.detectDown() or OnStopBlock()
  62. end
  63.  
  64. function MineOreForward()
  65.   isOre = false
  66.   for junk = NonOreStartSlot, lastNonOreSlot, 1 do
  67.     print("Checking forward for junk")
  68.     turtle.select(junk)
  69.     isOre = turtle.compare()
  70.     if isOre then break end
  71.   end
  72.   if not isOre then
  73.     print("Just junk here")
  74.   else
  75.     print("Should mine forward")
  76.   end
  77. end
  78.  
  79. function MineOreUp()
  80.   isOre = false
  81.   for junk = NonOreStartSlot, lastNonOreSlot, 1 do
  82.     print("Checking up for junk")
  83.     turtle.select(junk)
  84.     isOre = turtle.compareUp()
  85.     if isOre then break end
  86.   end
  87.   if not isOre then
  88.     print("Just junk here")
  89.   else
  90.     print("Should mine up")
  91.   end
  92. end
  93.  
  94. function MineOreDown()
  95.   isOre = false
  96.   for junk = NonOreStartSlot, lastNonOreSlot, 1 do
  97.     print("Checking down for junk")
  98.     turtle.select(junk)
  99.     isOre = turtle.compareDown()
  100.     if isOre then break end
  101.   end
  102.   if not isOre then
  103.     print("Just junk here")
  104.   else
  105.     print("Should mine down")
  106.   end
  107. end
  108.  
  109. function MineOre()
  110.   MineOreUp()
  111.   turtle.turnLeft()
  112.   MineOreForward()
  113.   turtle.turnLeft()
  114.   turtle.turnLeft()
  115.   MineOreForward()
  116.   turtle.turnLeft()
  117.   MineOreDown()
  118. end
  119.  
  120. function ReturnBecauseAllFullUp()
  121.   print("So much stuff!")
  122.   while not turtle.detectDown() and turtle.forward() do
  123.   end
  124.   turtle.down()
  125.   print("Nearly home")
  126.   while not OnStopBlock() and turtle.forward() do
  127.   end  
  128. end
  129.  
  130. function ReturnBecauseEndOfRun()
  131.   print("My work here is done")
  132.   while not DetectAllFull() and not OnStopBlock() do
  133.     MoveForward()
  134.     MineOre()
  135.   end
  136.   if allFullUp then
  137.     turtle.up()
  138.     ReturnBecauseAllFullUp()
  139.   end
  140. end
  141.  
  142. function ReturnBecauseAlreadyDone()
  143.   print("Demarcation! Running home")
  144.   while not OnStopBlock() and turtle.forward() do
  145.     -- just keep going man
  146.   end
  147.   if not OnStopBlock() then
  148.     print("Something's blocking me; halting")
  149.   end
  150. end
  151.  
  152. function DumpIntoChestBelow()
  153.   Result = true
  154.   for n=firstCargoSlot, slots, 1 do
  155.     turtle.select(n)
  156.     Result = Result and turtle.dropDown()
  157.   end
  158.   return Result
  159. end
  160.  
  161. function MakeTunnel()
  162.   local keepMining = true
  163.   while not ShouldStop() and turtle.forward() do
  164.     print("Hi Ho, hi ho...")
  165.     -- detect torches here
  166.   end
  167.   if turtle.detectDown() then
  168.     print("It's up to work I go")
  169.     MoveUp()
  170.     while not turtle.detect() do
  171.       turtle.forward()
  172.     end
  173.     repeat
  174.       MoveForward()
  175.       MineOre()
  176.     until GoneFarEnough()
  177.     turtle.turnRight()
  178.     turtle.turnRight()
  179.     if allFullUp then
  180.       ReturnBecauseAllFullUp()
  181.     else
  182.       turtle.digDown() -- Just to be sure
  183.       turtle.down()
  184.       ReturnBecauseEndOfRun()
  185.     end
  186.   else
  187.     print("Weird, this one's already done!")
  188.     turtle.turnRight()
  189.     turtle.turnRight()
  190.     ReturnBecauseAlreadyDone()
  191.   end
  192.   keepMining = DumpIntoChestBelow()
  193.   -- reset to normal starting position
  194.   turtle.turnRight()
  195.   turtle.turnRight()
  196.   turtle.forward()
  197.   return chestFull
  198. end
  199.  
  200. MakeTunnel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement