> For the complete documentation index, see [llms.txt](https://docs.sparkframework.dev/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.sparkframework.dev/documentation/developer-guide/plugins/itembar/api.md).

# API

**Assembly:** `Spark.ItemBar` **Interface:** `IItemBarPlugin` **Implementation:** `ItemBarPlugin`

## Interface

```csharp
public interface IItemBarPlugin
{
    void RegisterItemBarEntity(ItemBarEntity entity);
    void UnregisterItemBarEntity(ItemBarEntity entity);
    void SelectSlot(GameObject target, int slotIndex);
    void CycleSlot(GameObject target, int direction);
    int GetSelectedSlotIndex(GameObject target);
    ItemBarSlot GetSelectedSlot(GameObject target);
}
```

## ItemBarEntry

Extends `SparkDatabaseEntry`. Defines item bar behavior.

| Field              | Type                | Description                 |
| ------------------ | ------------------- | --------------------------- |
| `allowedItemTypes` | List\<ItemTypeBase> | Item types this bar accepts |

**Methods:**

```csharp
bool CanAcceptItemType(ItemTypeBase itemType)
bool CanAcceptItem(ItemEntry itemEntry)
bool CanAcceptItem(ItemInstance itemInstance)
```

## ItemBarSlot

Represents a single slot in the item bar.

**Methods:**

```csharp
ItemInstance GetSlottedItem()
bool HasItem()
bool IsEmpty()
bool IsLocked()
void SetLocked(bool locked)
bool CanSlotItem(ItemInstance item)
void SlotItem(ItemInstance item)
ItemInstance RemoveItem()
ItemInstance SwapItem(ItemInstance newItem)
```

**Events:** `OnSlotChanged`, `OnItemSlotted`, `OnItemRemoved`

## Commands

| Command                    | Fields                         | Description     |
| -------------------------- | ------------------------------ | --------------- |
| `SelectItemBarSlotCommand` | target (GameObject), slotIndex | Select a slot   |
| `CycleItemBarSlotCommand`  | target (GameObject), direction | Cycle selection |

## Components

### ItemBarEntity

MonoBehaviour that manages an item bar on an entity.

**Configuration:**

| Field                   | Type                 | Description              |
| ----------------------- | -------------------- | ------------------------ |
| `numberOfSlots`         | int                  | Slot count (1-20)        |
| `selectedSlotIndex`     | int                  | Initially selected slot  |
| `scrollInputAction`     | InputActionReference | Scroll wheel input       |
| `enableScrollCycling`   | bool                 | Scroll to cycle slots    |
| `invertScrollDirection` | bool                 | Reverse scroll direction |
| `autoEquipItems`        | bool                 | Auto-equip slotted items |
| `equipmentEntity`       | EquipmentEntity      | Equipment reference      |
| `isPersistent`          | bool                 | Save to disk             |
| `loadOnInitialize`      | bool                 | Load from save on enable |
| `autoSaveOnChange`      | bool                 | Save on every change     |

**Methods:**

```csharp
void SelectSlot(int slotIndex)
void CycleSlot(int direction)
int GetSelectedSlotIndex()
ItemBarSlot GetSelectedSlot()
ItemBarSlot GetSlot(int index)
ItemBarSlot[] GetAllSlots()
void SetSlotItem(int slotIndex, ItemInstance item)
ItemInstance GetSlotItem(int slotIndex)
void ClearSlot(int slotIndex)
void SaveItemBarState()
void LoadItemBarState()
```

Integrates with the Rules plugin to prevent slot switching while UI is open or abilities are active.

**Events:** `OnSlotSelected`, `OnSlotItemChanged`

## Save Data

### ItemBarPluginSaveData

Extends `SaveDataEntry`.

**Methods:**

```csharp
void SaveItemBar(string entityId, int selectedSlot, ItemBarSlot[] slots)
SerializedItemBarData GetItemBarData(string entityId)
bool HasItemBarData(string entityId)
void RemoveItemBar(string entityId)
void ClearAllItemBars()
```

### SerializedItemBarData

| Field               | Type                             | Description   |
| ------------------- | -------------------------------- | ------------- |
| `entityId`          | string                           | Owner entity  |
| `selectedSlotIndex` | int                              | Selected slot |
| `slots`             | List\<SerializedItemBarSlotData> | Slot contents |

### SerializedItemBarSlotData

| Field         | Type   | Description   |
| ------------- | ------ | ------------- |
| `slotIndex`   | int    | Slot position |
| `itemEntryId` | string | Item in slot  |
| `quantity`    | int    | Stack count   |
| `isLocked`    | bool   | Lock state    |

## Usage

```csharp
var itemBar = Spark.GetPlugin<IItemBarPlugin>();
if (itemBar != null)
{
    // Select a slot
    itemBar.SelectSlot(playerObject, 0);

    // Cycle through slots
    itemBar.CycleSlot(playerObject, 1);  // Next
    itemBar.CycleSlot(playerObject, -1); // Previous

    // Get selected slot
    var slot = itemBar.GetSelectedSlot(playerObject);
    if (slot.HasItem())
    {
        Debug.Log($"Selected: {slot.GetSlottedItem().GetDisplayName()}");
    }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.sparkframework.dev/documentation/developer-guide/plugins/itembar/api.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
