NbtPredicateHelper
com.jsmacrosce.jsmacros.client.api.helper.NbtPredicateHelper
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 benulland is stored as-is
Methods
test
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
Tests the stack's
CUSTOM_DATA component against this condition; other components are not considered.Parameters:
itemStack: stack whoseCUSTOM_DATAcomponent is tested
Returns: whether the component data matches this condition
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