lgrocks11

Untitled

Mar 10th, 2024
670
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.61 KB | None | 0 0
  1. --Variables
  2.  
  3. local Connected_Inventories = {}
  4. local Inventory = {}
  5. local Slot_Count = 16
  6.  
  7. --Functions
  8.  
  9. local function readInventory(InventoryIndex,InventoryID)
  10.     --make a list of every item,its count,and slot number.
  11.     local ItemInfo_List = {}
  12.     for i = 1,Slot_Count do
  13.         local ItemInfo = turtle.getItemDetail(i)
  14.         if ItemInfo then
  15.             local Item_Info = {ItemInfo[1],ItemInfo[2],i}
  16.             table.insert(ItemInfo_List,Item_Info)
  17.         end
  18.     end
  19.     return ItemInfo_List
  20. end
  21.  
  22. local function addItemToInvList(ItemInfos)
  23.     --Add item and count to the general Inventory list.
  24.     table.insert(Inventory,ItemInfos)
  25. end
  26.  
  27. local function moveInfo(Inventory_List)
  28.     for Item_Index,Item_Information in pairs(Inventory_List) do
  29.         addItemToInvList(Item_Information)
  30.     end
  31. end
  32.  
  33. local function takeInventory()
  34.     for Inventory_Index,Inventory_ID in pairs(Connected_Inventories) do
  35.         local InvList = readInventory(Inventory_Index,Inventory_ID)
  36.         --for every item in the readInventory lists, add its name and its count to the general Inventory list.
  37.         moveInfo(InvList)
  38.     end
  39.     return Inventory
  40. end
  41.  
  42. local function printInventory()
  43.     takeInventory()
  44.     print("Inventory: ")
  45.     for ItemIndex,ItemInformation in pairs(Inventory) do
  46.         print(ItemInformation[1]..";"..ItemInformation[2])
  47.     end
  48. end
  49.  
  50. --Program starts
  51.  
  52. for Peripheral_Index,Peripheral_ID in pairs(peripheral.getNames()) do
  53.     local Current_Peripheral = peripheral.wrap(Peripheral_ID)
  54.     local Peripheral_Name,Peripheral_Type = peripheral.getType(Current_Peripheral)
  55.     if Peripheral_Type == "inventory" then
  56.         table.insert(Connected_Inventories,Current_Peripheral)
  57.     end
  58. end
  59.  
  60. printInventory()
Advertisement
Add Comment
Please, Sign In to add comment