---
# System prepended metadata

title: Inventory DSL

---

# Inventory DSL

## Directives

### Inventory

* `inventory(size, title, body)`
* `inventory(type, title, body)`
* `inventory(inventory, title, body)`

### Block

* `section(fromPoint, toPoint, body)`
* `row(index, body)`
* `rowFromLast(index, body)` = `row(rowCount - index, body)`
* `firstRow(body)`
* `lastRow(body)`
* `column(index, body)`
* `columnFromLast(index, body)` = `column(columnCount - index, body)`
* `firstColumn(body)`
* `lastColumn(body)`

### Item

* `item(slot, itemStack)`
* `item(slot, itemStack with action)`
* `itemFromLast(slot, itemStack)` = `item(slotCount - slot, itemStack)`
* `itemFromLast(slot, itemStack with action)` = `item(slotCount - slot, itemStack)`
* `fill(itemStack)`
* `fill(itemStack with action)`
* `clear()` = `fill { ItemStack(Material.AIR) }`
* `empty(slot)` = `item(slot) { ItemStack(Material.AIR) }`

## Predefined Actions

* `Actions.navigateTo(inventory, flushHistory = false)`
    * `infix fun ItemStack.navigatesTo(inventory)`
    * `infix fun ItemStack.forceNavigatesTo(inventory)`
* `Actions.navigateBack()`
    * `fun ItemStack.navigatesBack()`
* `Actions.close()`
    * `fun ItemStack.closes()`

## Example

```kotlin=
val borderItem = ItemStack(Material.STAINED_GLASS_PANE, ...)
val placeholderItem = ItemStack(Material.BARRIER, ...)
val backItem = ItemStack(Material.SLIME_BALL, ...)

val navigateBack: (Player) -> Boolean = { context, player ->
    context.navigateBack()
    return true
}

// ...

inventory(player, size, title) {
    firstRow { borderItem }
    section(Point(0, 1) to Point(9, 2)) {
        firstColumn { borderItem }
        fill { placeholderItem }
        lastColumn { borderItem }
    }
    lastRow {
        fill { borderItem }
        item(1) { backItem withAction Actions.navigateBack() }
    }
}
```

```kotlin=
val baseInventory: Inventory = // ...

inventory(player, baseInventory) {
    section(fromSlot, toSlot) {
        clear()
    }
    lastRow {
        item(1) { backItem.navigatesBack() }
    }
}
```

```kotlin=
inventory(player, type, title) {
    lastRow {
        itemFromLast(1) { backItem navigatesTo otherInventory }
    }
}
```
