Advertisement
zaboodable

Tree

Apr 2nd, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 2.23 KB | None | 0 0
  1. -- Variables
  2. local boneCountMin = 32
  3. local saplingCountMin = 5
  4. local boneTries = 32
  5. local boneIndex = 1
  6. local saplingIndex = 2
  7. local storageIndex = 3
  8.  
  9. -- Stats
  10. local treesCut = 0
  11. local saplingsUsed = 0
  12. local bonemealUsed = 0
  13. local logsDeposited = 0
  14. local logsPerTree = 0
  15.  
  16.  
  17.  
  18. print("Place bonemeal in slot " .. boneIndex)
  19. print("Place saplings in slot " .. saplingIndex)
  20. print("slots " .. storageIndex .. ".. 16 are for storage")
  21. print("Press enter to begin")
  22. io.read()
  23. print("Beginning...")
  24.  
  25. -- Functions
  26. function DisplayStats()
  27.   print("")
  28.   print("Logging Stats")
  29.   print("Total Logs: " .. logsDeposited)
  30.   print("Total Trees: " .. treesCut)
  31.   print("avg log/tree: " .. logsPerTree)
  32.   print("Bonemeal Used: " .. bonemealUsed)
  33.   print("Saplings Used: " .. saplingsUsed)  
  34. end
  35.  
  36.  
  37. function Deposit(s, e)
  38.   treesCut = treesCut + 1
  39.   local count = 0
  40.   for i = s, e do
  41.     turtle.select(i)
  42.     count = count + turtle.getItemCount()
  43.     turtle.drop()
  44.   end
  45.   logsDeposited = logsDeposited + count
  46.   logsPerTree = logsDeposited / treesCut
  47.   print("Deposited " .. count .. " logs")
  48. end
  49.  
  50. function Bone(idx)
  51.   turtle.select(idx)
  52.   local bstart = turtle.getItemCount()
  53.   for i = 0, boneTries do
  54.     turtle.place()    
  55.   end
  56.   local bend = turtle.getItemCount()
  57.   bonemealUsed = bonemealUsed + (bstart - bend)
  58. end
  59.  
  60. function Plant(idx)
  61.   turtle.select(idx)
  62.   turtle.place()
  63.   saplingsUsed = saplingsUsed + 1
  64. end
  65.  
  66. function Resupply()
  67.   turtle.turnLeft()
  68.   turtle.select(boneIndex)
  69.   while (turtle.getItemCount() < boneCountMin) do
  70.     turtle.suck(1)
  71.   end
  72.   turtle.turnRight()
  73.   turtle.turnRight()
  74.   turtle.select(saplingIndex)
  75.   while (turtle.getItemCount() < saplingCountMin) do
  76.     turtle.suck()
  77.   end
  78.   turtle.turnLeft()
  79. end
  80.  
  81. -- Main
  82. sleep(1)
  83. while (true) do
  84.   DisplayStats()  
  85.   print("Beginning iteration " .. treesCut)  
  86.   Resupply()
  87.   Plant(saplingIndex)
  88.   Bone(boneIndex)
  89.   turtle.dig()
  90.   turtle.forward()
  91.  
  92.   local h = 0
  93.   while(turtle.detectUp()) do
  94.     turtle.digUp()
  95.     turtle.up()
  96.     h = h + 1
  97.   end
  98.  
  99.   for i = 0, h do
  100.     turtle.down()
  101.   end
  102.   turtle.back()
  103.   turtle.turnRight()
  104.   turtle.turnRight()
  105.   Deposit(storageIndex, 16)
  106.   turtle.turnRight()
  107.   turtle.turnRight()
  108. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement