Advertisement
Efud933

TreeFarm2.1

Jan 5th, 2022
707
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.07 KB | None | 0 0
  1. --Returns ID of block in front of turtle
  2. function viewBlock()
  3.     local success, data = turtle.inspect()
  4.  
  5.     if success then
  6.         itemId = data.name
  7.         print(itemId)
  8.         return itemId
  9.     end
  10. end
  11.  
  12. --BasicWoodcutLoop
  13. function cut()
  14.  
  15.     for i = 0,6 do
  16.         turtle.digUp()
  17.         turtle.up()
  18.     end
  19.    
  20.     turtle.dig()
  21.     turtle.forward()
  22.    
  23.     for i = 0,6 do
  24.         turtle.digDown()
  25.         turtle.down()
  26.     end
  27.    
  28.     turtle.forward()
  29.    
  30. end
  31.  
  32.  
  33. --Basic movement loop
  34. function moveForward()
  35.  
  36.     for i = 0,5 do
  37.         turtle.forward()
  38.     end
  39. end
  40.  
  41. function moveAround()
  42.     turtle.turnRight()
  43.     turtle.forward()
  44.     turtle.turnLeft()
  45.     turtle.forward()
  46.     turtle.forward()
  47.     turtle.turnLeft()
  48.     turtle.forward()
  49.     turtle.turnRight()
  50. end
  51.  
  52. --Turns and plants sapling
  53. function plant()
  54.     turtle.turnLeft()
  55.     turtle.turnLeft()
  56.     turtle.place()
  57.     turtle.turnLeft()
  58.     turtle.turnLeft()
  59. end
  60.  
  61. function detectCut()
  62.     viewedBlock = viewBlock()
  63.     if viewedBlock == "minecraft:spruce_log" then
  64.         cut()
  65.     else
  66.         moveAround()
  67.     end
  68.  
  69. end
  70.  
  71. --Cuts entire column of trees
  72. function cutColumn()
  73.     for i = 1,treesInColumn do  
  74.         detectCut()
  75.         plant()
  76.         if counter < timesToMove then
  77.             moveForward()
  78.             counter = counter + 1
  79.         end
  80.     end
  81.     counter = 0
  82. end
  83.  
  84. --Updates Faceinit value to current facing (True if facing initial direction, false if opposite)
  85. function updateFacing()
  86.     if faceInit == true then
  87.         faceInit = false
  88.         else
  89.         faceInit = true
  90.     end
  91. end
  92.  
  93. --Moves between rows to cut the next one
  94. function moveRows()
  95.     if faceInit == true then
  96.         turtle.turnRight()
  97.     else
  98.         turtle.turnLeft()
  99.     end
  100.     moveForward()
  101.     if faceInit == true then
  102.         turtle.turnRight()
  103.     else
  104.         turtle.turnLeft()
  105.     end
  106.     updateFacing()
  107.  
  108.  
  109. end
  110.  
  111.  
  112.    
  113.          
  114.  
  115.  
  116. --RunTime Loop
  117. run = true
  118. faceInit = true
  119. treesInColumn = 6 -- UPDATE ME TO FIT SIZE OF TREE FARM
  120. numOfColumns = 4 -- UPDATE ME TO FIT SIZE OF TREE FARM
  121. timesToMove = treesInColumn - 1
  122. counter = 0
  123. blocksToReset = 18
  124.  
  125. while run == true do
  126.     counter = 0
  127.     counter2 = 0
  128.  
  129.     for i = 1,numOfColumns do
  130.         cutColumn()
  131.         counter2 = counter2 + 1
  132.  
  133.         if counter2 < numOfColumns then
  134.             moveRows()
  135.         else
  136.             print("reset")
  137.             turtle.turnRight()
  138.             for i = 1,blocksToReset do
  139.                 turtle.forward()
  140.             end
  141.            
  142.             turtle.down()
  143.             turtle.down()
  144.             turtle.select(1)
  145.             for i = 1,16 do
  146.                 turtle.suckDown()
  147.             end
  148.            
  149.             turtle.up()
  150.             turtle.up()
  151.            
  152.             for num = 2,16 do
  153.                 turtle.select(num)
  154.                 turtle.drop()
  155.             end
  156.  
  157.             turtle.turnRight()
  158.             faceInit = true
  159.            
  160.         end
  161.     end
  162.     sleep(600)
  163.    -- run = false
  164. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement