Advertisement
Curlip

Foogle Proof Mining Program (Curlip Torch Edit)

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