Advertisement
jubjub727

Untitled

Feb 25th, 2023
13
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.95 KB | None | 0 0
  1. local clients = peripheral.call("back", "getNamesRemote")
  2.  
  3. local chests = {}
  4.  
  5. local items = {}
  6.  
  7. local function DiscoverChests()
  8. for k,client in pairs(clients) do
  9. if (string.sub(peripheral.getType(client), 1, 19) == "minecraft:ironchest") then
  10. table.insert(chests, client)
  11. end
  12. end
  13. end
  14.  
  15. local function DiscoverItems()
  16. for _k,_chest in pairs(chests) do
  17. local chest = peripheral.wrap(_chest)
  18.  
  19. for k,_item in pairs(chest.list()) do
  20. local item = chest.getItem(k)
  21.  
  22. local itemTable = {}
  23.  
  24. itemTable.metaData = item.getMetadata()
  25. itemTable.displayName = itemTable.metaData.displayName
  26. itemTable.name = _item.name
  27. itemTable.count = _item.count
  28. itemTable.chest = _chest
  29.  
  30. table.insert(items, itemTable)
  31. end
  32. end
  33. end
  34.  
  35. local function Deposit()
  36. local chest = peripheral.wrap("left")
  37. local depositChest = nil
  38.  
  39. for k, v in pairs(chests) do
  40. local depChest = peripheral.wrap(v)
  41.  
  42. if (#depChest.list() < depChest.size()) then
  43. depositChest = v
  44. end
  45. end
  46.  
  47. if (depositChest == nil) then
  48. print("No available chest space")
  49. read()
  50. end
  51.  
  52. for k, item in pairs(chest.list()) do
  53. chest.pullItems(depositChest, k)
  54. end
  55. end
  56.  
  57. local function main()
  58. term.clear()
  59. term.setCursorPos(1,1)
  60.  
  61. chests = {}
  62. items = {}
  63.  
  64. DiscoverChests()
  65.  
  66. DiscoverItems()
  67.  
  68. for k,v in pairs(items) do
  69. print(v.displayName..": "..v.count.." in "..string.sub(v.chest, 20))
  70. end
  71.  
  72. print("Type 'dep' to deposit items into storage\nType 'req <itemindex> <itemcount>' to retreive items from storage\nPress enter to refresh item list")
  73.  
  74. local input = read()
  75.  
  76. if (string.lower(string.sub(input, 1, 3)) == "dep") then
  77. Deposit()
  78. end
  79.  
  80. main()
  81. end
  82.  
  83. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement