SHARE
TWEET

tree

a guest Mar 26th, 2020 68 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. local tArgs = {...}
  2. amountOfTreesFelled = tArgs
  3.  
  4. totalBoneMealUsed = 0
  5. totalBoneMealSucked = 0
  6. totalSaplingsSucked = 0
  7. totalWoodCollected = 0
  8.  
  9. function refuel()
  10.   if turtle.getFuelLevel() < 200 then
  11.     turtle.select(15)
  12.     turtle.refuel(1)
  13.     print("Refueled. Fuel lvl: "..turtle.getFuelLevel()..".")
  14.   end
  15. end
  16.  
  17. function checkSapling()
  18.   if turtle.getItemCount(14) < 4 then
  19.     saplingSpace = turtle.getItemSpace(14)
  20.     refillSapling(turtle.getItemSpace(14))
  21.     print(saplingSpace.." saplings sucked from chest.")
  22.   end
  23. end
  24.  
  25. function checkBoneMeal()
  26.   if turtle.getItemCount(16) == 0 then
  27.     refillBoneMeal()
  28.     print("64 bone meal sucked from chest.")
  29.   end
  30. end  
  31.  
  32. function refillSapling(saplings)
  33.   turtle.turnLeft()
  34.   turtle.select(14)
  35.   turtle.suck(saplings)
  36.   turtle.turnRight()
  37.   totalSaplingsSucked = totalSaplingsSucked + saplings
  38. end
  39.  
  40. function refillBoneMeal()
  41.   turtle.select(16)
  42.   turtle.suckDown(64)
  43.   totalBoneMealSucked = totalBoneMealSucked + 64
  44. end
  45.  
  46. function checkCoal()
  47.   if turtle.getItemSpace(15) ~= 0 then
  48.     refillCoal(turtle.getItemSpace(15))
  49.   end
  50. end
  51.  
  52. function refillCoal(coalSpace)
  53.   turtle.turnRight()
  54.   turtle.select(15)
  55.   turtle.suck(coalSpace)
  56.   turtle.turnLeft()
  57.   print(coalSpace.." coal sucked from chest.")
  58. end    
  59.  
  60. function moveForward()
  61.   while turtle.forward() == false do
  62.     turtle.dig()
  63.     turtle.attack()
  64.   end
  65. end
  66.  
  67. function sapling()
  68.   checkSapling()
  69.   turtle.digUp()
  70.   turtle.up()
  71.   moveForward()
  72.   turtle.select(14)
  73.   turtle.placeDown()
  74.   moveForward()
  75.   turtle.placeDown()
  76.   turtle.turnRight()
  77.   moveForward()
  78.   turtle.turnRight()
  79.   turtle.placeDown()
  80.   moveForward()
  81.   turtle.placeDown()
  82.   moveForward()
  83.   turtle.turnRight()
  84.   moveForward()
  85.   turtle.turnRight()
  86.   turtle.digDown()
  87.   turtle.down()
  88. end
  89.  
  90. function detectTree()
  91.   turtle.up()
  92.   if turtle.detect() == true then
  93.     turtle.down()
  94.     return true
  95.   else
  96.     turtle.down()
  97.     return false
  98.   end
  99. end
  100.  
  101. function placeBoneMeal()
  102.   checkBoneMeal()
  103.   turtle.select(16)
  104.   turtle.place()
  105.   boneMealUsed = 1
  106.   totalBoneMealUsed = totalBoneMealUsed + 1
  107.   while detectTree() == false do
  108.     checkBoneMeal()
  109.     turtle.place()
  110.     boneMealUsed = boneMealUsed + 1
  111.     totalBoneMealUsed = totalBoneMealUsed + 1
  112.   end
  113.   print(boneMealUsed.." bone meal used.")  
  114. end
  115.  
  116. function storeWood()
  117.   woodCollected = 0
  118.   for i = 1,8 do
  119.     turtle.select(i)
  120.     if turtle.getItemCount() > 0 then
  121.       itemType = turtle.getItemDetail(i)
  122.       if itemType.name == "minecraft:log" then
  123.         woodCollected = woodCollected + turtle.getItemCount(i)
  124.         totalWoodCollected = totalWoodCollected + turtle.getItemCount(i)
  125.       end  
  126.     end
  127.     turtle.drop()
  128.   end
  129.   turtle.turnLeft()
  130.   turtle.turnLeft()
  131.   turtle.select(1)
  132.   print("Tree felled successfully! "..woodCollected.." wood collected.")
  133. end
  134.  
  135. function fell()
  136.   turtle.select(1)
  137.   turtle.dig()
  138.   turtle.forward()
  139.   turtle.dig()
  140.   treeHeight = 1
  141.   while turtle.digUp() == true do
  142.     refuel()
  143.     turtle.up()
  144.     turtle.dig()
  145.     treeHeight = treeHeight + 1
  146.   end
  147.   turtle.up()
  148.   turtle.turnRight()
  149.   turtle.forward()
  150.   turtle.turnLeft()
  151.   for i = 1,treeHeight do
  152.     refuel()
  153.     turtle.digDown()
  154.     turtle.down()
  155.     turtle.dig()
  156.   end
  157.   turtle.turnRight()
  158.   turtle.back()
  159.   turtle.turnRight()
  160.   turtle.forward()    
  161. end  
  162.  
  163. function displayInformation(numberOfTrees)
  164.   numberOfSaplings = numberOfTrees * 4
  165.   if numberOfSaplings / 4 < 2 then
  166.     print("1 tree successfully felled!")
  167.   else
  168.     print(numberOfTrees.." trees successfully felled!")
  169.   end
  170.   print(" ")
  171.   print("INFORMATION")
  172.   print("Total wood collected: "..totalWoodCollected..".")
  173.   print("Total saplings used: "..numberOfSaplings..".")
  174.   print("Total saplings sucked: "..totalSaplingsSucked..".")
  175.   print("Total bone meal used: "..totalBoneMealUsed..".")
  176.   print("Total bone meal sucked: "..totalBoneMealSucked..".")
  177.   print("Average bone meal used per tree: "..totalBoneMealUsed / numberOfTrees..".")
  178. end
  179.  
  180. if #amountOfTreesFelled == 0 then
  181.   print("Please specify how many trees you want felled.")
  182. else
  183.   for i = 1,amountOfTreesFelled[1] do
  184.     checkCoal()
  185.     refuel()
  186.     sapling()
  187.     placeBoneMeal()
  188.     print("Felling tree "..i.." of "..amountOfTreesFelled[1]..".")
  189.     fell()
  190.     storeWood()
  191.    end
  192.   displayInformation(amountOfTreesFelled[1])
  193. end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top