Wiiplay123

Ultimate Program for ComputerCraft

Jan 20th, 2018
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 37.89 KB | None | 0 0
  1. --[[
  2.  
  3. INSTRUCTIONS:
  4.  
  5. Turtle must have pickaxe on right side, and crafting table on left side.
  6. Place single chests in front of and on top of turtle.
  7. Place a single hopper to the left of front chest.
  8. Place a furnace under the turtle.
  9. Place a hopper behind furnace.
  10. Place a single redstone dust in front of the furnace.
  11. Place a single pressure plate in front of the redstone dust.
  12. Add to instructions as more requirements are added.
  13.  
  14.  
  15. VALUE DOCUMENTATION:
  16.  
  17. minFuel (number): Minimum fuel allowed in furnace before refuelling
  18. chests (table): External Chest Cache
  19. turtleInventory (table): Internal Inventory Cache
  20. inventorySize (number): Internal Inventory Size
  21. inv (number): Main Buffer Chest Size
  22. slots (table): List of crafting slots
  23. craftingRecipes (table): List of crafting recipes. Key is item name to be crafted, value is a table of either {itemCount,(1-9 itemName of items to place in crafting grid)} or {itemCount, {Item Names}, {Keys to previous item name table}}.
  24. furnaceRecipes (table): List of furnace recipes. Key is resulting item name, value is item name to be smelted/cooked.
  25. miners (number): Amount of active turtle miners
  26.  
  27.  
  28. FUNCTION DOCUMENTATION:
  29.  
  30. notCrafting(slot: number) (Returns boolean): Returns whether or not (slot) is a crafting slot.
  31. turnAround() (Returns nil): Does turtle.turnLeft() twice.
  32. updateInternalInventory([slot: number]) (Returns nil): Updates internal inventory cache table (turtleInventory) slot (slot), or if (slot) is absent, updates entire table.
  33. checkUp(chestIndex: number, [itemName: string, itemCount: number]) (Returns nil if itemName and itemCount exist, returns table containing chest contents otherwise) return: Updates chests[chestIndex] with the contents of the chest currently above the turtle. If itemName and itemCount are BOTH present, will only update for places that the items could possibly be placed in since the last cache update. (Used IMMEDIATELY after dropping anything into a chest)
  34. itemCount(itemName: string) (Returns number): Returns combined amount of (itemName) in both (turtleInventory) and (chests).
  35. checkIfEmptyInventory() (Returns boolean): Checks if turtle's internal inventory is empty. (not counting crafting slots)
  36. emptyBufferChest() (Returns boolean): Checks if buffer chest is empty.
  37. clearInventory([dontClearOne: boolean]) (Returns nil): Puts entire internal inventory (Unless dontClearOne is true, in which case everything except slot 1) into chests, and changes (turtleInventory) and (chests) contents to match.
  38. nearestBuffer([itemName: string]) (Returns number): Returns lowest internal inventory slot that can hold (itemName), or the lowest empty slot if itemName is not set.
  39. stockInventory([dontClearOne: boolean]) (Returns nil): Fills inventory with contents of buffer chest. If inventory is full, calls clearInventory([dontClearOne: boolean]) to clear inventory. Repeats until buffer chest is empty.
  40. pullItemFromStorage(itemName: string, itemCount: number) (Returns number): Pulls item from external chest inventory if item is not already in internal inventory. Returns and selects slot number item is in once item is in internal inventory.
  41. checkTotalInventoryCapacity() (Returns number): Returns amount of empty slots left in external chest inventory.
  42. canCraft(itemName: string, itemCount: number) (Returns boolean): Returns whether or not (itemCount) of (itemName) can be crafted using the contents of the internal and external inventories.
  43. minStack(coalAvailable: number, coalInFuelSlot: number) (Returns number): Returns the lowest of (coalAvailable) or (64 - coalInFuelSlot) (The amount of coal that can be placed into the furnace's fuel slot).
  44. mergeStack(itemName: string) (Returns nil): Merges all stacks of (itemName) in internal inventory to the lowest amount of stacks possible.
  45. notInList(list: table, string: string) (Returns boolean): Returns true if (string) is not in (list), false otherwise.
  46. mergeStacks() (Returns nil): Merges all stacks in internal inventory to the lowest amount of stacks possible using mergeStack(itemName: string).
  47. checkFurnaceFuel() (Returns nil): Refuels furnace below turtle if fuel is below (minFuel).
  48. clearCrafting() (Returns nil): Clears crafting slots.
  49. craft(itemName: string, itemCount: number) (Returns boolean): Puts (itemCount) of (itemName) into lowest available slot. If items are already available in internal inventory, will select slot. If not, will use pullItemFromStorage(itemName, itemCount) to pull more items in. If there are not enough items in external inventory, will craft the required items.
  50. pushItemToStorage(slot: number) (Returns nil): Puts items in (slot) into external inventory.
  51. updateAllChests()
  52. digAndUpdate(direction: string) (Returns nil): Direction can be nil, "up", or "down". Digs a block if it exists, and puts it in the inventory cache. Selects previously selected slot afterwards.
  53. makePickaxe(i: number) (Returns nil): Helper function for addNewChest(), crafts pickaxe if one isn't already available and then moves forward.
  54. addNewMiner() (Returns nil): Adds new miner and increments (miners) if successful
  55. addNewChest() (Returns nil): Adds new external chest to external chest inventory and updates (chests) to match.
  56. getItemName() (Returns (string, number) or (string) or (nil)): Returns "exit"
  57. canCraftInstance(itemRecipe: table, itemCount: number) (Returns boolean): Returns whether or not (itemCount) of item with (itemRecipe) recipe can be made. Helper function to canCraft() and craft().
  58. ]]
  59. if peripheral == nil then
  60. error("Program is only designed for ComputerCraft.",0)
  61. end
  62. local cautious = true
  63. local makeMiners = false
  64. local ironChests = true
  65. local checkingFuel = false
  66. local minFuel = 5
  67. local minTurtleFuel = 1600
  68. local inventorySize = 16
  69. --local turtleInventory = {}
  70. turtleInventory = {}
  71. --local chests = {}
  72. chests = {}
  73. local inv = peripheral.call("front","getInventorySize")
  74. if inv == nil then
  75. repeat
  76. turtle.turnLeft()
  77. inv = peripheral.call("front","getInventorySize")
  78. until inv
  79. end
  80. local slots = {1,2,3,5,6,7,9,10,11}
  81. local craftingRecipes = {
  82. ["minecraft:planks"] = {4,"minecraft:log"},
  83. ["Natura:planks"] = {4,"Natura:tree"},
  84. ["minecraft:stick"] = {4,"minecraft:planks","","","minecraft:planks"},
  85. ["IronChest:woodIronUpgrade"] = {{1,{"minecraft:iron_ingot","minecraft:planks"},{1,1,1,1,2,1,1,1,1}},{1,{"minecraft:iron_ingot","Natura:planks"},{1,1,1,1,2,1,1,1,1}}},
  86. ["IronChest:ironGoldUpgrade"] = {1,{"minecraft:gold_ingot","minecraft:iron_ingot"},{1,1,1,1,2,1,1,1,1}},
  87. ["IronChest:goldDiamondUpgrade"] = {1,{"minecraft:glass","minecraft:diamond","minecraft:gold_ingot"},{1,1,1,2,3,2,1,1,1}},
  88. ["minecraft:glass_pane"] = {16,{"minecraft:glass"},{1,1,1,1,1,1}},
  89. ["ComputerCraft:CC-Computer"] = {1,{"minecraft:stone","minecraft:redstone","minecraft:glass_pane"},{1,1,1,1,2,1,1,3,1}},
  90. ["ComputerCraft:CC-Turtle"] = {1,{"minecraft:iron_ingot","ComputerCraft:CC-Computer","minecraft:chest"},{1,1,1,1,2,1,1,3,1}},
  91. ["ComputerCraft:CC-Peripheral"] = {1,{"minecraft:stone","minecraft:redstone"},{1,1,1,1,2,1,1,2,1}},
  92. ["minecraft:chest"] = {{1,{"Natura:planks"},{1,1,1,1,0,1,1,1,1}},{1,{"minecraft:planks"},{1,1,1,1,0,1,1,1,1}}},
  93. ["minecraft:furnace"] = {1,{"minecraft:cobblestone"},{1,1,1,1,0,1,1,1,1}},
  94. ["minecraft:enchanting_table"] = {1,{"minecraft:book","minecraft:diamond","minecraft:obsidian"},{0,1,0,2,3,2,3,3,3}},
  95. ["tile.chickenchunkloader|0"] = {1,{"minecraft:ender_pearl","minecraft:gold_ingot","minecraft:enchanting_table"},{0,1,0,2,2,2,2,3,2}},
  96. ["tile.chickenchunkloader|1"] = {10,{"minecraft:ender_pearl","tile.chickenchunkloader|0"},{1,1,1,1,2,1,1,1,1}},
  97. ["tile.computercraft:wireless_modem"] = {1,{"minecraft:stone","minecraft:ender_pearl"},{1,1,1,1,2,1,1,1,1}},
  98. ["PeripheralsPlusPlus:chunkLoaderUpgrade"] = {1,"tile.chickenchunkloader|1","tile.computercraft:wireless_modem"},
  99. ["minecraft:diamond_pickaxe"] = {1,{"minecraft:diamond","minecraft:stick"},{1,1,1,0,2,0,0,2}},
  100. ["minecraft:iron_pickaxe"] = {1,{"minecraft:iron_ingot","minecraft:stick"},{1,1,1,0,2,0,0,2}},
  101. --["ComputerCraft:CC-TurtleExpanded"] = {1,"minecraft:diamond_pickaxe","ComputerCraft:CC-Turtle","PeripheralsPlusPlus:chunkLoaderUpgrade"},
  102. ["ComputerCraft:CC-TurtleExpanded"] = {1,"minecraft:diamond_pickaxe","ComputerCraft:CC-Turtle"},
  103. --["usefulDNS:PStone"] = {1,{"minecraft:redstone","minecraft:glowstone_dust","usefulDNS:DecaNySodiumGem"},{1,2,1,2,3,2,1,2,1}},
  104. --["ProjectE:item.pe_philosophers_stone"] = {1,{"minecraft:redstone","minecraft:glowstone_dust","minecraft:diamond"},{1,2,1,2,3,2,1,2,1}},
  105. --["minecraft:ender_pearl"] = {1,{"usefulDNS:PStone","minecraft:iron_ingot"},{1,2,0,2,2,0,2}},
  106. --["minecraft:diamond"] = {1,{"usefulDNS:PStone","minecraft:gold_ingot"},{1,2,0,2,2,0,2}},
  107. --["minecraft:sand"] = {1,"usefulDNS:PStone","minecraft:cobblestone","","","minecraft:cobblestone"},
  108. ["minecraft:stone_slab"] = {6,{"minecraft:stone"},{1,1,1}},
  109. ["minecraft:hopper"] = {1,{"minecraft:iron_ingot","minecraft:chest"},{1,0,1,1,2,1,0,1,0}},
  110. ["ComputerCraft:pocketComputer"] = {1,{"minecraft:gold_ingot","minecraft:golden_apple","minecraft:glass_pane"},{1,1,1,1,2,1,1,3,1}},
  111. ["minecraft:golden_apple"] = {1,{"minecraft:gold_ingot","minecraft:apple"},{1,1,1,1,2,1,1,1,1}},
  112. ["OpenPeripheral:pim"] = {1,{"minecraft:obsidian","minecraft:chest","minecraft:redstone"},{1,1,1,2,3,2}}
  113. }
  114. local furnaceRecipes = {
  115. ["minecraft:stone"] = "minecraft:cobblestone",
  116. ["minecraft:iron_ingot"] = "minecraft:iron_ore",
  117. ["minecraft:gold_ingot"] = "minecraft:gold_ore",
  118. ["minecraft:glass"] = "minecraft:sand",
  119. ["minecraft:cooked_chicken"] = "minecraft:chicken",
  120. ["minecraft:cooked_porkchop"] = "minecraft:porkchop",
  121. ["minecraft:cooked_beef"] = "minecraft:beef",
  122. ["minecraft:cooked_fished"] = "minecraft:fish"
  123. }
  124.  
  125. function notCrafting(s)
  126. return s > 11 or s == 4 or s == 8
  127. end
  128.  
  129. function turnAround()
  130. turtle.turnLeft()
  131. turtle.turnLeft()
  132. end
  133.  
  134. function checkFuel()
  135. if not checkingFuel then
  136. checkingFuel = true
  137. local fuel = turtle.getFuelLevel()
  138. local count = itemCount("minecraft:coal")
  139. if fuel ~= "unlimited" and fuel < minTurtleFuel and count > 0 then
  140. local slot = pullItemFromStorage("minecraft:coal",(count >= 64 and 64 or itemCount("minecraft:coal")))
  141. if slot > 0 then
  142. if turtle.refuel(64) then
  143. turtleInventory[slot] = nil
  144. else
  145. updateInternalInventory()
  146. end
  147. end
  148. end
  149. checkingFuel = false
  150. end
  151. end
  152.  
  153. function updateInternalInventory(n)
  154. if n then
  155. turtleInventory[n] = turtle.getItemDetail(n)
  156. if turtleInventory[n] then
  157. turtleInventory[n].maxSize = turtle.getItemSpace(n) + turtleInventory[n].count
  158. end
  159. else
  160. turtleInventory = {}
  161. for i = 4, inventorySize do
  162. if notCrafting(i) then
  163. turtleInventory[i] = turtle.getItemDetail(i)
  164. if turtleInventory[i] then
  165. turtleInventory[i].maxSize = turtle.getItemSpace(i) + turtleInventory[i].count
  166. end
  167. end
  168. end
  169. end
  170. end
  171.  
  172. function checkUp(ix,id,count)
  173. if chests and ix and ix <= #chests then
  174. local oldSize = 0
  175. if ix and id and chests[ix] and chests[ix]["stacks"] and count then
  176. oldSize = chests[ix]["size"]
  177. chests[ix].size = peripheral.call("top","getInventorySize")
  178. end
  179. if (oldSize == chests[ix]["size"]) and id and count then
  180. local cacheCount = 0
  181. for i = 1, chests[ix]["size"] do
  182. if not chests[ix]["stacks"][i] or chests[ix]["stacks"][i].id == id then
  183. local oldSlot = (chests[ix]["stacks"][i] or {id = "", qty = 0})
  184. chests[ix]["stacks"][i] = peripheral.call("top","getStackInSlot",i)
  185. if chests[ix]["stacks"][i] and (oldSlot.id == chests[ix]["stacks"][i].id or oldSlot.qty == 0) then
  186. cacheCount = cacheCount + chests[ix]["stacks"][i].qty - oldSlot.qty
  187. if cacheCount >= count then
  188. break
  189. end
  190. end
  191. end
  192. end
  193. else
  194. chests[ix] = checkUp()
  195. end
  196. else
  197. local stacks = {}
  198. local size = peripheral.call("top","getInventorySize")
  199. if size then
  200. for i = 1, size do
  201. stacks[i] = peripheral.call("top","getStackInSlot",i)
  202. end
  203. return {["stacks"] = stacks,["size"] = size}
  204. else
  205. return false
  206. end
  207. end
  208. end
  209.  
  210. function itemCount(id)
  211. local count = 0
  212. for i = 4, inventorySize do
  213. if notCrafting(i) then
  214. local slot = turtleInventory[i]
  215. if slot and slot.name == id then
  216. count = count + slot.count
  217. end
  218. end
  219. end
  220. for i = 1, #chests do
  221. for o, v in pairs(chests[i]["stacks"]) do
  222. if v.id == id then
  223. count = count + v.qty
  224. end
  225. end
  226. end
  227. return count
  228. end
  229.  
  230. function checkIfEmptyInventory()
  231. for i = 1, inventorySize do
  232. if turtle.getItemCount(i) > 0 then
  233. return false
  234. end
  235. end
  236. return true
  237. end
  238.  
  239. function emptyBufferChest()
  240. for i = 1, inv do
  241. if peripheral.call("front","getStackInSlot",i) then
  242. return false
  243. end
  244. end
  245. return true
  246. end
  247.  
  248. function clearInventory(dontClearOne)
  249. printTitle("Ultimate Program Running","Clearing Inventory")
  250. checkFuel()
  251. local chestz = 0
  252. local lastSlot = (dontClearOne and 2 or 1)
  253. if #chests == 1 then
  254. for i = (dontClearOne and 2 or 1), inventorySize do
  255. local inspect = turtle.getItemDetail(i)
  256. if inspect then
  257. turtle.select(i)
  258. if not turtle.dropUp() then
  259. break
  260. end
  261. checkUp(1,inspect.name,inspect.count)
  262. end
  263. end
  264. else
  265. for i = 1, #chests do
  266. for p = lastSlot, inventorySize do
  267. local detail = turtle.getItemDetail(p)
  268. if detail then
  269. turtle.select(p)
  270. if not turtle.dropUp() then
  271. updateInternalInventory()
  272. lastSlot = p
  273. chests[i] = checkUp()
  274. break
  275. end
  276. checkUp(i,detail.name,detail.count)
  277. updateInternalInventory(p)
  278. end
  279. end
  280. if i < #chests and not ((lastSlot == inventorySize) or checkIfEmptyInventory()) then
  281. if i == 1 then
  282. turtle.turnRight()
  283. end
  284. forward()
  285. forward()
  286. chestz = chestz + 1
  287. end
  288. end
  289. for i = 1, chestz do
  290. chests[chestz + 2 - i] = checkUp()
  291. repeat until back()
  292. repeat until back()
  293. end
  294. if chestz > 0 then
  295. turtle.turnLeft()
  296. end
  297. end
  298. updateInternalInventory()
  299. end
  300.  
  301. function nearestBuffer(id)
  302. for i = 4, inventorySize do
  303. if notCrafting(i) and (not turtleInventory[i] or (turtleInventory[i].name == id and turtleInventory[i].count < turtleInventory[i].maxSize)) then
  304. return i
  305. end
  306. end
  307. return 0
  308. end
  309.  
  310. function stockInventory(dontClearOne)
  311. updateInternalInventory()
  312. local slot = turtle.getSelectedSlot()
  313. local selecting = false
  314. repeat
  315. --printTitle("Ultimate Program Running","Checking front chest")
  316. local breaking = false
  317. local s = false
  318. repeat
  319. if not emptyBufferChest() then
  320. turtle.select(1)
  321. selecting = true
  322. else
  323. break
  324. end
  325. if not turtle.suck() then
  326. break
  327. else
  328. s = true
  329. end
  330. until emptyBufferChest()
  331. updateInternalInventory()
  332. if s then clearCrafting() end
  333. if slotsLeft() < 4 or nearestBuffer() == 0 then
  334. clearInventory(dontClearOne)
  335. updateInternalInventory()
  336. end
  337. until emptyBufferChest()
  338. if selecting then
  339. turtle.select(slot)
  340. end
  341. end
  342.  
  343. function pullItemFromStorage(id,count)
  344. checkFuel()
  345. local allTotal = 0
  346. local intoSlot = 0
  347. for i = 1, inventorySize do
  348. if notCrafting(i) then
  349. local tempSlot = turtleInventory[i]
  350. if tempSlot and tempSlot.name == id then
  351. if intoSlot == 0 then
  352. allTotal = allTotal + turtleInventory[i].count
  353. intoSlot = i
  354. turtle.select(intoSlot)
  355. else
  356. turtle.select(i)
  357. allTotal = allTotal + turtleInventory[i].count
  358. turtle.transferTo(intoSlot)
  359. if turtleInventory[intoSlot].count + turtleInventory[i].count > turtleInventory[intoSlot].maxSize then
  360. turtleInventory[i].count = turtleInventory[i].count - (turtleInventory[intoSlot].maxSize - turtleInventory[intoSlot].count)
  361. turtleInventory[intoSlot].count = turtleInventory[intoSlot].maxSize
  362. else
  363. turtleInventory[intoSlot].count = turtleInventory[intoSlot].count + turtleInventory[i].count
  364. turtleInventory[i] = nil
  365. end
  366. end
  367. if allTotal >= count then
  368. turtle.select(intoSlot)
  369. return intoSlot
  370. end
  371. end
  372. end
  373. end
  374. if intoSlot == 0 then
  375. repeat
  376. intoSlot = nearestBuffer(id)
  377. if intoSlot == 0 then
  378. stockInventory()
  379. end
  380. until intoSlot > 0
  381. end
  382. local chestTotal = {}
  383. local moves = 0
  384. local needsToMove = false
  385. for i = 1, #chests do
  386. chestTotal[i] = 0
  387. for o, p in pairs(chests[i]["stacks"]) do
  388. if p.id == id then
  389. allTotal = allTotal + p.qty
  390. chestTotal[i] = chestTotal[i] + p.qty
  391. if i > 1 then
  392. needsToMove = true
  393. end
  394. if allTotal >= count then
  395. break
  396. end
  397. end
  398. end
  399. end
  400. if needsToMove then
  401. turtle.turnRight()
  402. end
  403. turtle.select(intoSlot)
  404. local done = false
  405. for i = 1, #chestTotal do
  406. if chestTotal[i] > 0 then
  407. for o, p in pairs(chests[i]["stacks"]) do
  408. local newCount = (turtleInventory[intoSlot] and turtleInventory[intoSlot].count or 0)
  409. if newCount >= count then
  410. done = true
  411. break
  412. end
  413. if p.id == id then
  414. peripheral.call("top","pushItemIntoSlot","down",o,count - newCount,intoSlot)
  415. updateInternalInventory(intoSlot)
  416. if p.qty <= count - newCount then
  417. chests[i] = checkUp()
  418. done = p.qty == count - newCount
  419. if done then break end
  420. else
  421. chests[i]["stacks"][o].qty = p.qty - count - newCount
  422. break
  423. end
  424. end
  425. end
  426. end
  427. if done then
  428. break
  429. elseif needsToMove and i < #chestTotal and not done then
  430. bulldoze(2)
  431. moves = moves + 1
  432. end
  433. end
  434. if needsToMove then
  435. for i = 1, moves do
  436. repeat until back()
  437. repeat until back()
  438. end
  439. turtle.turnLeft()
  440. end
  441. return intoSlot
  442. end
  443.  
  444. function checkTotalInventoryCapacity()
  445. local itemsLeft = 0
  446. for i = 1, #chests do
  447. itemsLeft = itemsLeft + chests[i]["size"] - #chests[i]["stacks"]
  448. end
  449. return itemsLeft
  450. end
  451.  
  452. function canCraftInstance(v,count)
  453. local items = {}
  454. if type(v[2]) == "table" then
  455. for o = 1, #v[3] do
  456. if v[3][o] > 0 then
  457. if items[v[2][v[3][o]]] == nil then
  458. items[v[2][v[3][o]]] = 0
  459. end
  460. items[v[2][v[3][o]]] = items[v[2][v[3][o]]] + (1/v[1])
  461. end
  462. end
  463. for o, p in pairs(items) do
  464. items[o] = items[o]*math.ceil(count/v[1])*v[1]
  465. end
  466. else
  467. for o = 2, #v do
  468. if v[o] ~= "" then
  469. if items[v[o]] == nil then
  470. items[v[o]] = 0
  471. end
  472. items[v[o]] = items[v[o]] + 1
  473. end
  474. end
  475. end
  476. for o, p in pairs(items) do
  477. if not canCraft(o,p) then
  478. return false
  479. end
  480. end
  481. return true
  482. end
  483.  
  484. function canCraft(id,count)
  485. local currentCount = 0
  486. currentCount = currentCount + itemCount(id)
  487. if currentCount >= count then
  488. return true
  489. end
  490. if furnaceRecipes[id] then
  491. currentCount = currentCount + itemCount(furnaceRecipes[id])
  492. if currentCount >= count then
  493. return true
  494. end
  495. end
  496. if craftingRecipes[id] then
  497. local v = craftingRecipes[id]
  498. if type(v[1]) == "table" then
  499. for first, second in pairs(craftingRecipes[id]) do
  500. local v = second
  501. if canCraftInstance(second,count) then
  502. return true
  503. else
  504. print("Could not craft "..count.." of "..id)
  505. sleep(1)
  506. end
  507. end
  508. else
  509. if canCraftInstance(v,count) then
  510. return true
  511. else
  512. print("Could not craft "..count.." of "..id)
  513. sleep(1)
  514. end
  515. end
  516. end
  517. return currentCount >= count
  518. end
  519. function minStack(id,qty)
  520. if 64 - qty > id then
  521. return id
  522. else
  523. return 64 - qty
  524. end
  525. end
  526. function mergeStack(name)
  527. local intoSlot = 0
  528. for i = 1, inventorySize do
  529. if turtleInventory[i] then
  530. local v = turtleInventory[i]
  531. if v.name == name then
  532. if intoSlot == 0 and v.count < v.maxSize then
  533. intoSlot = i
  534. else
  535. if intoSlot ~= 0 and v.count < v.maxSize then
  536. turtle.select(i)
  537. if turtle.transferTo(intoSlot) then
  538. if turtleInventory[intoSlot].count + turtleInventory[i].count > turtleInventory[intoSlot].maxSize then
  539. turtleInventory[i].count = turtleInventory[i].count - (turtleInventory[intoSlot].maxSize - turtleInventory[intoSlot].count)
  540. turtleInventory[intoSlot].count = turtleInventory[intoSlot].maxSize
  541. intoSlot = i
  542. else
  543. turtleInventory[intoSlot].count = turtleInventory[intoSlot].count + turtleInventory[i].count
  544. turtleInventory[i] = nil
  545. end
  546. end
  547. end
  548. end
  549. end
  550. end
  551. end
  552. end
  553. function notInList(list,str)
  554. for i, v in pairs(list) do
  555. if str == v then
  556. return false
  557. end
  558. end
  559. return true
  560. end
  561. function mergeStacks()
  562. local names = {}
  563. for i = 1, inventorySize do
  564. if turtleInventory[i] then
  565. if notInList(names,turtleInventory[i].name) then
  566. table.insert(names,turtleInventory[i].name)
  567. end
  568. end
  569. end
  570. for i = 1, #names do
  571. mergeStack(names[i])
  572. end
  573. end
  574.  
  575. function rf()
  576. turtle.turnLeft()
  577. turtle.turnRight()
  578. end
  579.  
  580. function checkFurnaceFuel()
  581. printTitle("Ultimate Program Running","Checking furnace fuel")
  582. sleep(0.1)
  583. local originalSlot = turtle.getSelectedSlot()
  584. rf()
  585. local fuelSlot = peripheral.call("bottom","getStackInSlot",2)
  586. if fuelSlot == nil or fuelSlot.qty < minFuel then
  587. fuelSlot = (fuelSlot and fuelSlot or {["qty"] = 0})
  588. local coal = itemCount("minecraft:coal")
  589. if coal - fuelSlot.qty > 0 then
  590. if minStack(coal,fuelSlot.qty) > 0 then
  591. local newSlot = pullItemFromStorage("minecraft:coal",minStack(coal,fuelSlot.qty))
  592. turnAround()
  593. turtle.drop()
  594. turnAround()
  595. turtleInventory[newSlot] = nil
  596. turtle.select(originalSlot)
  597. updateInternalInventory(newSlot)
  598. for i = 1, 50 do
  599. rf()
  600. if peripheral.call("bottom","getStackInSlot",2).qty >= minFuel then break end
  601. sleep(0.1)
  602. end
  603. end
  604. end
  605. end
  606. end
  607.  
  608. function clearCrafting()
  609. if cautious then
  610. for i = 1, #slots do
  611. local slot = turtle.getItemDetail(slots[i])
  612. if slot then
  613. local buffer = nearestBuffer(slot.name)
  614. if buffer > 0 then
  615. turtle.select(i)
  616. turtle.transferTo(buffer)
  617. if turtleInventory[buffer] ~= nil and slot.count > turtleInventory[buffer].maxSize - turtleInventory[buffer].count then
  618. stockInventory()
  619. clearCrafting()
  620. break
  621. else
  622. if turtleInventory[buffer] ~= nil then
  623. turtleInventory[buffer].count = turtleInventory[buffer].count + slot.count
  624. else
  625. updateInternalInventory(buffer)
  626. end
  627. end
  628. else
  629. stockInventory()
  630. clearCrafting()
  631. break
  632. end
  633. end
  634. end
  635. updateInternalInventory()
  636. end
  637. end
  638.  
  639. function clearFurnaceBufferChest()
  640. for i = 1, 27 do
  641. peripheral.call("front","pullItem","down",i)
  642. end
  643. end
  644.  
  645. function craft(id,count)
  646. printTitle("Ultimate Program Running","Making "..count.." "..id)
  647. -- peripheral.call("top","getInventorySize")
  648. local itc = itemCount(id)
  649. local currentCount = itc
  650. if itc > 0 then
  651. local b = nearestBuffer(id)
  652. local c = turtle.getItemCount(b)
  653. if c >= count and count > 0 then
  654. turtle.select(b)
  655. return true
  656. else
  657. if itc >= count then
  658. pullItemFromStorage(id,count)
  659. return true
  660. else
  661. pullItemFromStorage(id,itc)
  662. end
  663. end
  664. end
  665. if canCraft(id,count) then
  666. local ready = false
  667. local furnaceItem = ""
  668. if furnaceRecipes[id] then
  669. ready = true
  670. furnaceItem = furnaceRecipes[id]
  671. currentCount = currentCount + itemCount(furnaceRecipes[id])
  672. end
  673. if ready then
  674. -- Furnace stuff happens here
  675. repeat
  676. checkFurnaceFuel()
  677. rf()
  678. until not peripheral.call("bottom","getStackInSlot",1)
  679. rf()
  680. local stack = peripheral.call("bottom","getStackInSlot",3)
  681. if stack then
  682. if nearestBuffer(stack.id) == 0 then
  683. stockInventory()
  684. end
  685. local bfr = nearestBuffer(stack.id)
  686. turtle.turnRight()
  687. back()
  688. down()
  689. turtle.suck()
  690. up()
  691. forward()
  692. turtle.turnLeft()
  693. --peripheral.call("bottom","pushItem",2,3,64,bfr)
  694. updateInternalInventory(bfr)
  695. end
  696. pullItemFromStorage(furnaceRecipes[id],count)
  697. turtle.dropDown()
  698. repeat
  699. rf()
  700. checkFurnaceFuel()
  701. until not peripheral.call("bottom","getStackInSlot",1)
  702. rf()
  703. local stack = peripheral.call("bottom","getStackInSlot",3)
  704. if stack then
  705. if nearestBuffer(stack.id) == 0 then
  706. stockInventory()
  707. end
  708. local bfr = nearestBuffer(stack.id)
  709. turtle.turnRight()
  710. back()
  711. down()
  712. turtle.suck()
  713. up()
  714. forward()
  715. turtle.turnLeft()
  716. --peripheral.call("bottom","pushItem",2,3,64,bfr)
  717. updateInternalInventory(bfr)
  718. end
  719. if itemCount(id) >= count then
  720. return true
  721. end
  722. end
  723. if craftingRecipes[id] then
  724. local v = craftingRecipes[id]
  725. local items = {}
  726. if type(v[1]) == "table" then
  727. for first, second in pairs(craftingRecipes[id]) do
  728. if canCraftInstance(second,count) then
  729. v = second
  730. end
  731. end
  732. end
  733. if type(v[2]) == "table" then
  734. for o = 1, #v[3] do
  735. if v[3][o] > 0 then
  736. if items[v[2][v[3][o]]] == nil then
  737. items[v[2][v[3][o]]] = 0
  738. end
  739. items[v[2][v[3][o]]] = items[v[2][v[3][o]]] + (1/v[1])
  740. end
  741. end
  742. else
  743. for o = 2, #v do
  744. if v[o] ~= "" then
  745. if items[v[o]] == nil then
  746. items[v[o]] = 0
  747. end
  748. items[v[o]] = items[v[o]] + (1/v[1])
  749. end
  750. end
  751. end
  752. local itemsOld = items
  753. for o, p in pairs(items) do
  754. items[o] = items[o]*math.ceil(count/v[1])*v[1]
  755. end
  756. for o, p in pairs(items) do
  757. if not canCraft(o,p) then
  758. return false
  759. end
  760. end
  761. if not checkIfEmptyInventory() then
  762. clearInventory()
  763. clearCrafting()
  764. end
  765. for o, p in pairs(items) do
  766. if itemCount(o) < p then
  767. if canCraft(o,p) then
  768. craft(o,p) -- Something goes wrong here
  769. pushItemToStorage(4)
  770. else
  771. return false
  772. end
  773. end
  774. end
  775. if not checkIfEmptyInventory() then
  776. clearInventory()
  777. return craft(id,count)
  778. end
  779. for o, p in pairs(items) do
  780. local item = pullItemFromStorage(o,p)
  781. if type(v[2]) == "table" then
  782. for m = 1, #v[3] do
  783. if v[3][m] > 0 and v[2][v[3][m]] == o then
  784. turtle.transferTo(slots[m],math.ceil((1/v[1])*count))
  785. updateInternalInventory(item)
  786. updateInternalInventory(slots[m])
  787. end
  788. end
  789. else
  790. for m = 2, #v do
  791. if v[m] == o then
  792. turtle.transferTo(slots[m - 1],math.ceil((1/v[1])*count))
  793. updateInternalInventory(item)
  794. updateInternalInventory(slots[m - 1])
  795. end
  796. end
  797. end
  798. end
  799. turtle.select(4)
  800. turtle.craft()
  801. updateInternalInventory()
  802. return true
  803. end
  804. else
  805. return false
  806. end
  807. return true
  808. end
  809.  
  810. function pushItemToStorage(slotz)
  811. local pushChest = 0
  812. local originalSlot = turtle.getSelectedSlot()
  813. local slot = (slotz and slotz or originalSlot)
  814. local currentSlot = turtleInventory[slot]
  815. if originalSlot ~= slot then
  816. turtle.select(slot)
  817. end
  818. if #chests > 1 then
  819. turtle.turnRight()
  820. end
  821. for i = 1, #chests do
  822. local oldCount = turtle.getItemCount()
  823. if turtle.dropUp() then
  824. if turtle.getItemCount() == 0 then
  825. checkUp(i,currentSlot.name,oldCount)
  826. turtleInventory[slot] = nil
  827. break
  828. else
  829. checkUp(i,currentSlot.name,oldCount)
  830. end
  831. end
  832. if #chests > 1 and i < #chests then
  833. forward()
  834. forward()
  835. pushChest = pushChest + 1
  836. end
  837. end
  838. for i = 1, pushChest do
  839. back()
  840. back()
  841. end
  842. if #chests > 1 then
  843. turtle.turnLeft()
  844. end
  845. turtle.select(originalSlot)
  846. end
  847.  
  848. function forward()
  849. return turtle.forward()
  850. end
  851.  
  852. function back()
  853. return turtle.back()
  854. end
  855.  
  856. function up()
  857. return turtle.up()
  858. end
  859.  
  860. function down()
  861. return turtle.down()
  862. end
  863.  
  864. function updateAllChests()
  865. checkFuel()
  866. if #chests > 1 then
  867. turtle.turnRight()
  868. end
  869. for i = 1, #chests do
  870. chests[i] = checkUp()
  871. if #chests > 1 and i < #chests then
  872. bullDoze(2)
  873. end
  874. end
  875. turnAround()
  876. if #chests > 1 then
  877. bullDoze((#chests - 1)*2)
  878. end
  879. if #chests > 1 then
  880. turtle.turnRight()
  881. end
  882. end
  883.  
  884. function digAndUpdate(dir)
  885. local slot = turtle.getSelectedSlot()
  886. local there, inspect = false, {}
  887. if dir == "up" then
  888. there, inspect = turtle.inspectUp()
  889. elseif dir == "down" then
  890. there, inspect = turtle.inspectDown()
  891. else
  892. there, inspect = turtle.inspect()
  893. end
  894. if there then
  895. local bf = 0
  896. if inspect.name == "minecraft:dirt" then
  897. bf = nearestBuffer(inspect.name)
  898. elseif inspect.name == "minecraft:stone" then
  899. bf = nearestBuffer("minecraft:cobblestone")
  900. else
  901. bf = nearestBuffer()
  902. end
  903. turtle.select(bf)
  904. if dir == "up" then
  905. turtle.digUp()
  906. elseif dir == "down" then
  907. turtle.digDown()
  908. else
  909. turtle.dig()
  910. end
  911. updateInternalInventory(bf)
  912. mergeStacks()
  913. end
  914. turtle.select(slot)
  915. end
  916.  
  917. function makePickaxe(i)
  918. if i == #chests then
  919. if turtle.detect() then
  920. digAndUpdate()
  921. end
  922. end
  923. forward()
  924. end
  925.  
  926. function slotsLeft()
  927. return inventorySize - #turtleInventory - 9
  928. end
  929.  
  930. local miners = 0
  931.  
  932. function reduceByOne(slot)
  933. if turtleInventory[slot].count == 1 then
  934. turtleInventory[slot] = nil
  935. else
  936. turtleInventory[slot].count = turtleInventory[slot].count - 1
  937. end
  938. end
  939. function addNewMiner() -- Needs fixing or testing!
  940. stockInventory()
  941. --[[
  942. local list = {"minecraft:hopper","ComputerCraft:CC-TurtleExpanded","ComputerCraft:CC-Peripheral","ComputerCraft:disk"}
  943. for i, v in pairs(list) do
  944. print(v..": "..tostring(canCraft(v,1)))
  945. end
  946. ]]
  947. if canCraft("minecraft:hopper",1) and canCraft("ComputerCraft:CC-TurtleExpanded",1) and canCraft("ComputerCraft:CC-Peripheral",1) and canCraft("ComputerCraft:disk",1) then
  948. printTitle("Ultimate Program Running","Adding New Miner")
  949. if slotsLeft() < 4 then
  950. stockInventory()
  951. end
  952. craft("minecraft:hopper",1)
  953. craft("ComputerCraft:CC-Peripheral",1)
  954. craft("ComputerCraft:CC-TurtleExpanded",1)
  955. pullItemFromStorage("ComputerCraft:disk",1)
  956. local droneSlot = turtle.getSelectedSlot()
  957. -- nearestBuffer("ComputerCraft:CC-Turtle")
  958. turtle.turnLeft()
  959. forward()
  960. if not turtle.up() then
  961. digAndUpdate("up")
  962. turtle.up()
  963. end
  964. for i = 1, miners + 1 do
  965. if math.ceil(i/2) == miners + 1 then
  966. if turtle.detect() then
  967. digAndUpdate()
  968. end
  969. end
  970. if not forward() then
  971. digAndUpdate()
  972. forward()
  973. end
  974. end
  975. if not down() then
  976. digAndUpdate("down")
  977. down()
  978. end
  979. pullItemFromStorage("ComputerCraft:CC-Peripheral",1)
  980. if turtle.placeDown() == false then
  981. digAndUpdate("down")
  982. pullItemFromStorage("ComputerCraft:CC-Peripheral",1)
  983. turtle.placeDown()
  984. end
  985. reduceByOne(turtle.getSelectedSlot())
  986. mergeStacks()
  987. local t = pullItemFromStorage("ComputerCraft:disk",1)
  988. turtle.dropDown()
  989. turtleInventory[t] = nil
  990. turtle.turnRight()
  991. local it = pullItemFromStorage("minecraft:hopper",1)
  992. digAndUpdate()
  993. forward()
  994. turtle.turnLeft()
  995. digAndUpdate()
  996. forward()
  997. turnAround()
  998. turtle.select(it)
  999. turtle.place()
  1000. reduceByOne(it)
  1001. mergeStacks()
  1002. digAndUpdate("up")
  1003. up()
  1004. digAndUpdate()
  1005. forward()
  1006. turtle.turnRight()
  1007. forward()
  1008. digAndUpdate("up")
  1009. up()
  1010. local tr = pullItemFromStorage("ComputerCraft:CC-TurtleExpanded",1)
  1011. turtle.placeDown()
  1012. turtle.turnRight()
  1013. reduceByOne(tr)
  1014. peripheral.call("bottom","turnOn")
  1015. for i = 1, miners + 1 do
  1016. back()
  1017. end
  1018. down()
  1019. back()
  1020. turtle.turnRight()
  1021. miners = miners + 1
  1022. return true
  1023. end
  1024. return false
  1025. end
  1026.  
  1027. function bulldoze(i)
  1028. for i = 1, i do
  1029. if not forward() then repeat turtle.dig() until forward() end
  1030. end
  1031. end
  1032.  
  1033. function addNewChest()
  1034. stockInventory()
  1035. if ironChests then
  1036. local firstChest = 0
  1037. for i = 1, #chests do
  1038. if chests[i].size == 27 and canCraft("IronChest:woodIronUpgrade",1) then
  1039. firstChest = i
  1040. craft("IronChest:woodIronUpgrade",1)
  1041. break
  1042. elseif chests[i].size == 54 and canCraft("IronChest:ironGoldUpgrade",1) then
  1043. firstChest = i
  1044. craft("IronChest:ironGoldUpgrade",1)
  1045. break
  1046. elseif chests[i].size == 81 and canCraft("IronChest:goldDiamondUpgrade",1) then
  1047. firstChest = i
  1048. craft("IronChest:goldDiamondUpgrade",1)
  1049. break
  1050. end
  1051. end
  1052. if firstChest ~= 0 then
  1053. if firstChest > 1 then
  1054. turtle.turnRight()
  1055. bulldoze((firstChest - 1)*2)
  1056. end
  1057. turtle.placeUp()
  1058. chests[firstChest] = checkUp()
  1059. updateInternalInventory()
  1060. if firstChest > 1 then
  1061. turnAround()
  1062. bulldoze((firstChest - 1)*2)
  1063. turtle.turnRight()
  1064. end
  1065. return true
  1066. end
  1067. end
  1068. if canCraft("minecraft:chest",1) then
  1069. craft("minecraft:chest",1)
  1070. turtle.turnRight()
  1071. for i = 1, #chests do
  1072. makePickaxe(i)
  1073. makePickaxe(i)
  1074. end
  1075. digAndUpdate("up")
  1076. local chest = pullItemFromStorage("minecraft:chest",1)
  1077. turtle.placeUp()
  1078. reduceByOne(chest)
  1079. for i = 1, #chests * 2 do
  1080. back()
  1081. end
  1082. chests[#chests + 1] = {stacks = {}, size = 27}
  1083. turtle.turnLeft()
  1084. return true
  1085. end
  1086. return false
  1087. end
  1088. --[[
  1089. for i, v in pairs(chests[1][1]) do
  1090. if v["all"] then
  1091. for o, p in pairs(v.all()) do
  1092. textutils.slowPrint(o..": "..tostring(p))
  1093. end
  1094. end
  1095. end
  1096.  
  1097. id:
  1098. minecraft:log
  1099. minecraft:chest
  1100. minecraft:planks
  1101. minecraft:cobblestone
  1102. minecraft:gold_ingot
  1103. minecraft:furnace
  1104. minecraft:diamond
  1105. minecraft:stick
  1106. minecraft:diamond_pickaxe
  1107. minecraft:chest
  1108. minecraft:iron_ingot
  1109. minecraft:redstone
  1110. minecraft:sand
  1111. minecraft:glass
  1112. minecraft:glass_pane
  1113. minecraft:ender_pearl
  1114. IronChest:woodIronUpgrade
  1115. IronChest:ironGoldUpgrade
  1116. IronChest:goldDiamondUpgrade
  1117. raw_name:
  1118. tile.ironchest:diamond
  1119. tile.ironchest:iron
  1120. tile.ironchest:gold
  1121. tile.computercraft:advanced_computer
  1122. tile.computercraft:computer
  1123. tile.computercraft:turtle
  1124. ]]
  1125.  
  1126. --[[
  1127. while true do
  1128. print("Ultimate Program Crafter")
  1129. write("Item Name: ")
  1130. local itemName = ""
  1131. itemName = read()
  1132. if not itemName then
  1133. break
  1134. end
  1135. if string.gsub(itemName," ","") == "" then
  1136. break
  1137. end
  1138. write("Item Count: ")
  1139. local itemCount = ""
  1140. itemCount = tonumber(read())
  1141. if not itemCount then
  1142. break
  1143. end
  1144. if craftingRecipes[itemName] or furnaceRecipes[itemName] then
  1145. if itemCount <= 64 then
  1146. craft(itemName,itemCount)
  1147. --stockInventory()
  1148. end
  1149. end
  1150. end
  1151. ]]--
  1152. --stockInventory()
  1153. function getItemName()
  1154. write("Item Name: ")
  1155. local itemName = ""
  1156. itemName = read()
  1157. if not itemName then
  1158. return nil
  1159. end
  1160. if itemName == "exit" or itemName == "add miner" or itemName == "count" or itemName == "clear" then
  1161. return itemName
  1162. end
  1163. if string.gsub(itemName," ","") == "" then
  1164. return nil
  1165. end
  1166. write("Item Count: ")
  1167. local itemCount2 = ""
  1168. itemCount2 = tonumber(read())
  1169. if not itemCount2 then
  1170. return nil
  1171. end
  1172. return itemName, itemCount2
  1173. end
  1174. function printCenter(str,line)
  1175. local x, y = term.getSize()
  1176. term.setCursorPos((x/2) - (string.len(str)/2),line)
  1177. term.clearLine()
  1178. term.setCursorPos((x/2) - (string.len(str)/2),line)
  1179. write(str)
  1180. end
  1181. function printLine()
  1182. write(string.rep("-",({term.getSize()})[1]))
  1183. end
  1184. function printTitle(...)
  1185. for i = 1, #({...}) do
  1186. printCenter(({...})[i],i)
  1187. end
  1188. term.setCursorPos(1,#({...}) + 1)
  1189. printLine()
  1190. end
  1191. function getInput()
  1192. turtle.turnRight()
  1193. term.clear()
  1194. printTitle("Ultimate Program Interface", "Type \"exit\" to exit, enter to cancel.","\"add miner\", \"clear\", \"count\".\"")
  1195. local itemName, itemCount2 = getItemName()
  1196. itemCount2 = tonumber(itemCount2)
  1197. if itemName then
  1198. if string.lower(itemName) == "exit" then
  1199. turtle.turnLeft()
  1200. return false
  1201. elseif string.lower(itemName) == "add miner" then
  1202. print("Attempting to add new miner...")
  1203. turtle.turnLeft()
  1204. addNewMiner()
  1205. return true
  1206. elseif string.lower(itemName) == "clear" then
  1207. turtle.turnLeft()
  1208. print("Clearing inventory...")
  1209. clearCrafting()
  1210. clearInventory()
  1211. return true
  1212. elseif string.lower(itemName) == "count" then
  1213. write("Item name: ")
  1214. local itemName2 = read()
  1215. print(itemCount2)
  1216. print(itemName2)
  1217. print("There are "..itemCount(itemName2).." of "..itemName2.." available.")
  1218. sleep(2)
  1219. else
  1220. if canCraft(itemName,itemCount2) then
  1221. print("Processing...")
  1222. turtle.turnLeft()
  1223. craft(itemName,itemCount2)
  1224. turtle.turnRight()
  1225. turtle.drop(itemCount2)
  1226. updateInternalInventory(turtle.getSelectedSlot())
  1227. else
  1228. print("Cannot craft items.")
  1229. sleep(0.5)
  1230. end
  1231. end
  1232. end
  1233. turtle.turnLeft()
  1234. return true
  1235. end
  1236. function checkRedstone()
  1237. local e = {"nothing"}
  1238. if not rs.getInput("bottom") then
  1239. os.startTimer(0.1)
  1240. e = {os.pullEvent()}
  1241. end
  1242. if rs.getInput("bottom") or e[1] == "key" or e[1] == "char" then
  1243. if getInput() == false then
  1244. term.clear()
  1245. printTitle("Ultimate Program Closed")
  1246. term.setCursorPos(1,3)
  1247. return true
  1248. else
  1249. term.clear()
  1250. printTitle("Ultimate Program Running")
  1251. end
  1252. end
  1253. return false
  1254. end
  1255. --[[
  1256. while true do
  1257. term.clear()
  1258. printTitle("Ultimate Program Running")
  1259. mergeStacks()
  1260. if checkTotalInventoryCapacity() < inventorySize then
  1261. addNewChest()
  1262. end
  1263. stockInventory()
  1264. addNewMiner()
  1265. end]]
  1266. term.clear()
  1267. printTitle("Ultimate Program Loading","Initializing External Inventory")
  1268. chests = {checkUp()}
  1269. checkFuel()
  1270. turtle.turnRight()
  1271. local initChests = 0
  1272. repeat
  1273. local breakingForward = false
  1274. repeat
  1275. if turtle.detect() then
  1276. breakingForward = true
  1277. break
  1278. end
  1279. until forward()
  1280. if breakingForward then break end
  1281. repeat
  1282. if turtle.detect() then
  1283. breakingForward = true
  1284. repeat until back()
  1285. break
  1286. end
  1287. until forward()
  1288. if breakingForward then break end
  1289. initChests = initChests + 1
  1290. local check = checkUp()
  1291. if check then chests[initChests + 1] = check else break end
  1292. until not peripheral.call("top","getInventorySize")
  1293. if initChests > 0 then
  1294. for i = 1, initChests*2 do
  1295. if not back() then
  1296. turnAround()
  1297. repeat until not turtle.dig()
  1298. turnAround()
  1299. back()
  1300. end
  1301. end
  1302. end
  1303. turtle.turnLeft()
  1304. printTitle("Ultimate Program Loading","Initializing Internal Inventory")
  1305. updateInternalInventory()
  1306. stockInventory()
  1307. term.clear()
  1308. local stop = false
  1309. while true do
  1310. mergeStacks()
  1311. if checkTotalInventoryCapacity() < inventorySize*2 then
  1312. repeat
  1313. if checkRedstone() then stop = true; break end
  1314. addNewChest()
  1315. until checkTotalInventoryCapacity() >= inventorySize
  1316. if stop then break end
  1317. end
  1318. stockInventory()
  1319. printTitle("Ultimate Program Running","Idle")
  1320. sleep(0.1)
  1321. mergeStacks()
  1322. if checkRedstone() then break end
  1323. if makeMiners then addNewMiner() end
  1324. printTitle("Ultimate Program Running","Idle")
  1325. sleep(0.1)
  1326. mergeStacks()
  1327. if checkRedstone() then break end
  1328. end
Advertisement
Add Comment
Please, Sign In to add comment