Advertisement
Guest User

Untitled

a guest
Jan 23rd, 2017
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.79 KB | None | 0 0
  1. --[[ Copyright by Pascal-HP.de 2017
  2. -> To lazy to whole out a room? This script will do that for you ;)
  3. ]]
  4.  
  5.  
  6. textutils.slowPrint("Welcome to kronova room builder.)")
  7. textutils.slowPrint("Please note: The turtle builds from\nthe left to the right side!")
  8.  
  9. print([[
  10. Slot IDs:
  11. -----------
  12. | 1| 2| 3| 4|
  13. | 5| 6| 7| 8|
  14. | 9|10|11|12|
  15. |13|14|15|16|
  16. -----------
  17. ]])
  18.  
  19. function digBlocks()
  20. -- break block(s)
  21. while turtle.detect() do
  22. turtle.dig()
  23. end
  24. end
  25.  
  26. function digBlocksUp()
  27. -- break block(s)
  28. while turtle.detectUp() do
  29. turtle.digUp()
  30. end
  31. end
  32.  
  33. function digBlocksDown()
  34. -- break block(s)
  35. while turtle.detectDown() do
  36. turtle.digDown()
  37. end
  38. end
  39.  
  40. --[[ inspects the item in direction and returns the nameDamage value ]]
  41. function inspectItemNameDamage(direction)
  42. if direction == "up" then
  43. local success, itemDetail = turtle.inspectUp()
  44. if success then
  45. return itemDetail.name .. "::" .. tostring(itemDetail.metadata)
  46. end
  47. elseif direction == "down" then
  48. local success, itemDetail = turtle.inspectDown()
  49. if success then
  50. return itemDetail.name .. "::" .. tostring(itemDetail.metadata)
  51. end
  52. else
  53. local success, itemDetail = turtle.inspect()
  54. if success then
  55. return itemDetail.name .. "::" .. tostring(itemDetail.metadata)
  56. end
  57. end
  58. end
  59.  
  60. --[[ places item in direction if target block is not equal to the slot item
  61. ]]
  62. function digAndPlaceBlock(direction)
  63. if direction == "up" then
  64. if inspectItemNameDamage("up") ~= selectAndGetItemDetail(turtle.getSelectedSlot(), "nameDamage") then
  65. digBlocksUp()
  66. turtle.placeUp()
  67. end
  68. elseif direction == "down" then
  69. if inspectItemNameDamage("down") ~= selectAndGetItemDetail(turtle.getSelectedSlot(), "nameDamage") then
  70. digBlocksDown()
  71. turtle.placeDown()
  72. end
  73. else
  74. if inspectItemNameDamage("") ~= selectAndGetItemDetail(turtle.getSelectedSlot(), "nameDamage") then
  75. digBlocks()
  76. turtle.place()
  77. end
  78. end
  79. end
  80.  
  81. --[[ reads a number and validates if there is a item in it.
  82. returns the slot id if there are items in it ]]
  83. function selectItemSlot()
  84. repeat
  85. continue = false
  86. write(" SlotID: ")
  87. slotId = io.read()
  88. if slotId ~= "" then
  89. slotId = tonumber(slotId)
  90. if slotId > 0 and slotId < 17 then
  91. turtle.select(slotId)
  92. if turtle.getItemCount() > 0 then
  93. continue = true
  94. else
  95. print("You have to put an item into that slot!")
  96. end
  97. else
  98. print("SlotID must between 1-16!")
  99. end
  100. else
  101. print("SlotID must between 1-16!")
  102. end
  103. until continue == true
  104. return slotId
  105. end
  106.  
  107. --[[ selects and returns name, damage or count of this item if possible.
  108. returnValue can be: name, damage, count, nameDamage ]]
  109. function selectAndGetItemDetail(slotNumber, returnValue)
  110. turtle.select(slotNumber)
  111. local itemDetail = turtle.getItemDetail()
  112.  
  113. if itemDetail then
  114. if returnValue == "name" then
  115. return itemDetail.name
  116. elseif returnValue == "damage" then
  117. return itemDetail.damage
  118. elseif returnValue == "nameDamage" then
  119. return itemDetail.name .. "::" .. tostring(itemDetail.damage)
  120. else
  121. return itemDetail.count
  122. end
  123. else
  124. return false
  125. end
  126. end
  127.  
  128. --[[ compares the item with the currently selected item
  129. returns true if identical else false
  130. use function selectAndGetItemDetail(slotNumber, "nameDamage")
  131. for param nameDamage ]]
  132. function compareItem(nameDamage)
  133. if selectAndGetItemDetail(turtle.getSelectedSlot(), "nameDamage") == nameDamage then
  134. return true
  135. else
  136. return false
  137. end
  138. end
  139.  
  140. --[[ selects an item by nameDamage value.
  141. use selectAndGetItemDetail(slotNumber, "nameDamage") to get nameDamage value ]]
  142. function selectItemByNameDamage(nameDamage)
  143. continue = false
  144. repeat
  145. loop = 1
  146. while loop < 17 do
  147. if selectAndGetItemDetail(loop, "nameDamage") == nameDamage then
  148. return true
  149. end
  150. loop = loop + 1
  151. end
  152. print("Please put more " .. nameDamage .. " into the turtle and press ENTER!")
  153. inputString = io.read()
  154. until continue == true
  155. end
  156.  
  157. -- deprecated: will be removed soon
  158. function selectAndCheckItem(slotNumber, slotName)
  159. turtle.select(slotNumber)
  160. if turtle.getItemCount() < 2 then
  161. print("Please insert more " .. slotName .. " into slot " .. slotNumber)
  162. while turtle.getItemCount() < 2 do
  163. os.queueEvent("randomEvent")
  164. os.pullEvent()
  165. end
  166. end
  167. end
  168.  
  169. function checkFuel()
  170. while turtle.getFuelLevel() <= 0 do
  171. print("No fuel left, going to refuel...")
  172. selectItemByNameDamage(fuelSlot)
  173. turtle.refuel(turtle.getItemCount())
  174. print("Fuelled turtle. New fuel level: " .. turtle.getFuelLevel())
  175. end
  176. end
  177.  
  178. --[[ moves like turtle.forward(), back(), up(), down() but additionally checks
  179. if there is a mob in its way ]]
  180. function moveTurtle(direction)
  181. movement = false
  182. while (not turtle.inspect() and not movement) do
  183. if direction == "forward" then
  184. movement = turtle.forward()
  185. elseif direction == "back" then
  186. movement = turtle.back()
  187. elseif direction == "up" then
  188. movement = turtle.up()
  189. elseif direction == "down" then
  190. movement = turtle.down()
  191. else
  192. print("Unknown movement! (" .. movement .. ")")
  193. return false
  194. end
  195.  
  196. if not movement then
  197. turtle.attack()
  198. print("Attack!!!")
  199. end
  200. end
  201. end
  202.  
  203. function checkYesOrNo()
  204. input = io.read()
  205. if input == "y" then
  206. return true
  207. else
  208. return false
  209. end
  210. end
  211.  
  212. repeat
  213.  
  214. -- fuelSlot - Put coal or lava bucket into this slot!
  215. print("\nSelect fuel slot: ")
  216. fuelSlot = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
  217. print(" Selected: " .. fuelSlot)
  218.  
  219. -- room width
  220. write("\nRoom width in blocks: ")
  221. roomWidth = tonumber(io.read())
  222.  
  223. -- room length
  224. write("\nRoom length in blocks: ")
  225. roomLength = tonumber(io.read())
  226.  
  227. -- room height
  228. write("\nRoom height in blocks: ")
  229. roomHeight = tonumber(io.read())
  230.  
  231. print("\n\n-> Viewpoint is the position of the turtle!")
  232.  
  233. print("\n\nShould I build the blanket (wall on top) for you? y/N: ")
  234. if (checkYesOrNo()) then
  235. print("\n\nMaterial slot for the blanket (wall on top):")
  236. wallMaterialTop = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
  237. print(" Selected: " .. wallMaterialTop)
  238. Blanket = true
  239. end
  240.  
  241. print("\n\nShould I build the floor for you? y/N: ")
  242. if (checkYesOrNo()) then
  243. print("\nMaterial slot for the floor (wall at the bottom):")
  244. wallMaterialBottom = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
  245. print(" Selected: " .. wallMaterialBottom)
  246. Floor = true
  247. end
  248.  
  249. print("\n\nShould I build the front wall for you? y/N: ")
  250. if (checkYesOrNo()) then
  251. print("\nMaterial slot for the front wall:")
  252. wallMaterialFront = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
  253. print(" Selected: " .. wallMaterialFront)
  254. FrontWall = true
  255. end
  256.  
  257. print("\n\nShould I build the back wall for you? y/N: ")
  258. if (checkYesOrNo()) then
  259. print("\nMaterial slot for the back wall:")
  260. wallMaterialBack = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
  261. print(" Selected: " .. wallMaterialBack)
  262. BackWall = true
  263. end
  264.  
  265. print("\n\nShould I build the left wall for you? y/N: ")
  266. if (checkYesOrNo()) then
  267. print("\nMaterial slot for the left wall:")
  268. wallMaterialLeft = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
  269. print(" Selected: " .. wallMaterialLeft)
  270. LeftWall = true
  271. end
  272.  
  273. print("\n\nShould I build the right wall for you? y/N: ")
  274. if (checkYesOrNo()) then
  275. print("\nMaterial slot for the right wall:")
  276. wallMaterialRight = selectAndGetItemDetail(selectItemSlot(), "nameDamage")
  277. print(" Selected: " .. wallMaterialRight)
  278. end
  279.  
  280. textutils.slowPrint("\n\nEnter 'y' to start building or any other key to repeat.")
  281. startJob = string.lower(io.read())
  282.  
  283. until startJob == "y"
  284.  
  285. textutils.slowPrint("Starting... Go away and dont block the Turtle!!!")
  286.  
  287. for totalLength = 1, roomLength, 1 do
  288. print("Mining in row " .. totalLength)
  289. checkFuel()
  290.  
  291. --
  292. for totalWidth = 1, roomWidth, 1 do
  293.  
  294. for totalHeight = 1, roomHeight, 1 do
  295.  
  296. -- wall on the left side
  297. if totalWidth == 1 then
  298. turtle.turnLeft()
  299. selectItemByNameDamage(wallMaterialLeft)
  300. digAndPlaceBlock("")
  301. turtle.turnRight()
  302. end
  303.  
  304. -- wall on the right side
  305. if totalWidth == roomWidth then
  306. turtle.turnRight()
  307. selectItemByNameDamage(wallMaterialRight)
  308. digAndPlaceBlock("")
  309. turtle.turnLeft()
  310. end
  311.  
  312. -- wall at the bottom
  313. if totalHeight == 1 then
  314. selectItemByNameDamage(wallMaterialBottom)
  315. digAndPlaceBlock("down")
  316. end
  317.  
  318. -- wall on top
  319. if totalHeight == roomHeight then
  320. selectItemByNameDamage(wallMaterialTop)
  321. digAndPlaceBlock("up")
  322. end
  323.  
  324. -- wall on the back
  325. if totalLength == 1 then
  326. turtle.turnLeft()
  327. turtle.turnLeft()
  328. selectItemByNameDamage(wallMaterialBack)
  329. digAndPlaceBlock("")
  330. turtle.turnRight()
  331. turtle.turnRight()
  332. end
  333.  
  334. -- wall on the front
  335. if totalLength == roomLength then
  336. selectItemByNameDamage(wallMaterialFront)
  337. digAndPlaceBlock("")
  338. end
  339.  
  340. if totalLength ~= roomLength then
  341. -- destroy block(s)
  342. digBlocks()
  343. end
  344.  
  345. -- go up if not last operation
  346. if totalHeight < roomHeight then
  347. digBlocksUp()
  348. moveTurtle("up")
  349. end
  350. end
  351.  
  352. -- go to primary position
  353. for totalHeight = 1, roomHeight - 1, 1 do
  354. digBlocksDown()
  355. moveTurtle("down")
  356. end
  357.  
  358. -- next column
  359. if totalWidth < roomWidth then
  360. turtle.turnRight()
  361. digBlocks()
  362. moveTurtle("forward")
  363. turtle.turnLeft()
  364. end
  365.  
  366. end
  367.  
  368. -- go to primary position
  369. turtle.turnLeft()
  370. for totalWidth = 1, roomWidth - 1, 1 do
  371. digBlocks()
  372. moveTurtle("forward")
  373. end
  374.  
  375. turtle.turnRight()
  376.  
  377. digBlocks()
  378. moveTurtle("forward")
  379. end
  380.  
  381. -- go to primary position
  382. for totalLength = 1, roomLength - 1, 1 do
  383. moveTurtle("back")
  384. end
  385.  
  386. print("room finished!")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement