# Item Judgment

## hasItem - Regular Item Check

Determine whether the player's inventory has an item with the specified material and quantity (optionally including lore and model).

### Format

```
hasItem.[mats=material;amount=quantity;lore=description;model=model]
```

### Parameter Description

| Parameter | Description                                                            | Required |
| --------- | ---------------------------------------------------------------------- | -------- |
| `mats`    | Minecraft material name (supports multiple formats)                    | ✅        |
| `amount`  | Required quantity                                                      | ✅        |
| `lore`    | Text that must be contained in the item description (case-insensitive) | ❌        |
| `model`   | The item's item\_model (format: namespace:key)                         | ❌        |

### Check Rules

* The item material must match
* The total quantity of all matching items must be greater than or equal to the specified quantity
* If specified `lore`, the item description must contain this string (case-insensitive)
* If specified `model`, the item's item\_model must match (format: `namespace:key`)

### Supported item material name formats

KaMenu supports multiple material name formats, and the system will automatically normalize and match the corresponding Material enum:

* Standard format:`DIAMOND_SWORD`
* Lowercase:`diamond_sword`
* Mixed case:`DiAMond swORd`
* Hyphenated:`Diamond-Sword`
* Spaces:`diamond sword`

**Examples:**

```yaml
# The following formats can all match DIAMOND_SWORD
- condition: "hasItem.[mats=DIAMOND_SWORD;amount=1]"
- condition: "hasItem.[mats=diamond_sword;amount=1]"
- condition: "hasItem.[mats=Diamond-Sword;amount=1]"
- condition: "hasItem.[mats=diamond sword;amount=1]"
```

{% hint style="info" %}
The system will automatically ignore case, replace hyphens and spaces with underscores, and merge extra underscores, so all of the above formats will match correctly.
{% endhint %}

### Example

**Check whether the player has 10 diamonds:**

```yaml
- condition: "hasItem.[mats=DIAMOND;amount=10]"
  allow:
    - 'tell: &aYou have enough diamonds!'
  deny:
    - 'tell: &cYou need 10 diamonds!'
```

**Check whether the player has 1 diamond whose description contains "forging material":**

```yaml
- condition: 'hasItem.[mats=DIAMOND;amount=1;lore=forging material]'
  allow:
    - 'tell: &aYou have a diamond with forging material!'
  deny:
    - 'tell: &cYou are missing a diamond with forging material!'
```

**Check whether the player has 16 items with a custom model (such as Oraxen items):**

```yaml
- condition: 'hasItem.[mats=PAPER;amount=16;model=oraxen:mana_crystal]'
  allow:
    - 'tell: &aYou have enough magic crystals!'
  deny:
    - 'tell: &cYou need 16 magic crystals!'
```

**Use together with the item action:**

```yaml
actions:
  - condition: "hasItem.[mats=DIAMOND;amount=16]"
    allow:
      - 'item: type=take;mats=DIAMOND;amount=16'
      - 'tell: &aPurchase successful! 16 diamonds have been deducted'
    deny:
      - 'tell: &cNot enough items! Need 16 diamonds'
```

**Inverse check (condition is met when the item is absent):**

```yaml
actions:
  - condition: "!hasItem.[mats=DIAMOND;amount=64]"
    allow:
      - 'tell: &aYou can continue mining diamonds!'
    deny:
      - 'tell: &cYour inventory is already full!'
```

### Notes

* Material name**is case-insensitive**, and supports multiple formats (see the explanation above)
* `lore` The check is a containment check; as long as the description contains the specified string, it matches
* `model` The format is `namespace:key`, for example:
  * `minecraft:book`(vanilla item model)
  * `oraxen:mana_crystal`(Oraxen custom item)
  * `itemsadder:test_item`(ItemsAdder custom item)
* Inverse checks are supported, such as `!hasItem.[...]` which means the condition is met when the item is not present
* Iterates over all inventory slots (main inventory, armor slots, off-hand slot, main-hand slot)

***

## hasStockItem - Saved Item Check

Determine whether the player's inventory has a saved item with the specified name and quantity.

### Format

```
hasStockItem.item name;quantity
```

### Parameter Description

| Parameter | Description                | Required |
| --------- | -------------------------- | -------- |
| Item name | The name of the saved item | ✅        |
| Quantity  | Required quantity          | ✅        |

### Check Rules

* The item must be saved first via `/km item save` command
* Item comparison uses the `ItemStack.isSimilar()` method, ignoring differences in item quantity
* The total quantity of all matching items must be greater than or equal to the specified quantity

### Example

**Check whether the player has 16 mysterious fruits:**

```yaml
- condition: "hasStockItem.神秘果;16"
  allow:
    - 'tell: &aYou have enough mysterious fruits!'
  deny:
    - 'tell: &cYou need 16 mysterious fruits!'
```

**Check whether the player has 1 holy sword:**

```yaml
- condition: "hasStockItem.神圣之剑;1"
  allow:
    - 'tell: &aYou can purchase this item!'
  deny:
    - 'tell: &cYou need the holy sword to buy this!'
```

**Use together with the stock-item action:**

```yaml
actions:
  - condition: "hasStockItem.神秘果;16"
    allow:
      - 'stock-item: type=take;name=神秘果;amount=16'
      - 'tell: &aPurchase successful!'
    deny:
      - 'tell: &cNot enough items! Need 16 mysterious fruits'
```

**Inverse check (condition is met when the item is absent):**

```yaml
actions:
  - condition: "!hasStockItem.神圣之剑;1"
    allow:
      - 'tell: &aYou don't have this weapon yet, you can buy it!'
    deny:
      - 'tell: &cYou already have the holy sword and cannot buy it again!'
```

**Using variables:**

```yaml
actions:
  # Read the item name and quantity from data
  - condition: "hasStockItem.{data:purchase_item};{data:required_amount}"
    allow:
      - 'stock-item: type=take;name={data:purchase_item};amount={data:required_amount}'
      - 'tell: &aPurchase successful!'
    deny:
      - 'tell: &cNot enough items!'
```

### Notes

* The item must be saved first `/km item save` before it can be used
* Inverse checks are supported, such as `!hasStockItem.item name;quantity`
* Item comparison ignores differences other than NBT tags
* Iterates over all inventory slots (main inventory, armor slots, off-hand slot, main-hand slot)

***

## Full Example: Shop Menu

### Buy Regular Items

This will demonstrate how to write a menu that buys diamonds at a price of 100 coins each.

```yaml
Title: '§6§lDiamond Shop'

Settings:
  need_placeholder:
    - 'math'
Body:
  diamond:
    type: 'item'
    text: '&a&lDiamond'
    material: DIAMOND
    lore:
      - '&7Price: 100 coins / each'
    description: 'Please drag the slider below to choose the purchase quantity.'

Inputs:
  amount:
    type: 'slider'
    text: '&aPurchase Quantity'
    min: 1
    max: 64
    default: 1
    format: '%s: %s pcs'

Bottom:
  type: 'confirmation'
  confirm:
    text: '&a[ Confirm Purchase ]'
    actions:
      # Buy diamonds (use hasMoney to determine whether there is enough currency)
      - condition: "isIntNum.$(amount)"
        deny:
          - 'tell: &cPlease enter a valid number.'
          - 'return'
      - condition: "hasMoney.%math_0_100*$(amount)%"
        allow:
          - 'money: type=take;num=%math_0_100*$(amount)%'
          - 'item: type=give;mats=DIAMOND;amount=$(amount)'
          - 'tell: &aPurchase successful! Spent coins x%math_0_100*$(amount)% and received diamonds x$(amount)'
        deny:
          - 'tell: &cNot enough currency! Need coins x%math_0_100*$(amount)% '
          - 'sound: block.note_block.bass'
  deny:
    text: '&c[ Cancel Purchase ]'
    actions:
      - 'actionbar: &cPurchase canceled'
      - 'sound: block.note_block.bass'
      - 'close'

```

### Buy Items from Storage

**Prerequisite:** To use this example menu, you should first use the command`/km item save Magic Diamond Sword`to save`Magic Diamond Sword`as an item.

```yaml
Title: '§6§lMagic Diamond Sword Shop'

Settings:
  need_placeholder:
    - 'math'
Body:
  diamond_sword:
    type: 'item'
    text: '&a&lMagic Diamond Sword'
    material: DIAMOND_SWORD
    lore:
      - '&7Price: 10 diamonds'
    description: 'Please drag the slider below to choose the exchange quantity.'

Inputs:
  amount:
    type: 'slider'
    text: '&aPurchase Quantity'
    min: 1
    max: 64
    default: 1
    format: '%s: %s pcs'

Bottom:
  type: 'confirmation'
  confirm:
    text: '&a[ Confirm Purchase ]'
    actions:
      # Buy the diamond sword (use hasItem to check regular items)
      - condition: "hasItem.[mats=DIAMOND;amount=%math_0_10*$(amount)%]"
        allow:
          - 'item: type=take;mats=DIAMOND;amount=%math_0_10*$(amount)%'
          - 'stock-item: type=give;name=Magic Diamond Sword;amount={data:purchase_amount}'
          - 'tell: &aPurchase successful! Spent diamonds x%math_0_10*$(amount)% and received Magic Diamond Sword x$(amount)'
        deny:
          - 'tell: &cNot enough items! Need diamonds x%math_0_10*$(amount)% '
          - 'sound: block.note_block.bass'
  deny:
    text: '&c[ Cancel Purchase ]'
    actions:
      - 'actionbar: &cPurchase canceled'
      - 'sound: block.note_block.bass'
      - 'close'

```

***

## Difference Between the Two

| Feature              | hasItem                                         | hasStockItem                                               |
| -------------------- | ----------------------------------------------- | ---------------------------------------------------------- |
| Applicable Scope     | Regular items                                   | Saved items                                                |
| Parameter Format     | `hasItem.[mats=...;amount=...]`                 | `hasStockItem.item name;quantity`                          |
| Material Check       | Use Minecraft's native material ID              | Use the full ItemStack of the saved item                   |
| Item Matching        | Only matches material, optional lore, and model | Use `isSimilar()` Full match                               |
| Pre-save             | No saving required                              | Must be obtained through `/km item save` save              |
| Applicable Scenarios | Check basic items (such as diamonds, iron ore)  | Check custom items (such as enchanted gear, special tools) |


---

# Agent Instructions: Querying This Documentation

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

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://katacr.gitbook.io/plugins/kamenu-en/menu/conditions/conditions_item.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
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.
