bigtwisty

MiningWellTurtle

Apr 6th, 2013
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.73 KB | None | 0 0
  1. -- Turtle in the front with pickaxe and gate reader
  2. local version = "1.0"
  3.  
  4. local function doScreen(str)
  5. term.clear()
  6. term.setCursorPos(1,1)
  7. write("Mining Well Turtle - v")
  8. print(version)
  9. print("------------------------------")
  10. write("Fuel: ")
  11. print(turtle.getFuelLevel())
  12. print()
  13. print(str)
  14. end
  15.  
  16. local stopAt16 = true
  17.  
  18. -- Special functions to handle gravel/sand
  19. local function forward()
  20. while not turtle.forward() do
  21. turtle.dig()
  22. end
  23. end
  24.  
  25. local function digUp()
  26. while turtle.detectUp() do
  27. turtle.digUp()
  28. os.sleep(0.5)
  29. end
  30. end
  31.  
  32. -- Empty into Ender Chest
  33. local function empty()
  34. doScreen("Emptying turtle...")
  35.  
  36. -- Place ender chest
  37. if turtle.detectUp() then
  38. digUp()
  39. end
  40. turtle.select(15)
  41. turtle.placeUp()
  42.  
  43. for i=1,16 do
  44. while turtle.getItemCount(i) > 0 do
  45. turtle.select(i)
  46. turtle.dropUp()
  47. end
  48. end
  49.  
  50. turtle.select(15)
  51. turtle.digUp()
  52.  
  53. end
  54.  
  55. -- Wrap the gate detector
  56. local gate = peripheral.wrap("right")
  57.  
  58. doScreen("Place items as follows...")
  59. print("-------------------------")
  60. print("| EnderChest in 15")
  61. print("| Mining Well in 16")
  62.  
  63. while (turtle.getItemCount(15)==0) or (turtle.getItemCount(16)==0) do
  64. os.sleep(0.1)
  65. end
  66.  
  67. rs.setBundledOutput("back", colors.red)
  68.  
  69. while true do
  70. for i=1,16 do
  71. turtle.digDown()
  72. turtle.select(16)
  73. turtle.placeDown()
  74. doScreen("Mining...")
  75. turtle.select(1)
  76. digUp()
  77. while not gate.get()["Work Done"] do
  78. os.sleep(0.1)
  79. end
  80.  
  81. if turtle.getItemCount(12) > 0 then
  82. empty()
  83. end
  84. doScreen("Moving...")
  85. turtle.select(16)
  86. turtle.digDown()
  87. turtle.select(1)
  88. forward()
  89. end
  90.  
  91. if stopAt16 then
  92. print("Mined 16 blocks. Press any key...")
  93. os.pullEvent("char")
  94. end
  95. end
Advertisement
Add Comment
Please, Sign In to add comment