# NbtPredicateHelper

`com.jsmacrosce.jsmacros.client.api.helper.NbtPredicateHelper`

**Since:** 1.9.1

Tests an entity, item stack, or NBT element against a partial NBT condition.  

Matching compares the expected paths and values without requiring unmentioned data to match.  
Entity and item-stack overloads apply their respective Minecraft data extraction rules; the
NBT-element overload tests the supplied tag directly. [BlockPredicateHelper.getNbtPredicate()](BlockPredicateHelper.md#com.jsmacrosce.jsmacros.client.api.helper.BlockPredicateHelper_getNbtPredicate-)
returns `null` when the block predicate has no NBT condition.  
```js
const player = Player.getPlayer();  
if (player === null) { throw new Error("not in a world"); }
const elytra = player.getMainHand();  

for (const condition of elytra.getDestroyRestrictions()) {
  const data = condition.getNbtPredicate();  
  if (data !== null) {
    // the data on the block below, tested as data
    const below = World.getBlock(player.getBlockPos().down());  
    if (below !== null) {
      const nbt = below.getNBT();  
      if (nbt !== null) {
        Chat.log(`the block below matches: ${data.test(nbt)}`);  
      }
    }
  }
}
```

## Constructors

### new NbtPredicateHelper {#com.jsmacrosce.jsmacros.client.api.helper.NbtPredicateHelper_constructor-NbtPredicate-}

```js
new NbtPredicateHelper(NbtPredicate base)
```

Wraps the supplied predicate without copying it; a `null` value can be retrieved with
 [getRaw()](../../../core/helpers/BaseHelper.md#com.jsmacrosce.jsmacros.core.helpers.BaseHelper_getRaw-) but cannot be used by this helper's test methods.

**Parameters:**
- `base`: raw NBT predicate to wrap; may be `null` and is stored as-is

## Methods

### test {#com.jsmacrosce.jsmacros.client.api.helper.NbtPredicateHelper_test-EntityHelper-}

```js
test(EntityHelper<?> entity): boolean
```

Tests the entity's serialized data against this condition, including its selected item for players.

**Parameters:**
- `entity`: entity whose serialized data is tested

**Returns:** whether the entity data matches this condition

**Since:** 1.9.1

### test {#com.jsmacrosce.jsmacros.client.api.helper.NbtPredicateHelper_test-ItemStackHelper-}

```js
test(ItemStackHelper itemStack): boolean
```

Tests the stack's `CUSTOM_DATA` component against this condition; other components are not
considered.

**Parameters:**
- `itemStack`: stack whose `CUSTOM_DATA` component is tested

**Returns:** whether the component data matches this condition

**Since:** 1.9.1

### test {#com.jsmacrosce.jsmacros.client.api.helper.NbtPredicateHelper_test-NBTElementHelper-}

```js
test(NBTElementHelper<?> nbtElement): boolean
```

Tests the supplied NBT element directly, without extracting data from an entity or item stack.

**Parameters:**
- `nbtElement`: NBT element to test

**Returns:** whether the element matches this condition

**Since:** 1.9.1
