Advertisement
Guest User

Untitled

a guest
Mar 4th, 2015
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.99 KB | None | 0 0
  1. term.clear()
  2. term.setCursorPos(4,7)
  3. print("**Welcome to Tunnel-Miner by SuperDizor**")
  4. term.setCursorPos(12,13)
  5. print("*Tunnel-Miner Beta v1.0*")
  6. os.sleep(2)
  7. term.clear()
  8. print "Torches in slot 15 (optional), Fuel in slot 16 (optional, allows turtle to eat found fuel as a last resort)."
  9. print "How far is this mine?(x)"
  10. local xSize = tonumber(io.read())
  11. print "How high? (y)"
  12. local ySize = tonumber(io.read())
  13. print "How wide (to the left)? (z) (even numbers are more efficient)"
  14. local zSize = tonumber(io.read())
  15.  
  16. end
  17.  
  18.  
  19.  
  20. -- 0 = South, 1 = West, 2 = North, 3 = East
  21. -- These are relative values, not necessarily the minecraft facing dir (which you need wireless for)
  22. -- If the player isn't actually facing south, x and z will be inverted or reversed. That's OK.
  23. local iDirection = 0
  24.  
  25. local xMovedFromOrigin = 0
  26. local yMovedFromOrigin = 0
  27. local zMovedFromOrigin = 0
  28. local distance = 0
  29. local distance_z = 0
  30.  
  31. local bHasTorches = turtle.getItemCount(15) > 0
  32. local bHasFuel = turtle.getItemCount(16) > 0
  33.  
  34. function CheckFuel()
  35. if(bHasFuel == false) then
  36. return true
  37. end
  38.  
  39. if turtle.getFuelLevel() <= 10 then
  40. turtle.select(16)
  41. turtle.refuel(1)
  42. if turtle.getFuelLevel() <= 10 then
  43. -- phase 2: low fuel, fueling failed, return home
  44. end
  45. end
  46.  
  47. if turtle.getFuelLevel() <= 1 then
  48. print "OOF: Out Of Fuel :("
  49. print "I'm going to eat your coal"
  50. shell.run("refuel", "all")
  51. if turtle.getFuelLevel() <= 1 then
  52. print "I am STILL out of fuel...turtle starving..."
  53. print "going...dark..."
  54. print "...so...cold...sleepy..."
  55. turtle.sleep(120)
  56. return false
  57. end
  58. end
  59.  
  60. return true
  61. end
  62.  
  63. function MoveForward()
  64. CheckFuel()
  65.  
  66. if(turtle.forward()) then
  67. if iDirection == 0 then
  68. zMovedFromOrigin = zMovedFromOrigin + 1
  69. elseif iDirection == 1 then
  70. xMovedFromOrigin = xMovedFromOrigin - 1
  71. elseif iDirection == 2 then
  72. zMovedFromOrigin = zMovedFromOrigin - 1
  73. elseif iDirection == 3 then
  74. xMovedFromOrigin = xMovedFromOrigin + 1
  75. end
  76. return true
  77. else
  78. return false
  79. end
  80. end
  81.  
  82. function TurnLeft()
  83. iDirection = iDirection - 1
  84. if(iDirection < 0) then
  85. iDirection = 3
  86. end
  87. turtle.turnLeft()
  88. end
  89.  
  90. function TurnRight()
  91. iDirection = iDirection + 1
  92. if(iDirection > 3) then
  93. iDirection = 0
  94. end
  95. turtle.turnRight()
  96. end
  97.  
  98. function MoveUp()
  99. CheckFuel()
  100. if(turtle.up()) then
  101. yMovedFromOrigin = yMovedFromOrigin + 1
  102. return true
  103. end
  104. return false
  105. end
  106.  
  107. function MoveDown()
  108. CheckFuel()
  109. if(turtle.down()) then
  110. yMovedFromOrigin = yMovedFromOrigin - 1
  111. return true
  112. end
  113. return false
  114. end
  115.  
  116. function PlaceTorch()
  117. if(bHasTorches == false) then
  118. return
  119. end
  120.  
  121. if turtle.getItemCount(15) >= 1 then
  122.  
  123. local iSaveDirection = iDirection
  124. while(iDirection ~= 2) do
  125. TurnRight()
  126. end
  127.  
  128. turtle.select(15)
  129. turtle.place()
  130.  
  131. while(iDirection ~= iSaveDirection) do
  132. TurnLeft()
  133. end
  134.  
  135. end
  136. end
  137.  
  138. function DigUp(iBlocks)
  139. if(iBlocks < 1) then
  140. return
  141. end
  142. for y = 1, iBlocks - 1 do
  143. while(MoveUp() == false) do
  144. turtle.digUp()
  145. turtle.suckUp()
  146. end -- end while
  147. end -- end up/down
  148. end
  149.  
  150. function DigDown(iBlocks)
  151. if(iBlocks < 1) then
  152. return
  153. end
  154. for y = 1, iBlocks - 1 do
  155. while(MoveDown() == false) do
  156. turtle.digDown()
  157. turtle.suckDown()
  158. end -- end while
  159. end -- end up/down
  160. end
  161.  
  162. function DigForward()
  163. while(MoveForward() == false) do
  164. turtle.dig()
  165. turtle.suck()
  166. end
  167. end
  168.  
  169.  
  170. function GoHome()
  171.  
  172. DigDown(yMovedFromOrigin)
  173.  
  174. if iDirection == 0 then
  175. TurnRight()
  176. TurnRight()
  177. elseif iDirection == 1 then
  178. TurnRight()
  179. elseif iDirection == 3 then
  180. TurnLeft()
  181. end
  182.  
  183. for i = 1, zMovedFromOrigin do
  184. DigForward()
  185. end
  186. TurnLeft()
  187.  
  188. for i = 1, xMovedFromOrigin do
  189. DigForward()
  190. end
  191.  
  192. end
  193.  
  194. function DumpInventoryToSlot1()
  195.  
  196. DigDown(yMovedFromOrigin)
  197. local distance = xMovedFromOrigin
  198. local distance_z = zMovedFromOrigin
  199.  
  200.  
  201. if iDirection == 0 then
  202. TurnRight()
  203. TurnRight()
  204. elseif iDirection == 1 then
  205. TurnRight()
  206. elseif iDirection == 3 then
  207. TurnLeft()
  208. end
  209.  
  210. for i = 1, zMovedFromOrigin do
  211. DigForward()
  212. end
  213. TurnLeft()
  214.  
  215. for i = 1, xMovedFromOrigin do
  216. DigForward()
  217. end
  218.  
  219. for i = 1,10 do
  220. TurnRight()
  221. turtle.select(i)
  222. if turtle.detect(true) then
  223. turtle.drop()
  224. end
  225. end
  226. TurnRight()
  227. TurnRight()
  228. for i = 1, distance do
  229. DigForward()
  230. end
  231. TurnLeft()
  232. for i = 1, distance_z do
  233. DigForward()
  234. end
  235.  
  236.  
  237. end
  238.  
  239.  
  240.  
  241.  
  242. function Main()
  243. print("Mining " .. xSize .. ", " .. ySize .. ", " .. zSize)
  244.  
  245. TurnLeft()
  246. local zMax = math.floor(zSize / 2)
  247.  
  248. for x = 1, xSize do
  249.  
  250. for z = 1, zMax do
  251. DigUp(ySize)
  252. DigForward()
  253. DigDown(ySize)
  254.  
  255. if z < zMax then
  256. DigForward()
  257. end
  258. -- if we filled up almost all of the inventory (1 is ender chest so 2-10), dump inventory to chest
  259. if turtle.getItemCount(10) >= 1 then
  260. print("~" .. (x / xSize * 100) .. "% complete, " .. turtle.getFuelLevel() .. " fuel remaining.")
  261. distance = zMovedFromOrigin
  262. DumpInventoryToSlot1()
  263. end
  264. end -- end z axis
  265.  
  266. -- if the face size wasn't even, we still have a single column to clear
  267. if(zSize % 2 ~= 0) then
  268. -- print("adjusting for odd face size")
  269. DigForward()
  270. DigUp(ySize)
  271. DigDown(ySize)
  272. end
  273.  
  274. -- if we need to change the orientation of the cleared area, change right to left here
  275. if(x % 2 ~= 0) then
  276. TurnRight()
  277. DigForward()
  278. TurnRight()
  279. else
  280. TurnLeft()
  281. DigForward()
  282. TurnLeft()
  283. end
  284.  
  285. if(x % 8 == 7) then
  286. PlaceTorch()
  287. end
  288.  
  289. end -- end x axis
  290.  
  291. print "Returning home now!"
  292.  
  293. GoHome()
  294. DumpInventoryToSlot1()
  295. end
  296.  
  297.  
  298.  
  299. Main() -- !
  300. -- Y = Hauteur, X = Longueur, Z = Largeur
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement