bigtwisty

MiningWellTurtleTurn

Apr 7th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.32 KB | None | 0 0
  1. --name MiningWellTurtle
  2. --version 1.3
  3.  
  4. -- Turtle in the front with pickaxe and gate reader
  5. local version = "1.3"
  6. local size = 16
  7. local posX = 1
  8. local posY = 1
  9. local turnRightNext = true
  10. local turning = false
  11. local args = {...}
  12. local startTime = os.clock()
  13.  
  14. if #args > 0 then
  15. size = tonumber(args[1])
  16. end
  17. if #args > 2 then
  18. posX = tonumber(args[2])
  19. posY = tonumber(args[3])
  20. end
  21.  
  22. local function doScreen(str)
  23. term.clear()
  24. term.setCursorPos(1,1)
  25. write("Mining Well Turtle - v")
  26. print(version)
  27. print("------------------------------")
  28. print(string.format("Fuel: %d", turtle.getFuelLevel()))
  29. print(string.format("Pos: %d/%d, %d", posX, size, posY))
  30. print()
  31. print(str)
  32. end
  33.  
  34. local function loopBack()
  35. local dirX = 1
  36. if posY % 2 == 0 then dirX = -1 end
  37.  
  38. posX = posX + dirX
  39. if (posX > size) or (posX < 1) then
  40. if posY == size then
  41. doScreen(string.format("Completed in %d seconds", os.clock()-startTime))
  42. while true do
  43. os.sleep(120)
  44. end
  45. end
  46. if posY % 2 == 0 then turtle.turnLeft()
  47. else turtle.turnRight()
  48. end
  49. turning = true
  50. posX = posX - dirX
  51. posY = posY + 1
  52. elseif turning then
  53. if posY % 2 == 0 then turtle.turnRight()
  54. else turtle.turnLeft()
  55. end
  56. turning = false
  57. end
  58. end
  59.  
  60. -- Special functions to handle gravel/sand
  61. local function forward()
  62. turtle.select(1)
  63. while not turtle.forward() do
  64. turtle.dig()
  65. end
  66. end
  67.  
  68. local function digUp()
  69. while turtle.detectUp() do
  70. turtle.digUp()
  71. os.sleep(0.5)
  72. end
  73. end
  74.  
  75. -- Empty into Ender Chest
  76. local function empty()
  77. doScreen("Emptying turtle...")
  78.  
  79. -- Place ender chest
  80. if turtle.detectUp() then
  81. digUp()
  82. end
  83. turtle.select(15)
  84. turtle.placeUp()
  85.  
  86. for i=1,16 do
  87. if turtle.getItemCount(i) > 0 and i ~= 14 then
  88. turtle.select(i)
  89. turtle.dropUp()
  90. end
  91. end
  92.  
  93. turtle.select(15)
  94. turtle.digUp()
  95. end
  96.  
  97. local function replaceCell()
  98. doScreen("Replacing redstone cell...")
  99.  
  100. turtle.select(1)
  101. -- Place ender chest
  102. if turtle.detectUp() then
  103. digUp()
  104. end
  105.  
  106. turtle.turnRight()
  107. turtle.turnRight()
  108. turtle.select(14)
  109. turtle.placeUp()
  110. turtle.suck()
  111. turtle.dropUp()
  112. os.sleep(2)
  113. while not turtle.suckUp() do
  114. os.sleep(0.5)
  115. end
  116. turtle.drop()
  117. turtle.digUp()
  118. turtle.turnRight()
  119. turtle.turnRight()
  120. while not redstone.getInput("back") do
  121. os.sleep(0.5)
  122. end
  123. end
  124.  
  125. -- Wrap the gate detector
  126. local gate = peripheral.wrap("right")
  127.  
  128. doScreen("Place items as follows...")
  129. print("-------------------------")
  130. print("| Red EnderChest in 14")
  131. print("| White EnderChest in 15")
  132. print("| Mining Well in 16")
  133.  
  134. while (turtle.getItemCount(14)==0) or (turtle.getItemCount(15)==0) or (turtle.getItemCount(16)==0) do
  135. os.sleep(0.1)
  136. end
  137.  
  138. redstone.setOutput("back", true)
  139.  
  140. while true do
  141. for i=1,size do
  142. turtle.digDown()
  143. turtle.select(16)
  144. turtle.placeDown()
  145. turtle.select(1)
  146. digUp()
  147. empty()
  148. doScreen("Waiting for cell turtle...")
  149. while not redstone.getInput("back") do
  150. os.sleep(0.1)
  151. end
  152. doScreen("Mining...")
  153. while not gate.get()["Work Done"] do
  154. if not redstone.getInput("back") then
  155. replaceCell()
  156. end
  157. os.sleep(0.1)
  158. end
  159. redstone.setOutput("back",false)
  160. doScreen("Moving...")
  161. turtle.select(16)
  162. turtle.digDown()
  163. turtle.select(1)
  164. loopBack()
  165. forward()
  166. redstone.setOutput("back",true)
  167. end
  168. end
Advertisement
Add Comment
Please, Sign In to add comment