TheChest.Inventories is a library for managing inventories and slots in generic item collections. It provides a flexible and extensible framework for inventory systems, with support for stackable items, customizable slots, and operations such as adding, removing, moving, and querying items.
- Generic inventory support: works with generic item types for maximum flexibility.
- Slot-based system: stores items in single-item or stackable slots.
- Extensible interfaces: enables custom inventory implementations.
- Core operations: add, remove, move, and retrieve items.
- Stacking support: handles both simple inventories and stack-based inventories.
-
Inventory<T>- Generic inventory implementation using single-item slots.
- Uses
InventorySlot<T>to represent each slot.
-
StackInventory<T>- Generic inventory for stackable items.
- Uses
InventoryStackSlot<T>to represent slots holding multiple units of the same item.
-
LazyStackInventory<T>- Stackable inventory with lazy item loading.
- Uses
InventoryLazyStackSlot<T>to represent slots that can return items on demand.
Add the NuGet package source:
nuget source add -n TheChest https://nuget.pkg.github.com/The-Chest/index.jsonInstall the package:
nuget install TheChest.InventoriesYou can also download the DLL directly and reference it in your project.
var slots = new IInventorySlot<string>[10];
for (int i = 0; i < slots.Length; i++)
{
slots[i] = new InventorySlot<string>();
}
var inventory = new Inventory<string>(slots);
inventory.Add("Item1");var stackSlots = new IInventoryStackSlot<string>[10];
for (int i = 0; i < stackSlots.Length; i++)
{
stackSlots[i] = new InventoryStackSlot<string>(Array.Empty<string>(), 5);
}
var stackInventory = new StackInventory<string>(stackSlots);
stackInventory.Add("StackableItem", "StackableItem");var lazyStackSlots = new IInventoryLazyStackSlot<string>[10];
for (int i = 0; i < lazyStackSlots.Length; i++)
{
lazyStackSlots[i] = new InventoryLazyStackSlot<string>($"item_{i}_", 5, 2);
}
var lazyStackInventory = new LazyStackInventory<string>(lazyStackSlots);
lazyStackInventory.Add("StackableItem", "StackableItem");More usage and extension details are available in the docs/ folder.
Future version plans are available on the GitHub Project Board.