Advertisement
ladyDia

Smart Land Clearence

Dec 25th, 2020 (edited)
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.88 KB | None | 0 0
  1. local landArea = {}
  2. local a = {}
  3. local args = {...}
  4.  
  5. local xScan = tonumber(args[1])
  6. local zScan = tonumber(args[2])
  7.  
  8. local xPos = 0
  9. local yPos = 0
  10. local zPos = 0
  11. local rotation = 0
  12.  
  13. local xDiff = 0
  14. local yDiff = 0
  15. local zDiff = 0
  16. local rotDiff = 0
  17.  
  18. local allToZero = false
  19. local allToZeroCheck = false
  20. local backTo = false
  21.  
  22. function a.goToPlace(x,y,z,rot)
  23. xDiff = xPos-x
  24. yDiff = yPos-y
  25. zDiff = zPos-z
  26. rotDiff = rotation-rot
  27. while rotDiff ~= 0 do
  28. if rotDiff<0 then
  29. turtle.turnLeft()
  30. rotDiff = rotDiff+90
  31. rotation = rotation+90
  32. end
  33. if rotDiff>0 then
  34. turtle.turnRight()
  35. rotDiff = rotDiff-90
  36. rotation = rotation-90
  37. end
  38. end
  39. turtle.turnLeft()
  40. while xDiff ~= 0 do
  41. if(turtle.detect()) then
  42. while(turtle.detect()) do
  43. turtle.digUp()
  44. turtle.up()
  45. yPos = yPos+1
  46. yDiff = yDiff+1
  47. end
  48. end
  49. if xDiff<0 then
  50. turtle.dig()
  51. turtle.forward()
  52. xDiff = xDiff+1
  53. xPos = xPos+1
  54. end
  55. if xDiff > 0 then
  56. turtle.back()
  57. xDiff = xDiff-1
  58. xPos = xPos-1
  59. end
  60. end
  61. turtle.turnRight()
  62. backTo = false
  63. if(zDiff>0)then turtle.turnRight() turtle.turnRight() backTo = true end
  64. while zDiff ~= 0 do
  65. if zDiff<0 then
  66. a.checkForStuff()
  67. turtle.forward()
  68. turtle.digDown()
  69. zDiff = zDiff+1
  70. zPos = zPos+1
  71. end
  72. if zDiff>0 then
  73. a.checkForStuff()
  74. turtle.forward()
  75. turtle.digDown()
  76. zDiff = zDiff-1
  77. zPos = zPos-1
  78. end
  79. end
  80. if(backTo == true)then turtle.turnRight() turtle.turnRight() end
  81. while yDiff ~= 0 do
  82. if yDiff<0 then
  83. if(turtle.detectUp())then
  84. turtle.digUp()
  85. end
  86. turtle.up()
  87. yDiff = yDiff+1
  88. yPos = yPos+1
  89. end
  90. if yDiff>0 then
  91. if(yPos>0)then
  92. turtle.digDown()
  93. end
  94. turtle.down()
  95. yDiff = yDiff-1
  96. yPos = yPos-1
  97. end
  98. end
  99.  
  100. end
  101.  
  102. for i=1,xScan do
  103. landArea[i] = {}
  104. for x=1,zScan do
  105. landArea[i][x]=0
  106. end
  107. end
  108.  
  109. function a.checkForStuff()
  110. if turtle.detect() then
  111. while turtle.detect() do
  112. if(turtle.detectUp()) then
  113. while(turtle.detectUp()) do
  114. turtle.digUp()
  115. end
  116. end
  117. turtle.up()
  118. yPos = yPos+1
  119. yDiff = yDiff+1
  120. end
  121. end
  122. end
  123.  
  124. while(allToZeroCheck == false)do
  125. allToZero=true
  126. while(xPos<xScan) do
  127. while(zPos<zScan) do
  128. a.checkForStuff()
  129. turtle.forward()
  130. zPos = zPos+1
  131. if (turtle.detectDown()==false) and (yPos>0) then
  132. while (turtle.detectDown()==false) and (yPos>0)do
  133. turtle.down()
  134. yPos=yPos-1
  135. end
  136. end
  137. if(yPos >0)then
  138. turtle.digDown()
  139. allToZero = false
  140. end
  141. landArea[xPos+1][zPos+1] = yPos
  142. end
  143. if(xScan~=1)then
  144. a.goToPlace(xPos+1,0,0,0)
  145. else
  146. a.goToPlace(0,0,0,0)
  147. end
  148. end
  149. a.goToPlace(0,0,0,0)
  150. print(allToZero)
  151. allToZeroCheck = allToZero
  152. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement