Advertisement
Blackhome

StripMineTunnelWithoutMining

Dec 17th, 2016
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.45 KB | None | 0 0
  1. -- only to dig a small strip mining tunnel
  2.  
  3. local numTunnels = 5
  4. local tunLength = 30
  5.  
  6. function turnAround()
  7. turtle.turnLeft()
  8. turtle.turnLeft()
  9. end
  10. function turtleForward()
  11. local numOfWait = 0
  12. while(turtle.forward() == false)do
  13. local success, data = turtle.inspect()
  14. if (success and data.name == "computercraft:CC-TurtleExpanded")then
  15. os.sleep(0.5)
  16. if (numOfWait%10 == 0)then
  17. print("Turtle is waiting in front of me")
  18. end
  19. numOfWait = numOfWait + 1
  20. else
  21. turtle.dig()
  22. end
  23. end
  24. os.sleep(0.25)
  25. while(turtle.detectUp())do
  26. turtle.digUp()
  27. os.sleep(0.25)
  28. end
  29. end
  30. function placeItemUp(itemName)
  31. local num = 1
  32. while (num < 17)do
  33. local numItems = turtle.getItemCount(num)
  34. if(numItems > 0)then
  35. turtle.select(num)
  36. local data = turtle.getItemDetail()
  37. if (data)then
  38. if(data.name == itemName)then
  39. turtle.placeUp()
  40. break
  41. end
  42. end
  43. end
  44. num = num + 1
  45. end
  46. end
  47. function placeItem(itemName)
  48. local num = 1
  49. while (num < 17)do
  50. local numItems = turtle.getItemCount(num)
  51. if(numItems > 0)then
  52. turtle.select(num)
  53. local data = turtle.getItemDetail()
  54. if (data)then
  55. if(data.name == itemName)then
  56. while(turtle.place() == false)do
  57. turtle.dig()
  58. end
  59. break
  60. end
  61. end
  62. end
  63. num = num + 1
  64. end
  65. end
  66. function placeUp()
  67. local slotNum = turtle.getSelectedSlot()
  68. if(turtle.placeUp() == false)then
  69. turtle.up()
  70. turtle.turnRight()
  71. local num = 1
  72. while (num < 17)do
  73. local numItems = turtle.getItemCount(num)
  74. if(numItems > 0)then
  75. turtle.select(num)
  76. local data = turtle.getItemDetail()
  77. if (data)then
  78. if(data.name == "minecraft:cobblestone" or data.name == "minecraft:stone")then
  79. turtle.place()
  80. break
  81. end
  82. end
  83. end
  84. num = num + 1
  85. end
  86. turtle.turnLeft()
  87. turtle.down()
  88. turtle.select(slotNum)
  89. turtle.placeUp()
  90. end
  91.  
  92. end
  93. function enoughTorchesAndChests()
  94. local cnt = 1
  95. local tSuccess = false
  96. local cSuccess = false
  97. while (cnt < 17)do
  98. local numItems = turtle.getItemCount(cnt)
  99. if (numItems > 0)then
  100. turtle.select(cnt)
  101. local data = turtle.getItemDetail()
  102. if (data)then
  103. if (data.name == "minecraft:torch" and numItems > 2)then
  104. tSuccess = true
  105. elseif (data.name == "minecraft:chest")then
  106. cSuccess = true
  107. end
  108. if (tSuccess and cSuccess)then
  109. return
  110. end
  111. end
  112. end
  113. cnt = cnt + 1
  114. end
  115. if (tSuccess == false)then
  116. print("You need 3 or more torches")
  117. print("Press enter to continue")
  118. io.read()
  119. enoughTorchesAndChests()
  120. return
  121. end
  122. if (cSuccess == false)then
  123. print("You need 1 or more chests")
  124. print("Press enter to continue")
  125. io.read()
  126. enoughTorchesAndChests()
  127. end
  128. end
  129. function haveEnoughFuel()
  130. if(turtle.getFuelLevel() < 100)then
  131. while(fuelWithOwnRessources() == false)do
  132. print("Please give some fuel to this turtle! After that press enter!")
  133. io.read()
  134. end
  135. end
  136. return true
  137. end
  138. function fuelWithOwnRessources()
  139. local slotsLeft = 16
  140. while (slotsLeft > 0)do
  141. local cntItem = turtle.getItemCount()
  142. if (cntItem > 0)then
  143. turtle.select(17 - slotsLeft)
  144. turtle.refuel()
  145. if (turtle.getFuelLevel() >= 100)then
  146. return true
  147. end
  148. end
  149. slotsLeft = slotsLeft - 1
  150. end
  151. return false
  152. end
  153. print("At which side do you make the strip mine tunnels?")
  154. print("Enter 1 for right, or any other number for left")
  155. local side = tonumber(io.read())
  156. local num = 0
  157. while (num < numTunnels)do
  158. enoughTorchesAndChests()
  159. local num1 = 1
  160. while (num1 <= tunLength)do
  161. turtleForward()
  162. num1 = num1 + 1
  163. end
  164. num1 = 1
  165. turnAround()
  166. placeItemUp("minecraft:torch")
  167. while (num1 <= tunLength)do
  168. if (num1 ~= 30 and num1 % 10 == 0)then
  169. placeItemUp("minecraft:torch")
  170. end
  171. turtle.forward()
  172.  
  173. num1 = num1 + 1
  174. end
  175. if(side == 1)then
  176. turtle.turnLeft()
  177. else
  178. turtle.turnRight()
  179. end
  180. placeItem("minecraft:chest")
  181. num1 = 1
  182. while(num1 < 17)do
  183. local numItems = turtle.getItemCount(num1)
  184. if (numItems > 0)then
  185. turtle.select(num1)
  186. local data = turtle.getItemDetail()
  187. if (data)then
  188. if (data.name ~= "minecraft:torch" and data.name ~= "minecraft:chest")then
  189. turtle.drop()
  190. end
  191. end
  192. end
  193. num1 = num1 + 1
  194. end
  195. if(num < numTunnels - 1)then
  196. turnAround()
  197. turtleForward()
  198. turtleForward()
  199. turtleForward()
  200. if (side == 1)then
  201. turtle.turnRight()
  202. else
  203. turtle.turnLeft()
  204. end
  205. end
  206.  
  207. num = num + 1
  208. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement