Advertisement
HarvDad

logger

Mar 17th, 2014
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.38 KB | None | 0 0
  1. -- logger
  2. -- Grows a tree, cuts it down.
  3. -- Stores the logs in a chest
  4. -- Written by HarvDad, March 2014
  5.  
  6. args = {...}
  7. nArgs = #args
  8. version = "logger: Rev 2.1"
  9.  
  10. saplingsSlot = 1
  11. sampleSlot = 16 -- This slot must have at least 1 sample of the correct log type
  12. bonemealSlot = 2
  13. y = 0
  14.  
  15. if nArgs == 1 and args[1] == "help" then
  16. print(version)
  17. print("No arguments required")
  18. print("Place sapling supply in slot ", saplingsSlot)
  19. print("Place log sample in slot ", sampleSlot)
  20. print("Needs to be part of special tree farm")
  21. end
  22.  
  23. function whackLeaves()
  24. turtle.dig()
  25. turtle.turnRight()
  26. turtle.dig()
  27. turtle.turnRight()
  28. turtle.dig()
  29. turtle.turnRight()
  30. turtle.dig()
  31. turtle.turnRight()
  32. end
  33.  
  34. function focusSaplings()
  35. local i
  36. saplingCount = turtle.getItemCount(saplingsSlot)
  37.  
  38. if saplingCount < 64 then
  39. -- print("Organizing saplings into slot ", saplingsSlot)
  40. for i=2,15 do
  41. turtle.select(i)
  42. if turtle.compareTo(saplingsSlot) then
  43. turtle.transferTo(saplingsSlot, 64-saplingCount)
  44. print("Transferred ", 64 - saplingCount, " saplings to slot ", saplingsSlot)
  45. saplingCount = turtle.getItemCount(saplingsSlot)
  46. if saplingCount >= 64 then
  47. turtle.select(saplingsSlot)
  48. break
  49. end
  50. end
  51. end
  52. end
  53.  
  54. sampleCount = turtle.getItemCount(sampleSlot)
  55. if sampleCount > 1 then
  56. turtle.select(sampleSlot)
  57. turtle.dropDown(sampleCount - 1)
  58. end
  59. turtle.select(saplingsSlot)
  60. end
  61.  
  62. function setFace(f)
  63. if f == 0 then
  64. if face == 0 then return end
  65. if face == 1 then right() return end
  66. if face == 2 then right() right() return end
  67. if face == 3 then left() return end
  68. end
  69.  
  70. if f == 1 then
  71. if face == 0 then left() return end
  72. if face == 1 then return end
  73. if face == 2 then right() return end
  74. if face == 3 then right() right() return end
  75. end
  76.  
  77. if f == 2 then
  78. if face == 0 then left() left() return end
  79. if face == 1 then left() return end
  80. if face == 2 then return end
  81. if face == 3 then right() return end
  82. end
  83.  
  84. if f == 3 then
  85. if face == 0 then right() return end
  86. if face == 1 then left() left() return end
  87. if face == 2 then left() return end
  88. if face == 3 then return end
  89. end
  90. end
  91.  
  92. function suckSaplings()
  93. for i=1,4 do
  94. turtle.suck()
  95. turtle.suckUp()
  96. turtle.turnRight()
  97. end
  98. setFace(0)
  99. end
  100.  
  101. function dump()
  102. for i=3,15 do
  103. if turtle.getItemCount(i) > 0 then
  104. turtle.select(i)
  105. turtle.dropDown()
  106. end
  107. end
  108. sampleCount = turtle.getItemCount(sampleSlot)
  109. if sampleCount > 1 then
  110. turtle.select(sampleSlot)
  111. turtle.dropDown(sampleCount - 1)
  112. end
  113. turtle.select(saplingsSlot)
  114. end
  115.  
  116. function tryBonemeal()
  117. if turtle.getItemCount(bonemealSlot) > 1 then
  118. turtle.select(bonemealSlot)
  119. turtle.place()
  120. end
  121. end
  122.  
  123. intervalLength = 30
  124. interval = 0
  125. print("Logging is enabled")
  126.  
  127. while true do
  128. turtle.select(saplingsSlot)
  129. turtle.place()
  130. tryBonemeal()
  131.  
  132. turtle.select(sampleSlot)
  133. repeat
  134. sleep(2)
  135. if interval > intervalLength then
  136. focusSaplings()
  137. interval = 0
  138. else
  139. interval = interval + 1
  140. end
  141. tryBonemeal()
  142. turtle.select(sampleSlot)
  143. until turtle.compare()
  144.  
  145. turtle.dig()
  146. turtle.forward()
  147.  
  148. turtle.select(2)
  149. while turtle.detectUp() do
  150. turtle.digUp()
  151. turtle.up()
  152. end
  153.  
  154. while not turtle.detectDown() do
  155. turtle.suckDown()
  156. turtle.down()
  157. end
  158.  
  159. suckSaplings()
  160. turtle.back()
  161. suckSaplings()
  162. dump()
  163. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement