Skip to content

NbtPredicateHelper ​

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

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

new NbtPredicateHelper(NbtPredicate base)#
Wraps the supplied predicate without copying it; a null value can be retrieved with 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 ​

test(EntityHelper<?> entity): booleanSince1.9.1#
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
test(ItemStackHelper itemStack): booleanSince1.9.1#
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
test(NBTElementHelper<?> nbtElement): booleanSince1.9.1#
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