Pandana

TreeFarm

Jan 26th, 2021 (edited)
569
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.44 KB | None | 0 0
  1. wood_id = "minecraft:spruce_log"
  2. sapling_id = "minecraft:spruce_sapling"
  3. dirt_id = "minecraft:dirt"
  4. grass_id = "minecraft:grass_block"
  5. sleep_time = 5
  6.  
  7. function FindItemSlot (item_id)
  8.  
  9.     for i = 1, 16, 1 do
  10.  
  11.         turtle.select(i)
  12.         local data = turtle.getItemDetail()
  13.         if data then
  14.  
  15.             if data.name == item_id then
  16.                
  17.                 return i
  18.  
  19.             end
  20.  
  21.         end
  22.  
  23.     end
  24.  
  25.     return -1
  26.  
  27. end
  28.  
  29. function PlantTree ()
  30.  
  31.     slot = FindItemSlot(sapling_id)
  32.     turtle.select(slot)
  33.     turtle.place()
  34.  
  35. end
  36.  
  37. function ReturnToStart ()
  38.  
  39.     local ground_level = false
  40.  
  41.     while not ground_level do
  42.  
  43.         local _, data = turtle.inspectDown()
  44.         if data.name == dirt_id or data.name == grass_id then
  45.  
  46.             ground_level = true
  47.  
  48.         else
  49.    
  50.             while turtle.detectDown() do
  51.  
  52.                 turtle.digDown()
  53.  
  54.             end
  55.             turtle.down()
  56.  
  57.         end
  58.  
  59.     end
  60.  
  61. end
  62.  
  63. function ChopTree ()
  64.  
  65.     tree_exists = true
  66.  
  67.     while tree_exists do
  68.  
  69.         local _, data = turtle.inspect()
  70.  
  71.         if data.name == wood_id then
  72.  
  73.             turtle.dig()
  74.             while turtle.detectUp() do
  75.  
  76.                 turtle.digUp()
  77.  
  78.             end
  79.             turtle.up()
  80.  
  81.         else
  82.        
  83.             tree_exists = false
  84.  
  85.         end
  86.  
  87.     end
  88.     ReturnToStart()
  89.     PlantTree()
  90.  
  91. end
  92.  
  93. while true do
  94.    
  95.     local _, data = turtle.inspect()
  96.     if data.name == wood_id then
  97.  
  98.         ChopTree()
  99.  
  100.     else
  101.  
  102.         os.sleep(sleep_time)
  103.  
  104.     end
  105.  
  106. end
Add Comment
Please, Sign In to add comment