Advertisement
Paxon57

Untitled

Jun 19th, 2019
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. args = {...}
  2.  
  3. -- Init variables
  4. local pos = {
  5. x = 0,
  6. y = 0,
  7. z = 0,
  8. f = 0
  9. }
  10.  
  11. local xSize = args[1]
  12. local ySize = args[2]
  13.  
  14. -- Functions
  15. local function moveForward()
  16. while turtle.detect() do turtle.dig() end
  17. turtle.forward()
  18. turtle.suck()
  19.  
  20. if pos.f == 0 then pos.x = pos.x + 1 end
  21. if pos.f == 2 then pos.x = pos.x - 1 end
  22. if pos.f == 1 then pos.y = pos.y + 1 end
  23. if pos.f == 3 then pos.y = pos.y - 1 end
  24. end
  25.  
  26. local function moveUp()
  27. while turtle.detectUp() do turtle.digUp() end
  28. turtle.up()
  29. pos.z = pos.z + 1
  30. end
  31.  
  32. local function moveDown()
  33. while turtle.detectDown() do turtle.digDown() end
  34. turtle.down()
  35. pos.z = pos.z - 1
  36. end
  37.  
  38. local function turnLeft()
  39. turtle.turnLeft()
  40. pos.f = (pos.f - 1) % 4
  41. end
  42.  
  43. local function turnRight()
  44. turtle.turnRight()
  45. pos.f = (pos.f + 1) % 4
  46. end
  47.  
  48. local function refuel()
  49. if turtle.getFuelLevel() > turtle.getFuelLimit() * 0.01 then return end
  50. turtle.select(16)
  51. while turtle.refuel(0) and turtle.getFuelLevel() < turtle.getFuelLimit() * 0.01 do
  52. turtle.refuel(1)
  53. end
  54. turtle.select(1)
  55. end
  56.  
  57. local function isItem(itemName, name)
  58. if string.find(itemName, name) then
  59. return true
  60. else
  61. return false
  62. end
  63. end
  64.  
  65. local function goAround()
  66. turnRight()
  67. moveForward()
  68. turnLeft()
  69. moveForward()
  70. moveForward()
  71. turnLeft()
  72. moveForward()
  73. turnRight()
  74. end
  75.  
  76. local function chopTheTree()
  77. moveUp()
  78. moveUp()
  79. while turtle.detectUp() do
  80. moveUp()
  81. end
  82. moveForward()
  83. for i = 1, math.abs(pos.z) do
  84. for i = 1, 4 do
  85. turtle.dig()
  86. turnRight()
  87. end
  88. moveDown()
  89. end
  90. moveForward()
  91. turnRight()
  92. turnRight()
  93. turtle.select(15)
  94. turtle.place()
  95. turnLeft()
  96. turnLeft()
  97. end
  98.  
  99. -- Main Code
  100. print("Insert saplings into slot 15")
  101. turtle.select(15)
  102. while turtle.getItemDetail() == nil do end
  103. while not isItem(turtle.getItemDetail().name, "sapling") do end
  104. print("Saplings detected")
  105. print("Please insert fuel into slot 16 (not wood)")
  106. turtle.select(16)
  107. while not turtle.refuel(0) do end
  108. print("Fuel detected, beginning the work")
  109. turtle.select(15)
  110.  
  111. -- Main Loop
  112. while true do
  113. refuel()
  114. if turtle.getFuelLevel() > 20 then
  115.  
  116. moveForward()
  117.  
  118. if pos.f == 0 and pos.x >= (3 * xSize) then
  119. if pos.y == (3 * (ySize - 1)) then
  120. turnLeft()
  121. moveForward()
  122. turnLeft()
  123. for i = 1, pos.x do
  124. moveForward()
  125. end
  126. turnRight()
  127. for i = 1, pos.y do
  128. moveForward()
  129. end
  130. turnLeft()
  131. for i = 1, 14 do
  132. turtle.select(i)
  133. turtle.drop()
  134. end
  135. turtle.select(15)
  136. turnRight()
  137. turnRight()
  138. else
  139. turnRight()
  140. for i = 1, 3 do
  141. moveForward()
  142. end
  143. turnRight()
  144. end
  145. elseif pos.f == 2 and pos.x == 0 then
  146. if pos.y == (3 * (ySize - 1)) then
  147. turnRight()
  148. for i = 1, pos.y do
  149. moveForward()
  150. end
  151. turnLeft()
  152. for i = 1, 14 do
  153. turtle.select(i)
  154. turtle.drop()
  155. end
  156. turtle.select(15)
  157. turnRight()
  158. turnRight()
  159. else
  160. turnLeft()
  161. for i = 1, 3 do
  162. moveForward()
  163. end
  164. turnLeft()
  165. end
  166. end
  167.  
  168. local b, data = turtle.inspect()
  169. if b ~= false then
  170. if isItem(data.name, "sapling") then
  171. goAround()
  172. elseif isItem(data.name, "log") then
  173. chopTheTree()
  174. end
  175. end
  176. else
  177. print("Waiting for fuel in slot 16")
  178. end
  179. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement