bigtwisty

RedstoneCellTurtle

Apr 6th, 2013
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. local version = "1.4"
  2. local torchDistance = 10
  3. local torchCount = 1
  4. local turn = ""
  5.  
  6. local gate = peripheral.wrap("right")
  7.  
  8. local function doScreen(str)
  9. term.clear()
  10. term.setCursorPos(1,1)
  11. write("Redstone Cell Turtle - v")
  12. print(version)
  13. print("------------------------------")
  14. write("Fuel: ")
  15. print(turtle.getFuelLevel())
  16. print()
  17. print(str)
  18. end
  19.  
  20. local function swapCells()
  21. doScreen("Getting fresh redstone cell from base...")
  22.  
  23. turtle.select(1)
  24. turtle.transferTo(14)
  25. turtle.select(16)
  26. turtle.digDown()
  27. turtle.transferTo(1)
  28. turtle.select(1)
  29. while turtle.getItemCount(1) > 0 do
  30. redstone.setOutput("front",true)
  31. os.sleep(0.2)
  32. redstone.setOutput("front",false)
  33. os.sleep(0.2)
  34. end
  35. while turtle.getItemCount(1) == 0 do
  36. os.sleep(0.2)
  37. end
  38. turtle.placeDown()
  39. redstone.setOutput("front",true)
  40. while not redstone.getInput("front") do
  41. os.sleep(0.2)
  42. end
  43. turtle.select(14)
  44. turtle.transferTo(1)
  45. turtle.select(1)
  46. doScreen("New redstone cell deployed.")
  47. end
  48.  
  49. local function doTorch()
  50. torchCount = torchCount + 1
  51. if torchCount > torchDistance then
  52. torchCount = 1
  53. turtle.select(15)
  54. turtle.placeUp()
  55. end
  56. end
  57.  
  58. local function fill()
  59. local i = 1
  60. while turtle.getItemCount(i) == 0 and i < 15 do
  61. i = i + 1
  62. end
  63. if i < 15 then
  64. turtle.select(i)
  65. turtle.placeDown()
  66. end
  67. end
  68.  
  69. doScreen("Place items as follows...")
  70. print("--------------------------")
  71. print("| Torches in 15 (optional)")
  72. print("| Redstone Cell in 16")
  73. print("| Fill rest with cobble (optional)")
  74. while (turtle.getItemCount(16)==0) do
  75. os.sleep(0.2)
  76. end
  77.  
  78. redstone.setOutput("front",true)
  79. doScreen("Waiting for lead turtle...")
  80. while not redstone.getInput("front") do
  81. os.sleep(0.1)
  82. end
  83.  
  84. turtle.select(16)
  85. turtle.placeDown()
  86. while true do
  87. doScreen("Powering...")
  88. doTorch()
  89. while redstone.getInput("front") do
  90. if gate.get()["No Energy"] then
  91. swapCells()
  92. end
  93. os.sleep(0.5)
  94. end
  95. doScreen("Moving...")
  96.  
  97. turtle.select(16)
  98. turtle.digDown()
  99. fill()
  100. redstone.setOutput("front",false)
  101. while not turtle.forward() do
  102. os.sleep(0.1)
  103. end
  104. turtle.select(16)
  105. turtle.placeDown()
  106. while not redstone.getInput("front") do
  107. doScreen("Searching for lead turtle...")
  108. turtle.turnRight()
  109. end
  110. redstone.setOutput("front",true)
  111. end
Advertisement
Add Comment
Please, Sign In to add comment