Advertisement
macbmacb

Untitled

Feb 17th, 2019
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.06 KB | None | 0 0
  1.  
  2. local robot = require("robot")
  3. local sides = require("sides")
  4. local component = require("component")
  5.  
  6. local ic = component.inventory_controller
  7.  
  8. local cmwalls = "compactmachines3:wallbreakable"
  9.  
  10. function index_inventory()
  11. local chest_size = ic.getInventorySize(sides.top)
  12. local item_index = {}
  13. for i=1,chest_size do
  14. item = ic.getStackInSlot(sides.top, i)
  15. if item then
  16. item_index[item.name] = i
  17. end
  18. end
  19. return item_index
  20. end
  21.  
  22. function craft_wall()
  23. item_index = index_inventory()
  24. robot.select(1)
  25. ic.suckFromSlot(sides.top, item_index["minecraft:iron_block"], 1)
  26. robot.select(2)
  27. ic.suckFromSlot(sides.top, item_index["minecraft:redstone"], 2)
  28.  
  29. robot.forward()
  30. robot.forward()
  31. robot.forward()
  32. robot.select(1)
  33. robot.place()
  34. robot.up()
  35. robot.select(2)
  36. robot.place()
  37. robot.down()
  38. robot.back()
  39. robot.back()
  40. robot.back()
  41. robot.drop(1)
  42. robot.back()
  43.  
  44. os.sleep(1)
  45.  
  46. robot.forward()
  47. robot.forward()
  48. robot.forward()
  49. while true do
  50. robot.select(1)
  51. done = robot.suck()
  52. if done then
  53. break
  54. end
  55. end
  56. robot.back()
  57. robot.back()
  58. robot.back()
  59. ic.dropIntoSlot(sides.down, 1)
  60. return true
  61. end
  62.  
  63. function index_robot_inventory()
  64. local chest_size = robot.inventorySize()
  65. local item_index = {}
  66. for i=1,chest_size do
  67. item = ic.getStackInInternalSlot(i)
  68. if item then
  69. item_index[item.name] = i
  70. end
  71. end
  72. return item_index
  73. end
  74.  
  75.  
  76. function selectMachineWall()
  77. current_item = ic.getStackInInternalSlot(robot.select())
  78. if current_item and current_item.name == cmwalls then
  79. return
  80. end
  81.  
  82. local item_index = index_robot_inventory()
  83. robot.select(item_index[cmwalls])
  84. end
  85.  
  86. function placeMachineWall(side)
  87. selectMachineWall()
  88. robot.place(side)
  89. end
  90.  
  91. function placeMiddleSections()
  92. placeMachineWall()
  93. robot.back()
  94. placeMachineWall()
  95. robot.back()
  96. placeMachineWall()
  97. robot.back()
  98. placeMachineWall()
  99. robot.back()
  100. placeMachineWall()
  101.  
  102. for i=1,3 do
  103. robot.up()
  104. robot.turnAround()
  105. robot.back()
  106. robot.back()
  107. placeMachineWall()
  108. robot.back()
  109. robot.back()
  110. robot.back()
  111. robot.back()
  112. placeMachineWall()
  113. end
  114.  
  115. robot.up()
  116. robot.turnAround()
  117. robot.back()
  118. robot.back()
  119. placeMachineWall()
  120. robot.back()
  121. placeMachineWall()
  122. robot.back()
  123. placeMachineWall()
  124. robot.back()
  125. placeMachineWall()
  126. robot.back()
  127. placeMachineWall()
  128.  
  129. robot.up()
  130. robot.turnAround()
  131. robot.back()
  132. robot.back()
  133. end
  134.  
  135. function craft_large_machine()
  136. item_index = index_inventory()
  137. ic.suckFromSlot(sides.top, item_index["minecraft:emerald_block"], 1)
  138. while true do
  139. if not item_index[cmwalls] then
  140. break
  141. end
  142.  
  143. moved = ic.suckFromSlot(sides.top, item_index[cmwalls], 64)
  144. if moved then
  145. item_index = index_inventory()
  146. else
  147. break
  148. end
  149. end
  150. ic.suckFromSlot(sides.top, item_index["minecraft:ender_pearl"], 1)
  151.  
  152. robot.forward()
  153. robot.forward()
  154. robot.forward()
  155. robot.forward()
  156. robot.forward()
  157. robot.forward()
  158.  
  159. robot.turnLeft()
  160. robot.forward()
  161.  
  162. -- back wall
  163. for i=1,5 do
  164. placeMachineWall()
  165. robot.back()
  166. placeMachineWall()
  167. robot.back()
  168. placeMachineWall()
  169. robot.back()
  170. placeMachineWall()
  171. robot.back()
  172. placeMachineWall()
  173. robot.up()
  174. robot.turnAround()
  175. robot.back()
  176. robot.back()
  177. end
  178.  
  179. robot.turnRight()
  180. robot.forward()
  181. robot.turnLeft()
  182. robot.down()
  183. robot.down()
  184. robot.down()
  185. robot.down()
  186. robot.down()
  187.  
  188. placeMiddleSections()
  189.  
  190. robot.turnLeft()
  191. robot.forward()
  192. robot.turnRight()
  193. robot.down()
  194. robot.down()
  195. robot.down()
  196. robot.down()
  197. robot.down()
  198.  
  199. placeMiddleSections()
  200.  
  201. robot.turnRight()
  202. robot.forward()
  203. robot.turnLeft()
  204. robot.down()
  205. robot.down()
  206. robot.down()
  207. robot.down()
  208. robot.down()
  209.  
  210. placeMiddleSections()
  211.  
  212. robot.turnLeft()
  213. robot.forward()
  214. robot.turnRight()
  215. robot.down()
  216. robot.down()
  217. robot.down()
  218. robot.down()
  219. robot.down()
  220.  
  221. for i=1,5 do
  222. placeMachineWall()
  223. robot.back()
  224. placeMachineWall()
  225. robot.back()
  226. placeMachineWall()
  227. robot.back()
  228. placeMachineWall()
  229. robot.back()
  230. placeMachineWall()
  231. robot.up()
  232. robot.turnAround()
  233. robot.back()
  234. robot.back()
  235. end
  236.  
  237. robot.back()
  238. robot.turnLeft()
  239. robot.back()
  240. robot.down()
  241. robot.down()
  242. robot.down()
  243. robot.down()
  244.  
  245. robot.swing()
  246. robot.forward()
  247. robot.forward()
  248. placeMachineWall()
  249. robot.up()
  250.  
  251. robot_inventory = index_robot_inventory()
  252. robot.select(robot_inventory["minecraft:emerald_block"])
  253. robot.place()
  254.  
  255. robot.down()
  256. robot.swing()
  257. robot.back()
  258. robot.back()
  259. placeMachineWall()
  260.  
  261. robot.down()
  262.  
  263. -- Finishing up
  264. robot_inventory = index_robot_inventory()
  265. robot.select(robot_inventory["minecraft:ender_pearl"])
  266. robot.drop()
  267. robot.back()
  268.  
  269. os.sleep(1)
  270.  
  271. robot.forward()
  272. robot.forward()
  273. robot.forward()
  274. while true do
  275. robot.select(1)
  276. done = robot.suck()
  277. if done then
  278. break
  279. end
  280. end
  281. robot.back()
  282. robot.back()
  283. robot.back()
  284. ic.dropIntoSlot(sides.down, 1)
  285. return true
  286. end
  287.  
  288. while true do
  289. print("Checking chest for items.")
  290. local item_index = index_inventory()
  291. if item_index["minecraft:iron_block"] then
  292. print("Found an iron block, making compact machine walls.")
  293. done = craft_wall()
  294. if done then
  295. print("Finished crafting walls.")
  296. end
  297. elseif item_index["minecraft:emerald_block"] then
  298. print("Found an emerald block, making a large compact machine.")
  299. done = craft_large_machine()
  300. if done then
  301. print("Finished crafting large compact machine.")
  302. end
  303. else
  304. print("No items found, sleeping.")
  305. os.sleep(1)
  306. end
  307. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement