Advertisement
jnsstnbrg

Place floor turtle script

Feb 6th, 2013
267
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.65 KB | None | 0 0
  1. args = {...}
  2.  
  3. local floorType
  4. local orientation
  5. local currentSlot = 2
  6.  
  7. if #args > 1 then
  8. if tostring(args[1]) == "top" then
  9. floorType = "top"
  10. elseif tostring(args[1]) == "bottom" then
  11. floorType = "bottom"
  12. elseif not tostring(args[1]) == "top" or not tostring(args[1]) == "bottom" then
  13. error("Usage: placeFloor <position> (either top or bottom) <direction> (either left or right)")
  14. end
  15.  
  16. if tostring(args[2]) == "left" then
  17. orientation = 1
  18. elseif tostring(args[2]) == "right" then
  19. orientation = 3
  20. elseif not tostring(args[2]) == "left" or not tostring(args[2]) == "right" then
  21. error("Usage: placeFloor <position> (either top or bottom) <direction> (either left or right)")
  22. end
  23. else
  24. error("Usage: placeFloor <position> (either top or bottom) <direction> (either left or right)")
  25. end
  26.  
  27. function gotoNextSlotIfEmpty()
  28. if turtle.getItemCount(currentSlot) == 0 then
  29. currentSlot = currentSlot + 1
  30. turtle.select(currentSlot)
  31. while not turtle.compareTo(1) do
  32. currentSlot = currentSlot + 1
  33. if currentSlot > 16 then
  34. return false
  35. end
  36. turtle.select(currentSlot)
  37. end
  38. end
  39. return true
  40. end
  41.  
  42. function reSupply()
  43. resupplied = false
  44. print("turtle out of items. waiting for new items in slot 2-16. once you place blocks in the 2nd slot it will count to 10 and then continue.")
  45. repeat
  46. if turtle.getItemCount(2) > 0 then
  47. sleep(10)
  48. resupplied = true
  49. currentSlot = 2
  50. turtle.select(currentSlot)
  51. end
  52. sleep(0.5)
  53. until resupplied
  54. end
  55.  
  56. function checkFuelLevel()
  57. if turtle.getFuelLevel() < 10 then
  58. return false
  59. end
  60. return true
  61. end
  62.  
  63. function reFuel()
  64. refueled = false
  65. print("turtle out of fuel. waiting for fuel in slot 2-16. once you place fuel in the 2nd slot it will count to 10 and then consume all it can and then continue.")
  66. repeat
  67. if turtle.getItemCount(2) > 0 then
  68. sleep(10)
  69. for i=2,16 do
  70. turtle.select(i)
  71. turtle.refuel()
  72. end
  73. currentSlot = 2
  74. turtle.select(currentSlot)
  75. refueled = true
  76. end
  77. sleep(0.5)
  78. until refueled
  79. end
  80.  
  81. function left()
  82. if turtle then turtle.turnLeft() end
  83. orientation = orientation - 1
  84. if orientation < 1 then orientation = 4 end
  85. return orientation
  86. end
  87.  
  88. function right()
  89. if turtle then turtle.turnRight() end
  90. orientation = orientation + 1
  91. if orientation > 1 then orientation = 1 end
  92. return orientation
  93. end
  94.  
  95. function placeBlock()
  96. if not gotoNextSlotIfEmpty() then
  97. reSupply()
  98. end
  99. if not checkFuelLevel() then
  100. reFuel()
  101. end
  102. if floorType == "top" then
  103. if not turtle.detectUp() then
  104. turtle.placeUp()
  105. else
  106. turtle.digUp()
  107. turtle.placeUp()
  108. end
  109. elseif floorType == "bottom" then
  110. if not turtle.detectDown() then
  111. turtle.placeDown()
  112. else
  113. turtle.digDown()
  114. turtle.placeDown()
  115. end
  116. end
  117. end
  118.  
  119. function moveTurtle()
  120. if orientation == 1 then
  121. left()
  122. if turtle.detect() then
  123. error()
  124. else
  125. turtle.forward()
  126. right()
  127. if not turtle.detect() then
  128. left()
  129. left()
  130. while true do
  131. if turtle.detect() then
  132. left()
  133. break
  134. end
  135. turtle.forward()
  136. end
  137. else
  138. left()
  139. end
  140. end
  141. left()
  142. elseif orientation == 3 then
  143. right()
  144. if turtle.detect() then
  145. error()
  146. else
  147. turtle.forward()
  148. left()
  149. if not turtle.detect() then
  150. right()
  151. right()
  152. while true do
  153. if turtle.detect() then
  154. right()
  155. break;
  156. end
  157. turtle.forward()
  158. end
  159. else
  160. right()
  161. end
  162. end
  163. right()
  164. end
  165. end
  166.  
  167. turtle.select(currentSlot)
  168. while true do
  169. if turtle.detect() then
  170. placeBlock()
  171. moveTurtle()
  172. else
  173. placeBlock()
  174. turtle.forward()
  175. end
  176. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement