Advertisement
Knito

baum.lua

Sep 30th, 2019
276
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.72 KB | None | 0 0
  1. -- tree mining
  2. -- pastebin get qBzVgNSg
  3. -- sapling is provided by a "clickmachine" from same mod
  4. -- or any other player imitating block which does
  5. -- right clicks with items
  6. -- mine trees up to 7 height
  7. -- make a roof in height 8 to prevent oak trees from
  8. -- growing weird
  9.  
  10. -- felling turtle required ( = turtle + diamond axe )
  11. -- fuel it before use
  12. -- put coal in the slot which is selected (u can c that)
  13. -- refuel( number of coals to eat from stack )
  14. -- i.e.: refuel( 1 ) -- eats 1 coal
  15.  
  16. function GoUp()
  17.  
  18. -- get the tree, go straight up
  19. -- clears the situation where after a chunk
  20. -- reload the bottom has a sapling and above it
  21. -- are logs. The sapling would never grow up.
  22.  
  23. for i=1, 7 do
  24.   if CheckSapling() == false then
  25.     turtle.dig()
  26.   end
  27.   turtle.digUp()
  28.   turtle.up()
  29. end
  30.  
  31. end
  32.  
  33. function CheckSapling()
  34. found = false
  35. local detect, what = turtle.inspect()
  36. if detect then
  37.     local anfang, ende = string.find( what.name, "sapling", 1, true )
  38.     if  ( anfang ~= nil ) then
  39.         found = true
  40.         print( "Sapling detected "..what.name )
  41.     end
  42. end
  43. return found
  44. end
  45.  
  46.  
  47. function WaitForTree()
  48. -- wait for tree
  49. loginfront = false
  50. while loginfront == false do
  51.   sleep( 1 )
  52.   detect, what = turtle.inspect()
  53.   if detect then
  54.     local anfang, ende = string.find( what.name, "_log", 1, true )
  55.     if  ( anfang ~= nil ) then
  56.         loginfront = true
  57.         print( "front log detected "..what.name )
  58.     end
  59.   end
  60.  end      
  61. end
  62.  
  63.  
  64. function TurnToTree()
  65. local detect, what, anfang, ende
  66.  
  67. notfound = true
  68. while notfound do
  69.  
  70. detect, what = turtle.inspect()
  71. if detect then
  72.     anfang, ende = string.find( what.name, "sapling", 1, true )
  73.     if anfang ~= nil then
  74.       notfound = false
  75.     end
  76.     anfang, ende = string.find( what.name, "_log", 1, true )
  77.     if anfang ~= nil then
  78.       notfound = false
  79.     end
  80. end
  81.  
  82. if notfound then
  83.     turtle.turnLeft()  
  84. end
  85.  
  86. end
  87. end
  88.  
  89. function GoDown()
  90.  
  91. local detect = false
  92. local what = ""
  93. local chestfound = false
  94.  
  95. -- going down to surface, until chest
  96. -- leaves are ok and get digged
  97.  
  98. print( "Going down and looking for chest" )
  99.  
  100. while chestfound == false do
  101.  
  102.   for i = 1, 4 do
  103.     turtle.turnLeft()
  104.     if CheckSapling() == false then
  105.         turtle.dig()
  106.     end
  107.    
  108.     -- try to get extra saplings
  109.     turtle.suck()
  110.     turtle.suckDown()
  111.    
  112.   end
  113.  
  114.  detect, what = turtle.inspectDown()
  115.  
  116.  if detect then
  117.  
  118.      
  119.   print( "down block= ".. what.name )
  120.  
  121.   if( what.name == "minecraft:chest" ) then
  122.    -- everything ok
  123.    print( "found my chest" )
  124.    chestfound = true
  125.   end
  126.  
  127.  
  128.   local anfang, ende = string.find( what.name, "_leaves", 1, true )
  129.  
  130.    if anfang ~= nil then
  131.    
  132.     turtle.digDown()
  133.    
  134.    end
  135.  
  136.   end
  137.  
  138.     turtle.down()  
  139.  
  140. end
  141.  
  142. end
  143.  
  144.  
  145. local detect, what
  146. local okay = true
  147.  
  148. -- label your turtle ie "label set XFiles"
  149.  
  150. if os.getComputerLabel() == nil then
  151.   os.setComputerLabel("Baum")
  152. end
  153.  
  154. -- copy this program to startup when its not "startup"
  155. -- to make it resistant against chunk reloads (ie return from nether)
  156.  
  157. me = fs.getName( shell.getRunningProgram() )
  158.  
  159. if( me ~=  "startup") then
  160.     print( "Overwriting startup with "..me )
  161.     if( fs.exists("startup") ) then
  162.         fs.delete("startup")
  163.     end
  164.     fs.copy( me, "startup" )
  165. end
  166.  
  167. -- Init after Chunk reload (random position over chest)
  168. -- find the base (chest)
  169. GoDown()
  170. -- Face the tree / sapling
  171. TurnToTree()
  172. -- often after a reload there's a sapling but
  173. -- there are logs above it. The sapling never grows.
  174. -- Go up and dig everything away
  175. GoUp()
  176.  
  177. -- Init finished
  178. -- main loop
  179.  
  180. while true do
  181.  
  182. GoDown()
  183.  
  184. -- unload all slots to chest
  185.  
  186. for i = 1, 16 do
  187.     turtle.select(i)
  188.     turtle.dropDown()
  189. end
  190.  
  191. TurnToTree()
  192. WaitForTree()
  193. GoUp()
  194.      
  195. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement