DrFair

Vanilla strip nofuel chest

Aug 6th, 2013
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.88 KB | None | 0 0
  1. Args = {...}
  2. x,y = 0,0
  3. dir = { [1]="+X", [2]="+Y", [3]="-X", [4]="-Y" }
  4. nDir = 1
  5.  
  6. function printUsage()
  7. print("Usage:")
  8. print("strip <BLOCKS> <WIDE> <left/right>")
  9. print("Strip mines <BLOCKS> blocks infront and <WIDE> blocks to the side.")
  10. end
  11.  
  12. function printFail()
  13. print("Failed at a task.")
  14. end
  15.  
  16. function hasSpace()
  17. local space = false
  18. for i=1,16 do
  19. if turtle.getItemCount(i) == 0 then
  20. space = true
  21. end
  22. end
  23. return space
  24. end
  25.  
  26. function dropOff()
  27. print("Dropping off items.")
  28. oldx = x
  29. oldy = y
  30. oldDir = nDir
  31. goY(0)
  32. goPos(0,0)
  33. for i=1,16 do
  34. turtle.select(i)
  35. turtle.drop()
  36. end
  37. turtle.select(1)
  38. goPos(oldx,oldy)
  39. while oldDir ~= nDir do
  40. turnRight()
  41. end
  42. end
  43.  
  44. function goDirFor(bool)
  45. if bool then
  46. if dir[nDir] == "+X" then x = x + 1 elseif
  47. dir[nDir] == "-X" then x = x - 1 elseif
  48. dir[nDir] == "+Y" then y = y + 1 elseif
  49. dir[nDir] == "-Y" then y = y - 1 end
  50. else
  51. if dir[nDir] == "+X" then x = x - 1 elseif
  52. dir[nDir] == "-X" then x = x + 1 elseif
  53. dir[nDir] == "+Y" then y = y - 1 elseif
  54. dir[nDir] == "-Y" then y = y + 1 end
  55. end
  56. end
  57.  
  58. function mineFor()
  59. while turtle.detect() do
  60. turtle.dig()
  61. os.sleep(0.5)
  62. end
  63. if not hasSpace() then dropOff() end
  64. return true
  65. end
  66.  
  67. function mineUp()
  68. while turtle.detectUp() do
  69. turtle.digUp()
  70. os.sleep(0.5)
  71. end
  72. if not hasSpace() then dropOff() end
  73. return true
  74. end
  75.  
  76. function mineDown()
  77. turtle.digDown()
  78. if not hasSpace() then dropOff() end
  79. return true
  80. end
  81.  
  82. function goFor()
  83. if turtle.forward() then
  84. goDirFor(true)
  85. else
  86. return false
  87. end
  88. end
  89.  
  90. function goBack()
  91. if turtle.back() then
  92. goDirFor(false)
  93. else
  94. return false
  95. end
  96. end
  97.  
  98. function turnRight()
  99. turtle.turnRight()
  100. if nDir < 4 then
  101. nDir = nDir + 1
  102. else
  103. nDir = 1
  104. end
  105. end
  106.  
  107. function turnLeft()
  108. turtle.turnLeft()
  109. if nDir > 1 then
  110. nDir = nDir - 1
  111. else
  112. nDir = 4
  113. end
  114. end
  115.  
  116. function mine()
  117. mineFor()
  118. mineUp()
  119. mineDown()
  120. goFor()
  121. end
  122.  
  123. function stripFor()
  124. if dirFor then
  125. while x < blocksfor do
  126. mineFor()
  127. mineUp()
  128. mineDown()
  129. goFor()
  130. end
  131. else
  132. while x > 0 do
  133. mineFor()
  134. mineUp()
  135. mineDown()
  136. goFor()
  137. end
  138. end
  139. end
  140.  
  141. function goX(dx)
  142. if dx > x then
  143. while dir[nDir] ~= "+X" do
  144. turnRight()
  145. end
  146. else
  147. while dir[nDir] ~= "-X" do
  148. turnRight()
  149. end
  150. end
  151. while x ~= dx do
  152. turtle.dig()
  153. goFor()
  154. end
  155. end
  156.  
  157. function goY(dy)
  158. if dy > y then
  159. while dir[nDir] ~= "+Y" do
  160. turnRight()
  161. end
  162. else
  163. while dir[nDir] ~= "-Y" do
  164. turnRight()
  165. end
  166. end
  167. while y ~= dy do
  168. turtle.dig()
  169. goFor()
  170. end
  171. end
  172.  
  173. function goPos(dx,dy)
  174. if dx > x then
  175. while dir[nDir] ~= "+X" do
  176. turnRight()
  177. end
  178. else
  179. while dir[nDir] ~= "-X" do
  180. turnRight()
  181. end
  182. end
  183. while x ~= dx do
  184. turtle.dig()
  185. goFor()
  186. end
  187. if dy > y then
  188. while dir[nDir] ~= "+Y" do
  189. turnRight()
  190. end
  191. else
  192. while dir[nDir] ~= "-Y" do
  193. turnRight()
  194. end
  195. end
  196. while y ~= dy do
  197. turtle.dig()
  198. goFor()
  199. end
  200. while dir[nDir] ~= "-X" do
  201. turnRight()
  202. end
  203. end
  204.  
  205. function stripMine(num)
  206. for i=1,num do
  207. stripFor()
  208. if i < num then
  209. print("Turning around.")
  210. if boolTurnRight then
  211. turnRight()
  212. mine()
  213. mine()
  214. mine()
  215. turnRight()
  216. else
  217. turnLeft()
  218. mine()
  219. mine()
  220. mine()
  221. turnLeft()
  222. end
  223. boolTurnRight = not boolTurnRight
  224. dirFor = not dirFor
  225. end
  226. end
  227. mineUp()
  228. mineDown()
  229. print("Going back to start.")
  230. goPos(0,0)
  231. dropOff()
  232. print("Job done.")
  233. end
  234.  
  235. if #Args == 0 then
  236. printUsage()
  237. else
  238. if tonumber(Args[1]) == 0 or tonumber(Args[2]) == 0 then
  239. printUsage()
  240. else
  241. if Args[3] == "right" or Args[3] == "left" then
  242. if Args[3] == "right" then
  243. boolTurnRight = true
  244. else
  245. boolTurnRight = false
  246. end
  247. blocksfor = tonumber(Args[1]) - 1
  248. dirFor = true
  249. stripMine(tonumber(Args[2])*3)
  250. end
  251. end
  252. end
Advertisement
Add Comment
Please, Sign In to add comment