# BlockPredicateHelper

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

**Since:** 1.9.1

A condition that tests whether a block at a position matches its block, state, and NBT criteria.  

Each criterion may be absent; the getters return `null` when absent. [test(BlockPosHelper)](#com.jsmacrosce.jsmacros.client.api.helper.BlockPredicateHelper_test-BlockPosHelper-)
checks the block and state criteria and, when present, its block-entity NBT predicate. It does
not apply the underlying predicate's data-component matcher.  
```js
const player = Player.getPlayer();  
if (player === null) { throw new Error("not in a world"); }

// an elytra restricts where it may be used, and those are block conditions
const elytra = player.getMainHand();  
for (const condition of elytra.getDestroyRestrictions()) {
  const blocks = condition.getBlocks();  
  // an absent list means "any block", which is null rather than empty
  if (blocks === null) {
    Chat.log("this one restricts nothing on its own");  
  } else {
    for (const block of blocks) {
      Chat.log(`allowed block ${block.getName().getString()}`);  
    }
  }

  // the actual test, against a position in the world
  const under = player.getBlockPos().down();  
  Chat.log(`the block below passes: ${condition.test(under)}`);  
}
```

## Constructors

### new BlockPredicateHelper {#com.jsmacrosce.jsmacros.client.api.helper.BlockPredicateHelper_constructor-BlockPredicate-}

```js
new BlockPredicateHelper(BlockPredicate base)
```

Wraps the supplied block predicate reference without copying or validating it.

**Parameters:**
- `base`: raw block predicate to wrap

## Methods

### getBlocks {#com.jsmacrosce.jsmacros.client.api.helper.BlockPredicateHelper_getBlocks-}

```js
getBlocks(): List<BlockHelper>
```

Returns the blocks this condition accepts, or `null` if it names none.  

An absent list means the condition does not restrict the block type. The returned list is
newly built on each call.

**Returns:** the accepted blocks, or `null` when the condition does not restrict block type

**Since:** 1.9.1

### getNbtPredicate {#com.jsmacrosce.jsmacros.client.api.helper.BlockPredicateHelper_getNbtPredicate-}

```js
getNbtPredicate(): NbtPredicateHelper
```

Returns the extra block data this condition requires, or `null` if it names none.  

When present, this criterion is tested against block-entity data at the position.

**Returns:** the NBT criterion, or `null` when absent

**Since:** 1.9.1

### getStatePredicate {#com.jsmacrosce.jsmacros.client.api.helper.BlockPredicateHelper_getStatePredicate-}

```js
getStatePredicate(): StatePredicateHelper
```

Returns the exact block states this condition accepts, or `null` if it names none.  

When present, this criterion further restricts the block states accepted by
[getBlocks()](#com.jsmacrosce.jsmacros.client.api.helper.BlockPredicateHelper_getBlocks-).

**Returns:** the state criterion, or `null` when absent

**Since:** 1.9.1

### test {#com.jsmacrosce.jsmacros.client.api.helper.BlockPredicateHelper_test-BlockPosHelper-}

```js
test(BlockPosHelper state): boolean
```

Tests the block at the position against this condition using the current client level.  
The test uses the block and state criteria and optional block-entity NBT predicate; it
does not check the data-component matcher. A world must be available.

**Parameters:**
- `state`: position to test in the current client world

**Returns:** whether the block matches the criteria checked by this method

**Since:** 1.9.1
