Advertisement
Paxon57

Untitled

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