MDKed

digdownV4.1

Jul 6th, 2013
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.04 KB | None | 0 0
  1. heading = 1
  2. rHeading = 1
  3.  
  4. pos = vector.new(0,0,0)
  5. lPos = vector.new(0,0,0)
  6.  
  7. tgted = false
  8. unloading = false
  9. tgt = vector.new(0,0,0)
  10.  
  11. waypoints = {}
  12. waypoints['dockUnl'] = vector.new(-2,0,2)
  13. waypoints['unload'] = vector.new(-2,0,1)
  14. waypoints['retP'] = vector.new(0,0,1)
  15.  
  16. function chkInv()
  17. if unloading ~= true then
  18.  
  19. itmQ = 0
  20. for a = 2, 16 do
  21. itmQ = itmQ + turtle.getItemCount(a)
  22. end
  23. print(' item count = ', itmQ)
  24. if itmQ > 600 then
  25. print(' returning to unload')
  26. lPos = vector.new(pos.x, pos.y, pos.z)
  27. rHeading = heading
  28. unloadTime()
  29. end
  30. end
  31. end
  32.  
  33. function unloadTime()
  34. unloading = true
  35. moveToTgt(waypoints['dockUnl'])
  36. moveToTgt(waypoints['unload'])
  37. for a = 2, 16 do
  38. turtle.select(a)
  39. turtle.drop()
  40. end
  41. moveToTgt(waypoints['dockUnl'])
  42. print('returning to ', lPos.x, "x",lPos.y, "x",lPos.z)
  43. moveToTgt(lPos)
  44. rot(rHeading)
  45. unloading = false
  46. end
  47.  
  48. function moveToTgt(Vector)
  49. tgt = Vector
  50. tgted = true
  51. while (pos.x ~= tgt.x) or (pos.y ~= tgt.y) or (pos.z ~= tgt.z) do
  52. if pos.x > tgt.x then
  53. move(4)
  54. elseif pos.x < tgt.x then
  55. move(2)
  56. end
  57. if pos.y > tgt.y then
  58. move(5)
  59. elseif pos.y < tgt.y then
  60. move(6)
  61. end
  62. if pos.z > tgt.z then
  63. move(3)
  64. elseif pos.z < tgt.z then
  65. move(1)
  66. end
  67. end
  68. end
  69.  
  70. function move(Int)
  71.  
  72. if (Int > 0) and (Int < 5) then
  73. rot(Int)
  74. Fwd(1)
  75. elseif Int == 5 then
  76. chkInv()
  77. ChkFuel()
  78. turtle.digDown()
  79. turtle.down()
  80. chngCoord(5)
  81. elseif Int == 6 then
  82. chkInv()
  83. ChkFuel()
  84. turtle.digUp()
  85. turtle.up()
  86. chngCoord(6)
  87. end
  88. end
  89.  
  90. function rotB(Bool)
  91. if Bool then
  92. turtle.turnRight()
  93. heading = heading + 1
  94. else
  95. turtle.turnLeft()
  96. heading = heading - 1
  97. end
  98. if heading > 4 then
  99. heading = 1
  100. elseif heading < 1 then
  101. heading = 4
  102. end
  103. end
  104.  
  105. function rot(Int)
  106. a = heading - 1
  107. if a < 1 then
  108. a = 4
  109. end
  110. if a == Int then
  111. turtle.turnLeft()
  112. heading = heading - 1
  113. end
  114. a = heading + 1
  115. if a > 4 then
  116. a = 1
  117. end
  118. if a == Int then
  119. turtle.turnRight()
  120. heading = heading + 1
  121. end
  122. if heading > 4 then
  123. heading = 1
  124. elseif heading < 1 then
  125. heading = 4
  126. end
  127. while Int ~= heading do
  128. turtle.turnRight()
  129. heading = heading + 1
  130. if heading > 4 then
  131. heading = 1
  132. elseif heading < 1 then
  133. heading = 4
  134. end
  135. end
  136. end
  137.  
  138. function swapBool(Bool)
  139. if Bool then
  140. return false
  141. else
  142. return true
  143. end
  144. end
  145.  
  146. function chngCoord(Int)
  147. if Int == 1 then
  148. pos.z = pos.z + 1
  149. elseif Int == 2 then
  150. pos.x = pos.x + 1
  151. elseif Int == 3 then
  152. pos.z = pos.z - 1
  153. elseif Int == 4 then
  154. pos.x = pos.x - 1
  155. elseif Int == 5 then
  156. pos.y = pos.y - 1
  157. elseif Int == 6 then
  158. pos.y = pos.y + 1
  159. end
  160. end
  161.  
  162. function ChkFuel()
  163. if turtle.getFuelLevel() == 0 then
  164. turtle.select(1)
  165. if turtle.refuel(1) == true then
  166. print('Dozapravke na ',pos.x, "x",pos.y, "x",pos.z)
  167. end
  168. end
  169. end
  170.  
  171. function Fwd(Int)
  172. for a = 1, Int do
  173. while turtle.detect() do
  174. chkInv()
  175. turtle.dig()
  176. end
  177. ChkFuel()
  178. if turtle.forward() then
  179. chngCoord(heading)
  180. end
  181. end
  182. end
  183.  
  184. function Turn(Bool)
  185. if Bool then
  186. rotB(true)
  187. Fwd(1)
  188. rotB(true)
  189. return false
  190. else
  191. rotB(false)
  192. Fwd(1)
  193. rotB(false)
  194. return true
  195. end
  196. end
  197.  
  198. function down()
  199. move(5)
  200. rotB(false)
  201. rotB(false)
  202. end
  203.  
  204. print('Vvedite Shiriny')
  205. mX = tonumber(read())
  206. print('Vvedite glubinu')
  207. mY = tonumber(read())
  208.  
  209. print(' Starting at ',pos.x, "x",pos.y, "x",pos.z)
  210.  
  211. Fwd(1)
  212. rotB(false)
  213. Fwd(mX/2)
  214. rotB(true)
  215.  
  216. for c=1, 2 do
  217. move(6)
  218. end
  219.  
  220. print(' Dig down at ',pos.x, "x",pos.y, "x",pos.z)
  221.  
  222. turn = true
  223.  
  224. for y = 1, mY+3 do
  225. if y > 1 then
  226. down()
  227. end
  228. for x = 1, mX do
  229. if mX > 1 then
  230. Fwd(mX - 1)
  231. else
  232. Fwd(mX)
  233. end
  234. if x ~= mX then
  235. turn = Turn(turn)
  236. end
  237. end
  238. end
  239.  
  240. print('Begin dig up, steps up = ', mY, "\n ", pos.x, "x",pos.y, "x",pos.z)
  241.  
  242.  
  243. for b=1, mY do
  244. move(6)
  245. end
  246. unloadTime()
  247. moveToTgt(waypoints['retP'])
  248. moveToTgt(vector.new(0,0,0))
  249. print('Ending operation ', pos.x, "x",pos.y, "x",pos.z)
Advertisement
Add Comment
Please, Sign In to add comment