bevy-inventory-system
БесплатноБез исполняемых скриптовНе проверенBevy ECS skill for inventories. Keywords: Bevy, inventory, stack, item, ECS.
от thedivergentai★ 1 019 звёзд на GitHubОб этом скилле
Bevy inventory system
When to use
Load this when stacks move between containers. UI grids stay on bevy-ui-layout. Economy prices stay on bevy-economy-system.
ECS shape
- Components: item id and stack count you define.
- Resources: run-wide tables live in a resource (bevy-data-resources).
- Systems: mutate those components on
Updateor the fixed timestep. Use.chain()when damage must land before death. - Messages: one-shot facts (hit, pickup, quest advance) go through bevy-events-messaging. This file does not add a new event type name.
Ownership
| Need | Bevy shape |
|---|---|
| Stack | Item id plus count on a component or inside a resource inventory |
| Container | An entity that owns stacks |
| Equip | A marker component. Stat changes go through bevy-rpg-stats |
Scope
- Item ids, stack counts, and containers are components. A move request is a message so one system writes both bags.
- Slot widgets stay on bevy-ui-layout. Prices stay on bevy-economy-system.
Examples
[package]
name = "inventory"
version = "0.1.0"
edition = "2021"
[dependencies]
bevy = "0.20"
Stacks live on the container entity. Moves are messages so a single query mutably borrows both bags.
#[derive(Clone, Copy, PartialEq, Eq)]
struct ItemId(u32);
#[derive(Clone, Copy)]
struct Stack {
item: ItemId,
count: u32,
}
#[derive(Component, Default)]
struct Inventory {
slots: Vec<Stack>,
}
#[derive(Message)]
struct MoveStack {
from: Entity,
to: Entity,
slot: usize,
count: u32,
}
fn add_stack(inv: &mut Inventory, item: ItemId, mut count: u32) {
for stack in &mut inv.slots {
if stack.item == item {
stack.count += count;
return;
}
}
if count > 0 {
inv.slots.push(Stack { item, count });
}
}
fn transfer(mut requests: MessageReader<MoveStack>, mut bags: Query<&mut Inventory>) {
for req in requests.read() {
if req.from == req.to || req.count == 0 {
continue;
}
let Ok([mut from, mut to]) = bags.get_many_mut([req.from, req.to]) else {
continue;
};
let Some(stack) = from.slots.get_mut(req.slot) else {
continue;
};
if stack.count < req.count {
continue;
}
let item = stack.item;
stack.count -= req.count;
let moved = req.count;
if stack.count == 0 {
from.slots.remove(req.slot);
}
add_stack(&mut to, item, moved);
}
}
pub struct InventoryPlugin;
impl Plugin for InventoryPlugin {
fn build(&self, app: &mut App) {
app.add_message::<MoveStack>()
.add_systems(Update, transfer);
}
}
Equip copies a stack onto a marker and leaves the remainder in the bag. Stat changes stay on bevy-rpg-stats.
#[derive(Clone, Copy, PartialEq, Eq)]
struct ItemId(u32);
#[derive(Component)]
struct Equipped {
item: ItemId,
}
#[derive(Component, Default)]
struct Inventory {
slots: Vec<(ItemId, u32)>,
}
fn equip_first(mut commands: Commands, actors: Query<(Entity, &Inventory), Without<Equipped>>) {
for (entity, bag) in &actors {
let Some((item, count)) = bag.slots.first().copied() else {
continue;
};
if count == 0 {
continue;
}
commands.entity(entity).insert(Equipped { item });
}
}
Spawn a chest and a player bag with a starter stack.
#[derive(Clone, Copy, PartialEq, Eq)]
struct ItemId(u32);
#[derive(Clone, Copy)]
struct Stack {
item: ItemId,
count: u32,
}
#[derive(Component)]
struct Inventory {
slots: Vec<Stack>,
}
fn spawn_bags(mut commands: Commands) {
commands.spawn(Inventory {
slots: vec![Stack {
item: ItemId(1),
count: 8,
}],
});
commands.spawn(Inventory { slots: Vec::new() });
}
Expert Knowledge Delta
Target: Bevy 0.20+.
Core ECS types: Component, Resource, Query, Commands, Startup, Update, Fixed / FixedMain (bevy::time), .chain(), Plugin, DefaultPlugins, MinimalPlugins. Messages and observers are an ownership slot. See bevy-events-messaging for their APIs. Systems run in parallel unless .chain() orders the ones that conflict.
Who owns state
| Piece | Owner | Who may mutate | Schedule |
|---|---|---|---|
| Data on one entity | Component |
One system via Query |
Update or FixedMain |
| One value for the whole app | Resource |
One system | Startup to insert, then the schedule that reads it |
| Spawn | Commands |
The spawning system | Startup for the initial world; later schedules for runtime spawn |
| Order that must not race | .chain() |
The chained systems only | Same schedule |
| Plugin boundary | Plugin |
build registers systems and resources |
Before the app runs |
Borrow rule: two systems that both mutably query the same component must be ordered (.chain())
Установить bevy-inventory-system в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
FAQ
Что делает скилл bevy-inventory-system?
Bevy ECS skill for inventories. Keywords: Bevy, inventory, stack, item, ECS.
Как установить скилл bevy-inventory-system?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл bevy-inventory-system запускает скрипты?
Нет, скилл состоит только из инструкций (SKILL.md), без исполняемых скриптов.
Похожие скиллы
theme-factory
Toolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
от Anthropicaccess
Manage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropicconfigure
Set up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
от Anthropicaccess
Manage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
от Anthropic