Advertisement
Paxon57

Untitled

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