Advertisement
Efud933

TreeFarm1.4

Jan 4th, 2022
854
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.46 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 = 3 -- UPDATE ME TO FIT SIZE OF TREE FARM
  120. numOfColumns = 3 -- UPDATE ME TO FIT SIZE OF TREE FARM
  121. timesToMove = treesInColumn - 1
  122. counter = 0
  123.  
  124. while run == true do
  125.     counter = 0
  126.     counter2 = 0
  127.  
  128.     for i = 1,numOfColumns do
  129.         cutColumn()
  130.         counter2 = counter2 + 1
  131.  
  132.         if counter2 < numOfColumns then
  133.             moveRows()
  134.         else
  135.             print("reset")
  136.         end
  137.     end
  138.    -- run = false
  139. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement