hornedcommando

Minecraft ComputerCraft Modem Get Inventory Slots

Nov 8th, 2024 (edited)
12
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | Gaming | 0 0
  1. ---
  2. --- Desc: A utility to get the inventory slots of a connected peripheral (using for mapping crafting recipes)
  3. ---
  4.  
  5. --By: hornedcommando
  6.  
  7. -- Define the peripheral
  8. local peripheralName = "tconstruct:crafting_station_0" -- Change this to your peripheral name
  9. local peripheral = peripheral.wrap(peripheralName)
  10.  
  11. -- Function to list inventory slots
  12. local function listInventorySlots(peripheral)
  13.     for slot = 1, peripheral.size() do
  14.         local itemDetail = peripheral.getItemDetail(slot)
  15.         if itemDetail then
  16.             print("Slot: " .. slot .. ", Item: " .. itemDetail.name .. ", Count: " .. itemDetail.count)
  17.         else
  18.             print("Slot: " .. slot .. " is empty.")
  19.         end
  20.     end
  21. end
  22.  
  23. -- Main function
  24. local function main()
  25.     if peripheral then
  26.         print("Peripheral connected: " .. peripheralName)
  27.         listInventorySlots(peripheral)
  28.     else
  29.         print("Peripheral not found: " .. peripheralName)
  30.     end
  31. end
  32.  
  33. -- Start the main function
  34. main()
Add Comment
Please, Sign In to add comment