Advertisement
Guest User

Mine

a guest
Jul 30th, 2015
425
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 7.40 KB | None | 0 0
  1. --Foogles Mining Software
  2. --Foogle Proof Mine 1.1 (7/30/2015)
  3. --Install:    in your turtle console, type pastebin get <code> Mine
  4. --            the code will be in the forum contents
  5. --Pre-Launch: put a bucket (empty or with lava) in any inventory slot
  6. --            place 32 or more cobblestone in any inventory slot(s)
  7. --Launch:     type the file name (in this case Mine) followed by a number
  8. --            for how long you want the mine shaft to be
  9. --            because this turtle program doesn't support chest use, you
  10. --            shouldn't make it longer than 100 to avoid overfilling your turtle
  11. --            For example, type: Mine 30
  12. --            To make the turtle mine a 30 block shaft and then come back
  13.  
  14.  
  15. --global variables (their scope applies to all functions in this file)
  16. args = {...}
  17. local reg = 0
  18. local up = 1
  19. local down = 2
  20.  
  21. --this is the only function that is automatically called, and all
  22. --it really does is coordinates the order that the methods
  23. --which actually accomplish things will be executed in
  24. --1. GetBuild() Find a block of cobblestone for building walls
  25. --2. Continue() Move forward, clearing a 1x2 path (even if gravel is in the way)
  26. --3. Search() Analyze the nearby blocks, searching for ores, gaps, lava, and water
  27. --            This function will also call methods to obtain lava for automatic fueling
  28. --4. CheckFuel() Attempt to refuel with a lava bucket if the fuel tank is less than 99% full
  29. --5. Return() This function will utilize Continue() to return to the starting location
  30. function Mine()
  31.   for i=1,args[1],1 do --do this the amount of times you specified (ex. Mine 10, does it 10 times)
  32.     CheckFuel()
  33.     GetBuild()
  34.     Continue()
  35.     Search()
  36.   end
  37.   Return()
  38. end
  39.  
  40. --this function is used to find a building block (cobblestone)
  41. --in the inventory and select it before placing a block
  42. --it starts at the beginning and checks every inventory slot until
  43. --it finds cobblestone, or reaches the end. If it finds cobble,
  44. --it selects it
  45. function GetBuild()
  46.   for i=1,16 do
  47.     if (turtle.getItemDetail(i) ~= nil) then
  48.       if (turtle.getItemDetail(i).name == 'minecraft:cobblestone' or turtle.getItemDetail(i).name == 'minecraft:dirt') then
  49.         turtle.select(i)
  50.         break
  51.       end
  52.     end
  53.   end
  54. end
  55.  
  56. --this behaves similarly to GetBuild() but instead tries to find a lava
  57. -- bucket which this turtle uses for fuel
  58. function GetFuel()
  59.   for i=1,16 do
  60.     if (turtle.getItemDetail(i) ~= nil) then
  61.       if (turtle.getItemDetail(i).name == 'minecraft:lava_bucket') then
  62.         turtle.select(i)
  63.         break
  64.       end
  65.     end
  66.   end
  67. end
  68.  
  69. --this behaves similarly to GetFuel() but it tries to find an
  70. --empty bucket to refill
  71. function GetBucket()
  72.   for i=1,16 do
  73.     if (turtle.getItemDetail(i) ~= nil) then
  74.       if (turtle.getItemDetail(i).name == 'minecraft:bucket') then
  75.         turtle.select(i)
  76.         return true
  77.       end
  78.     end
  79.   end
  80.   return false
  81. end
  82.  
  83. --This search function makes the turtle move and turn towards
  84. --all visible blocks in one vertical sliver of the mine shaft
  85.  
  86. function Search()
  87.   turtle.turnLeft() --face lower left block
  88.   Check(reg) --check block in front of it
  89.   turtle.up() --face upper left block
  90.   Check(reg)
  91.   turtle.turnRight()
  92.   turtle.turnRight() --face upper right block
  93.   Check(reg)
  94.   Check(up) --check block above it
  95.   if (turtle.down() == false) then --face lower right block
  96.     turtle.digDown()
  97.     turtle.down()
  98.   end
  99.   Check(reg)
  100.   Check(down) --check block below it
  101.   turtle.turnLeft() --face forward again
  102. end
  103.  
  104. --This function analyzes a block in front, above, or below
  105. --and determines what to do about it.
  106. --1. If it detects air, it will place cobblestone
  107. --2. If it detects a non dirt, cobblestone, gravel, or stone block,
  108. --   it will mine it and place cobblestone
  109. --3. If it detects lava, it will attempt to pick it up with a bucket
  110. --4. It will move into a water/lava block above or beneath it to remove
  111. --   the source and then fill it with cobblestone to seal the passage
  112.  
  113. function Check(dir)
  114.   local throw, success, block = 0;
  115.   if (dir == up) then
  116.     throw, block = turtle.inspectUp() --save what the block above it is
  117.   elseif (dir == down) then
  118.     throw, block = turtle.inspectDown() --save what the block below it is
  119.   else
  120.     throw, block = turtle.inspect() --save what the block in front of it is
  121.   end
  122.   success = 1
  123.   --if it finds lava, it will select an empty bucket and collect the lava
  124.   if (block.name == 'minecraft:lava' or block.name == 'minecraft:flowing_lava') then
  125.     GetBucket()
  126.     if (dir == up) then
  127.       turtle.placeUp()
  128.     elseif (dir == down) then
  129.       turtle.placeDown()
  130.     else
  131.       turtle.place()
  132.     end
  133.     GetBuild() --switches back to the building block (cobble)
  134.   end
  135.   --below, it scans a block in front, above, or beneath it
  136.   --and replaces if with cobblestone if it is not on the white list below
  137.   --if it runs out of cobblestone, it may place a random block
  138.   if (block.name ~= 'minecraft:stone' and block.name ~= 'minecraft:dirt' and block.name ~= 'minecraft:gravel' and block.name ~= 'minecraft:cobblestone') then
  139.     if (dir == up) then
  140.       turtle.digUp()
  141.       success = turtle.placeUp()
  142.     elseif (dir == down) then
  143.       turtle.digDown()
  144.       success = turtle.placeDown()
  145.     else
  146.       turtle.dig()
  147.       turtle.place()
  148.     end
  149.     --sometimes when it tries to place a block in a liquid space it fails
  150.     --to combat this, it will "fill" the space by moving into it and then out
  151.     --and placing cobblestone before the liquid flows back in
  152.     if (success == false) then
  153.       Fill(dir)
  154.     end
  155.   end
  156. end
  157.  
  158. --this function is short but powerful. It is solely responsible
  159. --for making sure that the turtle moves the correct number of spaces
  160. --First it digs in front of it, then it moves into the space if possible
  161. --Then it digs up. If it failed to move into the space,
  162. --It will call itself again. This usually only happens with gravel
  163. --or sand, but it also triggers when an entity blocks its path
  164. --It doesn't have path finding for alternate routes, but it will keep
  165. --trying to move and dig until the path is clear
  166. function Continue()
  167.   turtle.dig()
  168.   local x = turtle.forward()
  169.   turtle.digUp()
  170.   if (x == false) then
  171.     Continue()
  172.   end
  173. end
  174.  
  175. --This short function utilizes the recursion of continue() to (hopefully)
  176. --guarantee that it will return to the place where it was left, including
  177. --the same orientation. The turtle will not repair walls and seal the
  178. --shaft on the way back, but instead it will quickly mine any
  179. --gravel or obstacles that have fallen into the shaft on its
  180. --return trip
  181. function Return()
  182.   turtle.turnLeft()
  183.   turtle.turnLeft()
  184.   for i=1,args[1],1 do
  185.     Continue()
  186.   end
  187.   turtle.turnLeft()
  188.   turtle.turnLeft()
  189. end
  190.  
  191. --This function is used to fill in liquids in the floor and ceiling that
  192. --the turtle would otherwise fail to seal, so that a player
  193. --can walk through the shaft without hazards
  194. function  Fill(d)
  195.   if (d == 1) then
  196.     turtle.up()
  197.     turtle.down()
  198.     turtle.placeUp()
  199.   elseif (d == 2) then
  200.     turtle.down()
  201.     turtle.up()
  202.     turtle.placeDown()
  203.   end
  204. end
  205.  
  206. --This function will refuel the turtle with a lava bucket if it is below 99%
  207. function CheckFuel()
  208.   if (turtle.getFuelLevel() < 99000) then
  209.     GetFuel()
  210.     turtle.refuel()
  211.   end
  212. end
  213.  
  214. --this method call starts the program, and goes
  215. --at the end so it can find all the methods
  216.  
  217. Mine()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement