inventory-system
Skill29 starsChanged 6 months agoMITView on GitHub
Inventory system for games including item management, stacking, equipment, and inventory UI
2 other projects use a version of this.
Adopted by
Most recently taken up by
- jame581/GodotPromptertheir own version, first seen Oct 21, 2026
- Whaocaii/ai-game-skillstheir own version, first seen Oct 17, 2026
Other versions2 projects use a version of this.
Word for word · 0
None found.
Edited · 0
None found.
Wrote their own version · 2
- jame581/GodotPrompter★ 965same name
- Whaocaii/ai-game-skills★ 4same name
How matches are found. Word for word: the exact same text. Edited: shares passages with this file (“99% same” means 99% of its five-word phrases also appear here; 10% or more counts). Their own version: similar meaning, or, weakest, the same name. We can’t tell which project had it first. Projects are counted among the 200 most-starred candidates, and mentions are links to the repository we found, up to 50 per site, so both counts are a floor.
In this repository371 other files it gives its agents.
- AGENTS.mdAGENTS.md
- GameStudio Skill Testing Framework/AGENTS.mdAGENTS.md
- CLAUDE.mdCLAUDE.md
- design/CLAUDE.mdCLAUDE.md
- docs/CLAUDE.mdCLAUDE.md
- GameStudio Skill Testing Framework/CLAUDE.mdCLAUDE.md
- src/CLAUDE.mdCLAUDE.md
- .cursor/rules/gamestudio.mdcCursor rule
- adoptSkill
- ai-systemSkill
- architecture-decisionSkill
- architecture-reviewSkill
- art-bibleSkill
- asset-auditSkill
- asset-specSkill
- audio-systemSkill
- balance-checkSkill
- battery-optimizationSkill
- brainstormSkill
- bug-reportSkill
- bug-triageSkill
- camera-systemSkill
- changelogSkill
- code-reviewSkill
- collision-systemSkill
- consistency-checkSkill
- content-auditSkill
- create-architectureSkill
- create-control-manifestSkill
- create-epicsSkill
- create-storiesSkill
- day-one-patchSkill
- design-reviewSkill
- design-systemSkill
- dev-storySkill
- ecs-architectureSkill
- ecs-component-patternsSkill
- ecs-eventsSkill
- ecs-performanceSkill
- ecs-queriesSkill
- ecs-serializationSkill
- ecs-system-patternsSkill
- estimateSkill
- gate-checkSkill
- health-combat-systemSkill
- helpSkill
- hotfixSkill
- input-systemSkill
- launch-checklistSkill
- level-systemSkill
- localizeSkill
- map-systemsSkill
- memory-managementSkill
- milestone-reviewSkill
- mobile-performanceSkill
- onboardSkill
- patch-notesSkill
- perf-profileSkill
- phaser-2d-gameSkill
- phaser-actions-and-utilitiesSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
4 rules. About 0 are common, 4 are distinctive, and 0 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
0
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 12
Use this skill when:
- Distinctive: line 573
Missing item checks: Use items not owned
- Distinctive: line 577
Missing item database: No item definitions
- Distinctive: line 584
Use slot indices instead of searching
≈ “Common” is an estimate: at least 1 in 5 of the 408,460 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
Inventory System
When to Use
Use this skill when:
- Managing player inventory
- Implementing item collection
- Creating equipment systems
- Building crafting systems
- Managing item stacking
- Implementing item drops
Core Principles
- Slot-Based: Fixed or dynamic inventory slots
- Stackable: Items can stack with limits
- Data-Driven: Item definitions in data
- Type-Safe: Strong typing for items
- Event-Driven: Item pickup/use events
- Serializable: Save/load inventory
Inventory System Implementation
1. Item Definitions
// items/ItemDefinition.ts
export enum ItemType {
Consumable = 'consumable',
Equipment = 'equipment',
Material = 'material',
Quest = 'quest',
}
export enum EquipmentSlot {
Head = 'head',
Chest = 'chest',
Legs = 'legs',
Weapon = 'weapon',
Shield = 'shield',
}
export interface ItemDefinition {
id: string;
name: string;
description: string;
type: ItemType;
maxStack: number;
icon?: string;
value?: number; // Sell price
weight?: number;
// Equipment
equipmentSlot?: EquipmentSlot;
armor?: number;
damage?: number;
// Consumable
healAmount?: number;
effectDuration?: number;
}
export class ItemDatabase {
private items = new Map<string, ItemDefinition>();
register(item: ItemDefinition): void {
this.items.set(item.id, item);
}
get(id: string): ItemDefinition | undefined {
return this.items.get(id);
}
getAll(): ItemDefinition[] {
return Array.from(this.items.values());
}
}2. Inventory Components
// components/Inventory.ts
export interface InventorySlot {
itemId: string | null;
quantity: number;
}
export class Inventory {
slots: InventorySlot[];
maxSlots: number;
constructor(maxSlots: number = 20) {
this.maxSlots = maxSlots;
this.slots = Array.from({ length: maxSlots }, () => ({
itemId: null,
quantity: 0,
}));
}
addItem(itemId: string, quantity: number = 1, itemDb: ItemDatabase): boolean {
const itemDef = itemDb.get(itemId);
if (!itemDef) return false;
let remaining = quantity;
// Try to stack with existing items
if (itemDef.maxStack > 1) {
for (const slot of this.slots) {
if (slot.itemId === itemId && slot.quantity < itemDef.maxStack) {
const canAdd = Math.min(remaining, itemDef.maxStack - slot.quantity);
slot.quantity += canAdd;
remaining -= canAdd;
if (remaining === 0) return true;
}
}
}
// Add to empty slots
while (remaining > 0) {
const emptySlot = this.slots.find((s) => s.itemId === null);
if (!emptySlot) return false; // Inventory full
const addAmount = Math.min(remaining, itemDef.maxStack);
emptySlot.itemId = itemId;
emptySlot.quantity = addAmount;
remaining -= addAmount;
}
return true;
}
removeItem(itemId: string, quantity: number = 1): boolean {
let remaining = quantity;
for (const slot of this.slots) {
if (slot.itemId === itemId) {
const removeAmount = Math.min(remaining, slot.quantity);
slot.quantity -= removeAmount;
remaining -= removeAmount;
if (slot.quantity === 0) {
slot.itemId = null;
}
if (remaining === 0) return true;
}
}
return remaining === 0;
}
hasItem(itemId: string, quantity: number = 1): boolean {
let count = 0;
for (const slot of this.slots) {
if (slot.itemId === itemId) {
count += slot.quantity;
}
}
return count >= quantity;
}
getItemCount(itemId: string): number {
let count = 0;
for (const slot of this.slots) {
if (slot.itemId === itemId) {
count += slot.quantity;
}
}
return count;
}
isFull(): boolean {
return this.slots.every((slot) => slot.itemId !== null);
}
isEmpty(): boolean {
return this.slots.every((slot) => slot.itemId === null);
}
clear(): void {
for (const slot of this.slots) {
slot.itemId = null;
slot.quantity = 0;
}
}
getFilledSlots(): InventorySlot[] {
return this.slots.filter((slot) => slot.itemId !== null);
}
}
// components/Equipment.ts
export class Equipment {
slots = new Map<EquipmentSlot, string | null>();
constructor() {
// Initialize all equipment slots
for (const slot of Object.values(EquipmentSlot)) {
this.slots.set(slot, null);
}
}
equip(slot: EquipmentSlot, itemId: string): string | null {
const previous = this.slots.get(slot) ?? null;
this.slots.set(slot, itemId);
return previous; // Return unequipped item
}
unequip(slot: EquipmentSlot): string | null {
const itemId = this.slots.get(slot) ?? null;
this.slots.set(slot, null);
return itemId;
}
getEquipped(slot: EquipmentSlot): string | null {
return this.slots.get(slot) ?? null;
}
isEquipped(itemId: string): boolean {
return Array.from(this.slots.values()).includes(itemId);
}
getTotalArmor(itemDb: ItemDatabase): number {
let total = 0;
for (const itemId of this.slots.values()) {
if (itemId) {
const item = itemDb.get(itemId);
if (item?.armor) {
total += item.armor;
}
}
}
return total;
}
getTotalDamage(itemDb: ItemDatabase): number {
let total = 0;
for (const itemId of this.slots.values()) {
if (itemId) {
const item = itemDb.get(itemId);
if (item?.damage) {
total += item.damage;
}
}
}
return total;
}
}3. Inventory System
// systems/InventorySystem.ts
export class InventorySystem extends UpdateSystem {
priority = 40;
private itemDb: ItemDatabase;
private eventBus: EventBus;
constructor(itemDb: ItemDatabase, eventBus: EventBus) {
super();
this.itemDb = itemDb;
this.eventBus = eventBus;
}
update(world: World, deltaTime: number): void {
// Process item pickups
this.processItemPickups(world);
// Update equipment stats
this.updateEquipmentStats(world);
}
private processItemPickups(world: World): void {
const items = world.query<[Transform, ItemPickup]>([Transform, ItemPickup]);
const players = world.query<[Transform, Inventory]>([Transform, Inventory]);
items.iterate((itemEntity, [itemTransform, pickup]) => {
players.iterate((playerEntity, [playerTransform, inventory]) => {
const distance = itemTransform.position.distanceTo(playerTransform.position);
if (distance <= pickup.pickupRadius) {
// Try to add to inventory
if (inventory.addItem(pickup.itemId, pickup.quantity, this.itemDb)) {
// Pickup successful
this.eventBus.emit(new ItemPickedUpEvent(playerEntity, pickup.itemId, pickup.quantity));
world.destroyEntity(itemEntity);
}
}
});
});
}
private updateEquipmentStats(world: World): void {
const entities = world.query<[Equipment, Armor, Attack]>([Equipment, Armor, Attack]);
entities.iterate((entity, [equipment, armor, attack]) => {
// Update armor from equipment
armor.value = equipment.getTotalArmor(this.itemDb);
// Update damage from equipment
attack.damage = equipment.getTotalDamage(this.itemDb);
});
}
useItem(entity: Entity, itemId: string): boolean {
const inventory = entity.getComponent(Inventory);
if (!inventory || !inventory.hasItem(itemId)) return false;
const itemDef = this.itemDb.get(itemId);
if (!itemDef) return false;
switch (itemDef.type) {
case ItemType.Consumable:
return this.useConsumable(entity, itemId, itemDef);
case ItemType.Equipment:
return this.equipItem(entity, itemId, itemDef);
default:
return false;
}
}
private useConsumable(entity: Entity, itemId: string, itemDef: ItemDefinition): boolean {
const inventory = entity.getComponent(Inventory);
if (!inventory) return false;
// Apply consumable effect
if (itemDef.healAmount) {
const health = entity.getComponent(Health);
if (health) {
health.heal(itemDef.healAmount);
}
}
// Remove from inventory
inventory.removeItem(itemId, 1);
this.eventBus.emit(new ItemUsedEvent(entity, itemId));
return true;
}
private equipItem(entity: Entity, itemId: string, itemDef: ItemDefinition): boolean {
const inventory = entity.getComponent(Inventory);
const equipment = entity.getComponent(Equipment);
if (!inventory || !equipment || !itemDef.equipmentSlot) return false;
// Unequip current item in slot
const previousItem = equipment.equip(itemDef.equipmentSlot, itemId);
// Remove from inventory
inventory.removeItem(itemId, 1);
// Add previous item back to inventory
if (previousItem) {
inventory.addItem(previousItem, 1, this.itemDb);
}
this.eventBus.emit(new ItemEquippedEvent(entity, itemId, itemDef.equipmentSlot));
return true;
}
dropItem(entity: Entity, itemId: string, quantity: number = 1, world: World): void {
const inventory = entity.getComponent(Inventory);
const transform = entity.getComponent(Transform);
if (!inventory || !transform) return;
if (inventory.removeItem(itemId, quantity)) {
// Create dropped item entity
const droppedItem = world.createEntity();
const dropTransform = droppedItem.addComponent(new Transform(transform.position.clone()));
dropTransform.position.y += 0.5; // Slightly above ground
const pickup = droppedItem.addComponent(new ItemPickup(itemId, quantity));
this.eventBus.emit(new ItemDroppedEvent(entity, itemId, quantity));
}
}
}
// components/ItemPickup.ts
export class ItemPickup {
itemId: string;
quantity: number;
pickupRadius: number = 2;
constructor(itemId: string, quantity: number = 1) {
this.itemId = itemId;
this.quantity = quantity;
}
}4. Crafting System
// crafting/CraftingSystem.ts
export interface CraftingRecipe {
id: string;
result: { itemId: string; quantity: number };
ingredients: Array<{ itemId: string; quantity: number }>;
craftTime?: number;
}
export class CraftingSystem {
private recipes = new Map<string, CraftingRecipe>();
private itemDb: ItemDatabase;
constructor(itemDb: ItemDatabase) {
this.itemDb = itemDb;
}
addRecipe(recipe: CraftingRecipe): void {
this.recipes.set(recipe.id, recipe);
}
canCraft(recipeId: string, inventory: Inventory): boolean {
const recipe = this.recipes.get(recipeId);
if (!recipe) return false;
// Check if has all ingredients
for (const ingredient of recipe.ingredients) {
if (!inventory.hasItem(ingredient.itemId, ingredient.quantity)) {
return false;
}
}
return true;
}
craft(recipeId: string, inventory: Inventory): boolean {
if (!this.canCraft(recipeId, inventory)) return false;
const recipe = this.recipes.get(recipeId)!;
// Remove ingredients
for (const ingredient of recipe.ingredients) {
inventory.removeItem(ingredient.itemId, ingredient.quantity);
}
// Add result
inventory.addItem(recipe.result.itemId, recipe.result.quantity, this.itemDb);
return true;
}
getAvailableRecipes(inventory: Inventory): CraftingRecipe[] {
return Array.from(this.recipes.values()).filter((recipe) =>
this.canCraft(recipe.id, inventory)
);
}
}Usage Examples
// Example 1: Setup item database
const itemDb = new ItemDatabase();
itemDb.register({
id: 'health_potion',
name: 'Health Potion',
description: 'Restores 50 HP',
type: ItemType.Consumable,
maxStack: 10,
healAmount: 50,
value: 25,
});
itemDb.register({
id: 'iron_sword',
name: 'Iron Sword',
description: 'A sturdy iron sword',
type: ItemType.Equipment,
maxStack: 1,
equipmentSlot: EquipmentSlot.Weapon,
damage: 15,
value: 100,
});
// Example 2: Player inventory
const player = world.createEntity();
const inventory = player.addComponent(new Inventory(20));
const equipment = player.addComponent(new Equipment());
// Add items
inventory.addItem('health_potion', 3, itemDb);
inventory.addItem('iron_sword', 1, itemDb);
// Example 3: Use item
const inventorySystem = new InventorySystem(itemDb, eventBus);
// Use health potion
if (inventory.hasItem('health_potion')) {
inventorySystem.useItem(player, 'health_potion');
}
// Equip sword
inventorySystem.useItem(player, 'iron_sword');
// Example 4: Item pickup
const itemDrop = world.createEntity();
itemDrop.addComponent(new Transform(new Vector3(5, 0, 5)));
itemDrop.addComponent(new ItemPickup('health_potion', 1));
// Will be picked up automatically when player gets close
// Example 5: Crafting
const crafting = new CraftingSystem(itemDb);
crafting.addRecipe({
id: 'craft_bandage',
result: { itemId: 'bandage', quantity: 1 },
ingredients: [
{ itemId: 'cloth', quantity: 2 },
],
});
// Craft item
if (crafting.canCraft('craft_bandage', inventory)) {
crafting.craft('craft_bandage', inventory);
}
// Example 6: Drop item
inventorySystem.dropItem(player, 'health_potion', 1, world);
// Example 7: Equipment stats
const totalArmor = equipment.getTotalArmor(itemDb);
const totalDamage = equipment.getTotalDamage(itemDb);
console.log(`Armor: ${totalArmor}, Damage: ${totalDamage}`);Checklist
- Define item types and data
- Create inventory component
- Implement item stacking
- Add equipment system
- Create item pickups
- Implement item usage
- Add crafting system
- Create inventory UI
- Test item serialization
- Profile inventory performance
Common Pitfalls
- No max stack limit: Unlimited stacking
- Missing item checks: Use items not owned
- Equipment without inventory: Can't unequip
- No pickup radius: Hard to collect items
- Forgetting serialization: Can't save inventory
- Missing item database: No item definitions
- No full inventory check: Items disappear
Performance Tips
Inventory Optimization
- Cache item lookups
- Use slot indices instead of searching
- Limit inventory updates per frame
- Pool item pickup entities
- Batch UI updates
Memory Optimization
- Share item definitions
- Pool inventory events
- Limit max inventory slots
- Clear empty slots
Mobile Considerations
- Simpler inventory UI
- Touch-friendly item selection
- Fewer inventory slots
- Simpler crafting recipes
- Auto-pickup for items
Related Skills
ecs-serialization- Save/load inventoryui-system- Inventory UIecs-events- Item eventsspawn-system- Item dropsecs-component-patterns- Component design
References
- Inventory system design
- Item stacking algorithms
- Equipment slot systems
- Crafting mechanics
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

