Advertisement
Guest User

Untitled

a guest
Jul 18th, 2019
539
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.95 KB | None | 0 0
  1. --[[
  2. Known Issues:
  3. Also, allow this to work with fuel, though this was originally
  4. built with fuel disabled, if it runs in a world that requires fuel
  5. it may get stuck if its not fueled properly.
  6.  
  7. ]]
  8.  
  9. redstone.setOutput("left",false)
  10. local dn = 15 -- Distance notification, basically tells you how far the turtle has dug in increments
  11. local length, walk = ...
  12. local delay = 0.25 -- This is to accomodate Sand falling, or obsidian forming
  13. if length == nil then
  14. print("No length argument was given")
  15. return false -- Closes Program
  16. end
  17.  
  18. if walk == 'true' then
  19. walk = true
  20. else
  21. walk = false
  22. end
  23.  
  24.  
  25. --These variables keep track of the Turtles position and
  26. --orientation relative to the turtles Starting Position
  27. X = 0
  28. Y = 0
  29. Z = 0
  30. O = 0
  31.  
  32. --[[
  33. Orientation List
  34. Forward = 0
  35. Right = 1
  36. Back = 2
  37. Left = 3
  38. ]]--
  39.  
  40.  
  41. -- These functions are used to keep track of
  42. -- The Turtles Position Relative to its
  43. -- Starting Point
  44.  
  45. function left(q)
  46. if q == nil then q = 1 end
  47. for i=1,q do
  48. turtle.turnLeft()
  49. if O == 0 then
  50. O = 3
  51. else
  52. O = O - 1
  53. end
  54. end
  55. return true
  56. end
  57.  
  58. function right(q)
  59. if q == nil then q = 1 end
  60. for i=1,q do
  61. turtle.turnRight()
  62. if O == 3 then
  63. O = 0
  64. else
  65. O = O + 1
  66. end
  67. end
  68. return true
  69. end
  70.  
  71. function up(q)
  72. if q == nil then q = 1 end
  73. for i=1,q do
  74. while not turtle.up() do
  75. digUp()
  76. turtle.up()
  77. sleep(delay)
  78. end
  79. Y = Y + 1
  80. end
  81. return true
  82. end
  83.  
  84. function down(q)
  85. if q == nil then q = 1 end
  86. for i=1,q do
  87. while not turtle.down() do
  88. digDown()
  89. turtle.attackDown()
  90. sleep(delay)
  91. end
  92. Y = Y - 1
  93. end
  94. return true
  95. end
  96.  
  97. function forward(q)
  98. if q == nil then q = 1 end
  99. for i=1,q do
  100. while not turtle.forward() do
  101. turtle.dig()
  102. turtle.attack()
  103. sleep(delay)
  104. end
  105. if O == 0 then
  106. X = X + 1
  107. elseif O == 1 then
  108. Z = Z + 1
  109. elseif O == 2 then
  110. X = X - 1
  111. elseif O == 3 then
  112. Z = Z - 1
  113. end
  114. end
  115. return true
  116. end
  117.  
  118. function back()
  119. right()
  120. right()
  121. forward()
  122. left()
  123. left()
  124. return true
  125. end
  126.  
  127. function orient(arg1)
  128. while arg1 ~= O do
  129. right()
  130. end
  131. return true
  132. end
  133.  
  134. function dig()
  135. while turtle.detect() do
  136. turtle.dig()
  137. sleep(delay)
  138. end
  139. return true
  140. end
  141.  
  142. function digUp()
  143. while turtle.detectUp() do
  144. turtle.digUp()
  145. sleep(delay)
  146. end
  147. return true
  148. end
  149.  
  150. function digDown()
  151. while turtle.detectDown() do
  152. turtle.digDown()
  153. sleep(delay)
  154. end
  155. return true
  156. end
  157.  
  158. --[[ Tells turtle where to go for longer movements,
  159. such as going to and from the chest.
  160. This may error if theres blocks in the way, but
  161. Given the way we will have the turtle move in this
  162. program, it will be fine. How ever if I were to
  163. copy this function over to another program, I'd
  164. probably fix this issue.]]
  165. function go(lx,ly,lz)
  166. if X < lx then
  167. orient(0)
  168. for i=1,(lx-X) do
  169. forward()
  170. end
  171. end
  172.  
  173. if X > lx then
  174. orient(2)
  175. for i=1,X-lx do
  176. forward()
  177. end
  178. end
  179.  
  180. if Y < ly then
  181. for i=1,ly-Y do
  182. up()
  183. end
  184. end
  185.  
  186. if Y > ly then
  187. for i=1,Y-ly do
  188. down()
  189. end
  190. end
  191.  
  192. if Z < lz then
  193. orient(1)
  194. for i=1,lz-Z do
  195. forward()
  196. end
  197. end
  198.  
  199. if Z > lz then
  200. orient(3)
  201. for i=1,Z-lz do
  202. forward()
  203. end
  204. end
  205. end
  206.  
  207.  
  208.  
  209. -- Deposits Items into a chest
  210. -- Warning! This may error if
  211. -- the chest is full, so make sure
  212. -- its emptied
  213. function deposit()
  214. for i=1,16 do
  215. turtle.select(i)
  216. while turtle.drop() == false and turtle.getItemCount() ~= 0 do -- Waits until turtle can deposit item
  217. sleep(1)
  218. end
  219. turtle.drop()
  220. end
  221. turtle.select(1)
  222. return true
  223. end
  224.  
  225.  
  226.  
  227. --[[
  228. This function is what tells the
  229. turtle to mine and when to go back
  230. to empty its inventory
  231. ]]--
  232. function mine()
  233. dig()
  234. forward()
  235. digUp()
  236. digDown()
  237. up()
  238. left()
  239. dig()
  240. right(2)
  241. dig()
  242. down()
  243. dig()
  244. left(2)
  245. dig()
  246. down()
  247. dig()
  248. right(2)
  249. dig()
  250. left()
  251. up()
  252. end
  253.  
  254.  
  255. -- Checks if turtle is full
  256. function check()
  257. if turtle.getItemCount(15) == 0 then -- Checks second last slot. I'd like to leave 2 slots empty just to be safe
  258. return false
  259. else
  260. return true
  261. end
  262. end
  263.  
  264. function notify(include)
  265. if X % dn == 0 and X ~= 0 then
  266. print("The turtle has traveled "..X.."/"..length+include.." blocks so far")
  267. end
  268. return true
  269. end
  270.  
  271. local dni = 0 -- Blocks for distance notification to include in length, from the walk program
  272. if walk then
  273. while turtle.detect() == false do
  274. forward()
  275. dni = dni + 1
  276. notify(dni) -- Notifies Distance
  277. end
  278. end
  279.  
  280. for i=1,length do
  281. mine()
  282. notify(dni) -- Notifies Distance
  283. if check() then -- Checks if turtle should deposit items
  284. local lx,ly,lz = X,Y,Z
  285. go(0,0,0)
  286. orient(2) -- Faces Chest
  287. deposit()
  288. orient(0)
  289. go(lx,ly,lz)
  290. end
  291. end
  292.  
  293. -- Returns to chest and deposits items before ending program
  294. go(0,0,0)
  295. orient(2) -- Faces Chest
  296. deposit()
  297. orient(0)
  298. print("Program Ended, thank's for using BowWhalley's Digging Program")
  299. sleep(1)
  300. redstone.setOutput("left",true)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement