lgrocks11

Untitled

Mar 10th, 2024
766
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.56 KB | Software | 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.         local Item_Info = {ItemInfo[1],ItemInfo[2],i}
  15.         table.insert(ItemInfo_List,Item_Info)
  16.     end
  17.     return ItemInfo_List
  18. end
  19.  
  20. local function addItemToInvList(ItemInfos)
  21.     --Add item and count to the general Inventory list.
  22.     table.insert(Inventory,ItemInfos)
  23. end
  24.  
  25. local function moveInfo(Inventory_List)
  26.     for Item_Index,Item_Information in pairs(Inventory_List) do
  27.         addItemToInvList(Item_Information)
  28.     end
  29. end
  30.  
  31. local function takeInventory()
  32.     for Inventory_Index,Inventory_ID in pairs(Connected_Inventories) do
  33.         local InvList = readInventory(Inventory_Index,Inventory_ID)
  34.         --for every item in the readInventory lists, add its name and its count to the general Inventory list.
  35.         moveInfo(InvList)
  36.     end
  37.     return Inventory
  38. end
  39.  
  40. local function printInventory()
  41.     takeInventory()
  42.     for ItemIndex,ItemInformation in pairs(Inventory) do
  43.         print(ItemInformation[1]..";"..ItemInformation[2])
  44.     end
  45. end
  46.  
  47. --Program starts
  48.  
  49. for Peripheral_Index,Peripheral_ID in pairs(peripherals.getNames()) do
  50.     local Current_Peripheral = perpheral.wrap(Peripheral_ID)
  51.     local Peripheral_Name,Peripheral_Type = peripheral.getType(Current_Peripheral)
  52.     if Peripheral_Type == "inventory" then
  53.         table.insert(Connected_Inventories,Current_Peripheral)
  54.     end
  55. end
  56.  
  57. printInventory()
Advertisement
Add Comment
Please, Sign In to add comment