Advertisement
xmarks

FTB Harvest V 3.0

Apr 14th, 2019
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 4.31 KB | None | 0 0
  1. -- FTB LumberJack - V 3.0
  2. -- Made by Xmarks
  3. -- https://www.youtube.com/channel/UCA6oAnFqdDcc0sa6H8G5DSA
  4. -- Program cuts down a 1x1 Tree and replants
  5. -- Best Performed with a Fir Tree
  6. -- Drops items in slots 2-to-14 after process is finished
  7. -- Waits for Tree to regrow or uses BoneMeal of available - BoneMeal TODO
  8. -- Ensures Program won't start unless enough Fuel for 1 cycle
  9. -- Ensures Operation can't be blocked
  10. -- ***************************************
  11. -- * Wood-Drop Chest behind Turtle       *
  12. -- * Fuel-Stock Chest left of Turtle     *
  13. -- * Sapling-Stock Chest right of Turtle *
  14. -- * BoneMeal-Stock Chest below Turtle   *
  15. -- ***************************************
  16. -- * Slot  1: Fuel                       *
  17. -- * Stot 15: Wood Block - Comparison    *
  18. -- * Stot 16: Tree-Sapling - Replant     *
  19. -- ***************************************
  20.  
  21. -- Global Assumed Tree height - Change for taller Trees
  22. -- * Adapts to Taller Trees after first Run
  23. assumed_height = 50;
  24.  
  25. -- Do not Change - Stores height of tree after each itteration
  26. next_assumed_height = 0
  27.  
  28. -- Check Fuel Level - Refuel if necessary
  29. -- Assumes Tree Height - Does not start if not enough Fuel
  30. local function checkFuel()
  31.     while turtle.getFuelLevel() < (40 + 2 * assumed_height) do
  32.  
  33.         -- If not enough fuel available, wait for more fuel
  34.         if turtle.getItemCount(1) == 0 then
  35.             print('More Fuel requird on Slot 1 - sleeping for 10s')
  36.             os.sleep(10)
  37.         else
  38.             turtle.select(1)
  39.             turtle.refuel(1)
  40.         end
  41.     end
  42. end
  43.  
  44. -- Ensures Turtle Moves Forward 1 Block
  45. local function goForward()
  46.     local counter = 0
  47.    
  48.     while counter < 1 do
  49.         if turtle.forward() then
  50.             counter = counter + 1
  51.         -- if can not move, try digging and attacking
  52.         else
  53.             turtle.dig()
  54.             turtle.attack()
  55.         end
  56.     end
  57.    
  58.     return true
  59. end
  60.  
  61. -- Ensures Turtle Moves 1 Block Upwards
  62. local function goUp()
  63.     local counter = 0
  64.    
  65.     while counter < 1 do
  66.         if turtle.up() then
  67.             counter = counter + 1
  68.         -- if can not move, try digging and attacking
  69.         else
  70.             turtle.digUp()
  71.             turtle.attackUp()
  72.         end
  73.     end
  74.    
  75.     return true
  76. end
  77.  
  78. -- Ensures Turtle Moves 1 Block Downwards
  79. local function goDown()
  80.     local counter = 0
  81.    
  82.     while counter < 1 do
  83.         if turtle.down() then
  84.             counter = counter + 1
  85.         -- if can not move, try digging and attacking
  86.         else
  87.             turtle.digDown()
  88.             turtle.attackDown()
  89.         end
  90.     end
  91.    
  92.     return true
  93. end
  94.  
  95. -- Will place down Block from given Slot without fail
  96. -- * Expects Block Slot as argument
  97. local function placeBlock(block_slot)
  98.     local starting_stack = turtle.getItemCount(block_slot)
  99.     local counter = 0
  100.    
  101.     while counter < 1 do
  102.         turtle.place()
  103.        
  104.         -- if it could not place the Block - Clear Obstructions
  105.         if starting_stack == turtle.getItemCount(block_slot) then
  106.             turtle.dig()
  107.             turtle.attack()
  108.         else
  109.             counter = counter + 1
  110.         end
  111.     end
  112.    
  113.     return true
  114. end
  115.  
  116. -- Tree Fell Function
  117. local function fellTree()
  118.     turtle.dig()
  119.     goForward()
  120.    
  121.     print('digging upwards until no more blocks are detected')
  122.    
  123.     -- will store height of tree as turtle digs up
  124.     local tree_height = 0;
  125.    
  126.     -- turtle will dig the first half of the 2x2 tree
  127.     while turtle.detectUp() do
  128.         turtle.dig()
  129.         turtle.digUp()
  130.         if goUp() then
  131.             tree_height = tree_height + 1
  132.         end
  133.     end
  134.    
  135.     -- Next time - fuel assumptions will be more correct
  136.     next_assumed_height = tree_height
  137.    
  138.     print('Dug up to a Height of ' .. tree_height)
  139.  
  140.  
  141.     print('Going down for ' .. tree_height .. 'blocks')
  142.    
  143.     -- turtle will now go down for the same height
  144.     for i = 0,(tree_height - 1) do
  145.         goDown()
  146.     end
  147.    
  148.     print('Finished felling the Tree')
  149. end
  150.  
  151. -- Function clears inventory
  152. local function dropLoot()
  153.     print('Dropping all blocks in slots 2-to-14 into the chest')
  154.     for slot = 2,14 do
  155.         turtle.select(slot)
  156.         turtle.drop()
  157.     end
  158.    
  159.     return
  160. end
  161.  
  162. -- Function Replants a 2x2 area with provided seeds
  163. local function replant()
  164.     turtle.select(16)
  165.     if placeBlock(16) then
  166.         print('Seed planted - Waiting for tree to grow')
  167.     end
  168.    
  169.     return
  170. end
  171.  
  172. -- Main Code that runs the program
  173. while true do
  174.     -- wood slot for compare
  175.     turtle.select(15)
  176.    
  177.     -- If true - the tree has grown
  178.     if turtle.compare() then
  179.         checkFuel()
  180.         fellTree()
  181.         turtle.turnLeft()
  182.         turtle.turnLeft()
  183.         goForward()
  184.         dropLoot()
  185.         turtle.turnLeft()
  186.         turtle.turnLeft()
  187.         replant()
  188.     else
  189.         turtle.suck()
  190.     end
  191. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement