Advertisement
LK005

Spruce Feller

Jun 8th, 2022 (edited)
760
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.18 KB | None | 0 0
  1. local YPos = 0
  2.  
  3. function refuel()
  4.     print( "Refueling..." )
  5.  
  6.   turnAround()
  7.     turtle.select(1)
  8.     turtle.suck(64)
  9.     turtle.refuel(64)
  10.   turnAround()
  11. end
  12.  
  13. function getSapplings()
  14.     print( "Getting sapplings..." )
  15.  
  16.     turtle.select(2)
  17.     turtle.suckDown(4)
  18. end
  19.  
  20. function turnAround()
  21.     turn( "r" )
  22.     turn( "r" )
  23. end
  24.  
  25. function turn( direction )
  26.     if direction == "r" then
  27.         turtle.turnRight()
  28.  
  29.         return true
  30.     elseif direction == "l" then
  31.         turtle.turnLeft()
  32.  
  33.         return true
  34.     else
  35.         return false
  36.     end
  37. end
  38.  
  39. function dump()
  40.   turn("r")
  41.   for n=3,16 do
  42.         local itemCount = turtle.getItemCount(n)
  43.         if itemCount > 0 then
  44.             turtle.select(n)
  45.             turtle.drop(64)
  46.         end
  47.     end
  48.   turn("l")
  49. end
  50.  
  51. function plantSapplings()
  52.   turtle.select(2)
  53.   turtle.forward()
  54.   turtle.forward()
  55.   turn("l")
  56.   turtle.place()
  57.   turn("r")
  58.   turtle.back()
  59.   turtle.place()
  60.   turn("l")
  61.   turtle.place()
  62.   turn("r")
  63.   turtle.back()
  64.   turtle.place()
  65. end
  66.  
  67. function compareLoop()
  68.   local tree = false
  69.   while tree == false do
  70.     if not turtle.compare() then
  71.       tree = true
  72.     end
  73.     sleep(5)
  74.   end
  75. end
  76.  
  77. function mainLoop()
  78.   while true do
  79.     compareLoop()
  80.     local topFound = false
  81.  
  82.     if turtle.getFuelLevel() < 1000 then
  83.       refuel()
  84.     end
  85.     getSapplings()
  86.     turtle.dig()
  87.     turtle.forward()
  88.  
  89.     while topFound == false do
  90.       if YPos > 200 then
  91.         turtle.dig()
  92.         turtle.up()
  93.         turtle.dig()
  94.         YPos = YPos + 1
  95.         topFound = true
  96.         print("Reached max height...")
  97.       elseif turtle.up() then
  98.         turtle.dig()
  99.         YPos = YPos + 1
  100.         topFound = true
  101.         print("Top found...")
  102.       else
  103.         turtle.dig()
  104.         turtle.digUp()
  105.         turtle.up()
  106.         turtle.dig()
  107.         YPos = YPos + 1
  108.         print("Going up... YPos: "..YPos)
  109.       end
  110.     end
  111.  
  112.     turn("l")
  113.     turtle.dig()
  114.     turtle.forward()
  115.     turn("r")
  116.  
  117.     while YPos > 0 do
  118.       turtle.dig()
  119.       turtle.digDown()
  120.       turtle.down()
  121.       YPos = YPos - 1
  122.     end
  123.  
  124.     turtle.dig()
  125.     turn("r")
  126.     turtle.forward()
  127.     turn("l")
  128.     turtle.back()
  129.  
  130.     dump()
  131.     plantSapplings()
  132.   end
  133. end
  134.  
  135. mainLoop()
  136.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement