Advertisement
mitgobla

giantTreeFarm

Apr 10th, 2021 (edited)
1,157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 3.79 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(1, 1)
  3.  
  4. local fuel_requirement = 120
  5. local current_direction = 0
  6.  
  7. local function checkFuel()
  8.     if turtle.getItemCount(1) <= 1 then
  9.         if turtle.getFuelLevel() < fuel_requirement then
  10.             print("Fuel is urgently required in slot 1.")
  11.         elseif turtle.getFuelLevel() < (fuel_requirement * 2) then
  12.             print("Fuel is required soon in slot 1.")
  13.         end
  14.     end
  15.     repeat
  16.         if (turtle.getItemCount(1) > 1) then
  17.             turtle.select(1)
  18.             turtle.refuel(1)
  19.         end
  20.         sleep(0.5)
  21.     until turtle.getFuelLevel() >= fuel_requirement
  22. end
  23.  
  24. local function turnToFace(direction)
  25.     if direction == 0 then
  26.         if current_direction == 1 then
  27.             turtle.turnLeft()
  28.         elseif current_direction == 2 then
  29.             turtle.turnLeft()
  30.             turtle.turnLeft()
  31.         elseif current_direction == 3 then
  32.             turtle.turnRight()
  33.         end
  34.         current_direction = 0
  35.  
  36.     elseif direction == 1 then
  37.         if current_direction == 2 then
  38.             turtle.turnLeft()
  39.         elseif current_direction == 3 then
  40.             turtle.turnLeft()
  41.             turtle.turnLeft()
  42.         elseif current_direction == 0 then
  43.             turtle.turnRight()
  44.         end
  45.         current_direction = 1
  46.  
  47.     elseif direction == 2 then
  48.         if current_direction == 3 then
  49.             turtle.turnLeft()
  50.         elseif current_direction == 0 then
  51.             turtle.turnLeft()
  52.             turtle.turnLeft()
  53.         elseif current_direction == 1 then
  54.             turtle.turnRight()
  55.         end
  56.         current_direction = 2
  57.  
  58.     elseif direction == 3 then
  59.         if current_direction == 0 then
  60.             turtle.turnLeft()
  61.         elseif current_direction == 1 then
  62.             turtle.turnLeft()
  63.             turtle.turnLeft()
  64.         elseif current_direction == 2 then
  65.             turtle.turnRight()
  66.         end
  67.         current_direction = 3
  68.  
  69.     end
  70. end
  71.  
  72. local function waitForLog()
  73.     success, data = turtle.inspect()
  74.     print("Waiting for tree...")
  75.     repeat
  76.         sleep(1)
  77.         success, data = turtle.inspect()
  78.     until (data.name == "minecraft:spruce_log")
  79.     print("Chopping tree...")
  80. end
  81.  
  82. local function supplySaplings()
  83.     -- get saplings from chest
  84.     if turtle.getItemCount(2) < 4 then
  85.         turnToFace(1)
  86.         turtle.select(2)
  87.         while turtle.getItemCount(2) < 4 do
  88.             turtle.suck(1)
  89.             sleep(1)
  90.         end
  91.         turtle.select(1)
  92.         turnToFace(0)
  93.     end
  94. end
  95.  
  96.  
  97.  
  98. local function giantSpruce()
  99.     turtle.select(1)
  100.     checkFuel()
  101.     supplySaplings()
  102.     waitForLog()
  103.     turtle.dig()
  104.     turtle.forward()
  105.     local success, data = turtle.inspectUp()
  106.     while (success) do
  107.         turtle.dig() -- dig in front
  108.         turnToFace(1) -- turn right
  109.         turtle.dig() -- dig in front (the right)
  110.         turnToFace(0) -- turn left
  111.         turtle.digUp()
  112.         turtle.up()
  113.         success, data = turtle.inspectUp()
  114.     end
  115.     turtle.dig()
  116.     turtle.forward()
  117.     turnToFace(1)
  118.     success, data = turtle.inspectDown()
  119.     while (not success) do
  120.         turtle.dig()
  121.         turtle.down()
  122.         success, data = turtle.inspectDown()
  123.     end
  124.     turtle.dig()
  125.     -- place down saplings
  126.     turtle.select(2)
  127.     turtle.up()
  128.     turtle.placeDown()
  129.     turtle.forward()
  130.     turtle.placeDown()
  131.     turnToFace(2)
  132.     turtle.forward()
  133.     turtle.placeDown()
  134.     turnToFace(3)
  135.     turtle.forward()
  136.     turtle.placeDown()
  137.     turnToFace(2)
  138.     turtle.dig()
  139.     turtle.forward()
  140.     turtle.down()
  141.     -- empty inventory
  142.     for i = 3, 16, 1 do
  143.         turtle.select(i)
  144.         turtle.drop()
  145.     end
  146.  
  147.     turnToFace(0)
  148. end
  149.  
  150. local running = true
  151. while running do
  152.     giantSpruce()
  153. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement