Skip to content

BlockPredicateHelper ​

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

Since1.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) 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 ​

new BlockPredicateHelper(BlockPredicate base)#
Wraps the supplied block predicate reference without copying or validating it.

Parameters:

  • base: raw block predicate to wrap

Methods ​

getBlocks ​

getBlocks(): List<BlockHelper>Since1.9.1#
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

getNbtPredicate ​

getNbtPredicate(): NbtPredicateHelperSince1.9.1#
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

getStatePredicate ​

getStatePredicate(): StatePredicateHelperSince1.9.1#
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().
Returns: the state criterion, or null when absent

test ​

test(BlockPosHelper state): booleanSince1.9.1#
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