Larnu

Auto Chop

Sep 10th, 2020 (edited)
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5.94 KB | None | 0 0
  1. function getChops()
  2.     local sucked
  3.     write("Collecting items")
  4.     sucked = turtle.suck()
  5.     while sucked do
  6.         write("Collecting items")
  7.         sucked = turtle.suck()
  8.     end
  9.     write("No more items, moving on.")
  10.     turtle.forward(1)
  11.     sucked = turtle.suck()
  12.     while sucked do
  13.         write("Collecting items")
  14.         sucked = turtle.suck()
  15.     end
  16.     write("No more items, moving on.")
  17.     turtle.turnLeft()
  18.     turtle.forward(1)
  19.     sucked = turtle.suck()
  20.     while sucked do
  21.         write("Collecting items")
  22.         sucked = turtle.suck()
  23.     end
  24.     write("No more items, moving on.")
  25.     turtle.turnLeft()
  26.     turtle.forward(1)
  27.     sucked = turtle.suck()
  28.     while sucked do
  29.         write("Collecting items")
  30.         sucked = turtle.suck()
  31.     end
  32.     write("No more items, moving on.")
  33.     turtle.forward(1)
  34.     sucked = turtle.suck()
  35.     while sucked do
  36.         write("Collecting items")
  37.         sucked = turtle.suck()
  38.     end
  39.     write("No more items, moving on.")
  40.     turtle.turnLeft()
  41.     turtle.forward(1)
  42.     sucked = turtle.suck()
  43.     while sucked do
  44.         write("Collecting items")
  45.         sucked = turtle.suck()
  46.     end
  47.     write("No more items, moving on.")
  48.     turtle.forward(1)
  49.     sucked = turtle.suck()
  50.     while sucked do
  51.         write("Collecting items")
  52.         sucked = turtle.suck()
  53.     end
  54.     write("No more items, moving on.")
  55.     turtle.turnLeft()
  56.     turtle.forward(1)
  57.     sucked = turtle.suck()
  58.     while sucked do
  59.         write("Collecting items")
  60.         sucked = turtle.suck()
  61.     end
  62.     write("No more items, moving on.")
  63.     turtle.forward(1)
  64.     sucked = turtle.suck()
  65.     while sucked do
  66.         write("Collecting items")
  67.         sucked = turtle.suck()
  68.     end
  69.     write("No more items, moving on.")
  70.     turtle.turnLeft()
  71.     turtle.forward(1)
  72.     turtle.turnRight()
  73.  
  74. end
  75.  
  76. function placeBehind()
  77.     turtle.turnLeft()
  78.     turtle.turnLeft()
  79.     turtle.place(1)
  80.     turtle.turnLeft()
  81.     turtle.turnLeft()
  82. end
  83.  
  84. function avoidSapling()
  85.     turtle.turnLeft()
  86.     turtle.forward(1)
  87.     turtle.turnRight()
  88.     turtle.forward(1)
  89.     turtle.forward(1)
  90.     turtle.turnRight()
  91.     turtle.forward(1)
  92.     turtle.turnLeft()
  93. end
  94.  
  95. function hasSapling()
  96.     local item
  97.     local gotSapling
  98.     gotSapling = false
  99.     if turtle.getItemCount(1) > 0 then
  100.         item = turtle.getItemDetail(1)
  101.         if item.name == "minecraft:sapling" then
  102.             gotSapling = true
  103.         end
  104.     end
  105.     return gotSapling
  106. end
  107.  
  108. function placeInChest()
  109.     for i = 2,16 do
  110.         turtle.select(1)
  111.         if turtle.getItemCount(i) > 0 then
  112.             if turtle.compare(i) then
  113.                 write("Transferring saplings to active slot")
  114.                 turtle.transferTo(i)
  115.             else
  116.                 write("Dropping off items")
  117.                 turtle.select(i)
  118.                 turtle.drop()
  119.                 turtle.select(i)
  120.             end
  121.         end
  122.     end
  123. end
  124.  
  125. function getTheFuel()
  126.     local needFuel
  127.     needFuel = True
  128.     for i = 2,16 do
  129.         turtle.select(1)
  130.         if turtle.getItemCount(i) > 0 and needFuel then
  131.             item = turtle.getItemDetail(i)
  132.             write("Found ")
  133.             write(item.name)
  134.             if item.name == "minecraft:log" then
  135.                 write("Logs found, refueling")
  136.                 turtle.select(i)
  137.                 turtle.refuel()
  138.                 turtle.select(i)
  139.                 needFuel = False
  140.             end
  141.         end
  142.     end
  143. end
  144.  
  145.  
  146. local infront
  147. local block
  148.  
  149. local h
  150. local v
  151. local plant
  152. local sucked
  153. h = 1
  154. v = 1
  155.  
  156. f = "right"
  157.  
  158. if turtle.getFuelLevel() < 100 then
  159.     write("low on fuel, refueling")
  160.     getTheFuel()
  161. end
  162.  
  163. while hasSapling() and turtle.getFuelLevel() > 10 do
  164.     if turtle.getFuelLevel() < 100 then
  165.         write("low on fuel, refueling")
  166.         getTheFuel()
  167.     end
  168.     turtle.select(1)
  169.     while h <= 16 and hasSapling() do
  170.         while v <= 24 and hasSapling() do
  171.             infront, block = turtle.inspect()
  172.             if infront then
  173.                 if block.name == "minecraft:sapling" then
  174.                     write("Avoiding Sapling")
  175.                     avoidSapling()
  176.                     v = v + 2
  177.                 else
  178.                     if block.name == "minecraft:log" then
  179.                         write("Chopping Tree")
  180.                         turtle.dig()
  181.                         turtle.forward(1)
  182.                         getChops()
  183.                         v = v + 2
  184.                         placeBehind()
  185.                     else
  186.                         write("Weed in way. Killing.")
  187.                         turtle.dig()
  188.                         turtle.forward(1)
  189.                         v = v + 1
  190.                     end
  191.                 end
  192.             else
  193.                 write("No tree, moving forward")
  194.                 turtle.forward(1)
  195.                 v = v + 1
  196.                 write("Checking for items")
  197.                 sucked = turtle.suck()
  198.                 while sucked do
  199.                     write("Collecting items")
  200.                     sucked = turtle.suck()
  201.                 end
  202.             end
  203.         end
  204.         if f == "right" then
  205.             write("End of Row, proceeding to next row.")
  206.             turtle.turnRight()
  207.             turtle.forward(1)
  208.             h = h + 1
  209.             turtle.turnRight()
  210.             f = "left"
  211.             v = 1
  212.         else
  213.             write("End of Row, proceeding to next row.")
  214.             turtle.turnLeft()
  215.             turtle.forward(1)
  216.             h = h + 1
  217.             turtle.turnLeft()
  218.             f = "right"
  219.             v = 1
  220.         end
  221.     end
  222.     write("End of Cycle, going back to start.")
  223.     turtle.turnLeft()
  224.     write(h)
  225.     while h > 1 do
  226.         turtle.forward(1)
  227.         h = h - 1
  228.         write("Moving back")
  229.         write(h)
  230.     end
  231.     placeInChest()
  232.     turtle.turnRight()
  233. end
  234.  
  235. write("No more saplings. Stopping auto chopping")
  236.  
Add Comment
Please, Sign In to add comment