Represents the predicate for an MCItemDefinition.

This predicate will match an item against either a specific MCItemDefinition or item tag (MCTag<T>), with the second taking precedence over the first. If this initial check succeeds, then the predicate may also verify additional item properties, such as its current amount, its damage, or internal NBT data via NBTPredicate. The predicate can also check the enchantments that are currently either applied to or stored onto the item via EnchantmentPredicates, or the potion effect that is currently present on the item, if any.

By default, any item will be able to pass the checks of this predicate.

It might be required for you to import the package if you encounter any issues (like casting an Array), so better be safe than sorry and add the import at the very top of the file.

ZenScript
Copy
import crafttweaker.api.predicate.ItemPredicate;

Extending AnyDefaultingVanillaWrappingPredicate

Link to extending-anydefaultingvanillawrappingpredicate

ItemPredicate extends AnyDefaultingVanillaWrappingPredicate. That means all methods available in AnyDefaultingVanillaWrappingPredicate are also available in ItemPredicate

Name: matching

Sets this predicate to match the given IItemStack as closely as possible.

Additional properties such as damage, count, or NBT data are ignored.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.matching(stack as IItemStack) as ItemPredicate
参数类型描述
参数
堆叠
类型
IItemstack
描述
The stack that should be matched.

Name: matching

Sets this predicate to match the given IItemStack as closely as possible, optionally considering damage.

Additional properties such as count or NBT data are ignored.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.matching(stack as IItemStack, matchDamage as boolean) as ItemPredicate
参数类型描述
参数
堆叠
类型
IItemstack
描述
The stack that should be matched.
参数
matchDamage
类型
布尔值
描述
Whether to consider damage or not when matching the stack.

Name: matching

Sets this predicate to match the given IItemStack as closely as possible, optionally considering damage and count.

Additional properties such as NBT data are ignored.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.matching(stack as IItemStack, matchDamage as boolean, matchCount as boolean) as ItemPredicate
参数类型描述
参数
堆叠
类型
IItemstack
描述
The stack that should be matched.
参数
matchDamage
类型
布尔值
描述
Whether to consider damage or not when matching the stack.
参数
matchCount
类型
布尔值
描述
Whether to consider the amount or not when matching the stack.

Name: matching

Sets this predicate to match the given IItemStack as closely as possible, optionally considering damage, count, and NBT data.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.matching(stack as IItemStack, matchDamage as boolean, matchCount as boolean, matchNbt as boolean) as ItemPredicate
参数类型描述
参数
堆叠
类型
IItemstack
描述
The stack that should be matched.
参数
matchDamage
类型
布尔值
描述
Whether to consider damage or not when matching the stack.
参数
matchCount
类型
布尔值
描述
Whether to consider the amount or not when matching the stack.
参数
matchNbt
类型
布尔值
描述
Whether to consider the NBT data or not when matching the stack.

Link to withDataPredicate

Name: withDataPredicate

Creates and sets the NBTPredicate that will be matched against the item's NBT data.

Any changes that have already been made to the NBT predicate will be overwritten, effectively replacing the previous one, if any.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withDataPredicate(builder as Consumer<NBTPredicate>) as ItemPredicate
参数类型描述
参数
生成器
类型
Consumer<NBTPredicate>
描述
A consumer that will be used to configure the NBTPredicate.

Link to withEnchantmentPredicate

Name: withEnchantmentPredicate

Creates and adds a new EnchantmentPredicate to the list of predicates to match against the item's enchantments.

The added predicate is simply added to the list. No validity checks are performed, meaning that there may be multiple predicates that target a single enchantment. In this case, they all need to match, thus they have to have compatible bounds.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withEnchantmentPredicate(builder as Consumer<EnchantmentPredicate>) as ItemPredicate
参数类型描述
参数
生成器
类型
Consumer<EnchantmentPredicate>
描述
A consumer that will be used to configure the EnchantmentPredicate.

Link to withEnchantmentPredicate

Name: withEnchantmentPredicate

Creates and adds a new EnchantmentPredicate for the given MCEnchantment to the list of predicates to match against the item's enchantments.

The predicate that will be configured is already configured to target the specified enchantment.

The added predicate is simply added to the list. No validity checks are performed, meaning that there may be multiple predicates that target a single enchantment. In this case, they all need to match, thus they have to have compatible bounds.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withEnchantmentPredicate(enchantment as MCEnchantment, builder as Consumer<EnchantmentPredicate>) as ItemPredicate
参数类型描述
参数
enchantment
类型
MCEnchantment
描述
The enchantment that should be checked.
参数
生成器
类型
Consumer<EnchantmentPredicate>
描述
A consumer that will be used to configure the EnchantmentPredicate.

Name: withExactAmount

Sets the amount to exactly match the given value.

If the amount had already some bounds specified, then they will be overwritten with the new value.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withExactAmount(value as int) as ItemPredicate
参数类型描述
参数
value
类型
int
描述
The exact value the amount should be.

Name: withExactDamage

Sets the damage to exactly match the given value.

If the damage had already some bounds specified, then they will be overwritten with the new value.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withExactDamage(value as int) as ItemPredicate
参数类型描述
参数
value
类型
int
描述
The exact value the damage should be.

Name: withItem

Sets the MCItemDefinition that this predicate should match.

If a tag to match against has already been set, then the tag check will take precedence over this check.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withItem(definition as MCItemDefinition) as ItemPredicate
参数类型描述
参数
definition
类型
MCItemDefinition
描述
The item the predicate should match.

Name: withItem

Sets the MCItemDefinition that this predicate should match to the one contained in the given IItemStack.

If a tag to match against has already been set, then the tag check will take precedence over this check.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withItem(itemStack as IItemStack) as ItemPredicate
参数类型描述
参数
物品应用
类型
IItemstack
描述
The stack containing the item that the predicate should match.

Link to withMaximumAmount

Name: withMaximumAmount

Sets the maximum amount of items to max.

If the amount had already some bounds specified, then the maximum value of the bound will be overwritten with the value specified in max. On the other hand, if the amount didn't have any bounds set, the maximum is set, leaving the lower end unbounded.

The maximum value is inclusive, meaning that a value that is equal to max will pass the check.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withMaximumAmount(max as int) as ItemPredicate
参数类型描述
参数
max
类型
int
描述
The maximum value the amount should be.

Link to withMaximumDamage

Name: withMaximumDamage

Sets the maximum damage of the item to max.

If the damage had already some bounds specified, then the maximum value of the bound will be overwritten with the value specified in max. On the other hand, if the damage didn't have any bounds set, the maximum is set, leaving the lower end unbounded.

The maximum value is inclusive, meaning that a value that is equal to max will pass the check.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withMaximumDamage(max as int) as ItemPredicate
参数类型描述
参数
max
类型
int
描述
The maximum value the damage should be.

Link to withMinimumAmount

Name: withMinimumAmount

Sets the minimum amount of items to min.

If the amount had already some bounds specified, then the minimum value of the bound will be overwritten with the value specified in min. On the other hand, if the amount didn't have any bounds set, the minimum is set, leaving the upper end unbounded.

The minimum value is inclusive, meaning that a value that is equal to min will pass the check.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withMinimumAmount(min as int) as ItemPredicate
参数类型描述
参数
min
类型
int
描述
The minimum value the amount should be.

Link to withMinimumDamage

Name: withMinimumDamage

Sets the minimum damage of the item to min.

If the damage had already some bounds specified, then the minimum value of the bound will be overwritten with the value specified in min. On the other hand, if the damage didn't have any bounds set, the minimum is set, leaving the upper end unbounded.

The minimum value is inclusive, meaning that a value that is equal to min will pass the check.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withMinimumDamage(min as int) as ItemPredicate
参数类型描述
参数
min
类型
int
描述
The minimum value the damage should be.

Name: withPotion

Sets the potion effect that should be present on the target item.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withPotion(potion as MCPotion) as ItemPredicate
参数类型描述
参数
potion
类型
MCPotion
描述
The potion effect.

Link to withRangedAmount

Name: withRangedAmount

Sets both the minimum and maximum amount of items to min and max respectively.

If the amount had already some bounds specified, then they will be overwritten with the new values.

Both minimum and maximum values are inclusive, meaning that a value that is equal to either min or max will pass the check.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withRangedAmount(min as int, max as int) as ItemPredicate
参数类型描述
参数
min
类型
int
描述
The minimum value the amount should be.
参数
max
类型
int
描述
The maximum value the amount should be.

Link to withRangedDamage

Name: withRangedDamage

Sets both the minimum and maximum damage of the item to min and max respectively.

If the damage had already some bounds specified, then they will be overwritten with the new values.

Both minimum and maximum values are inclusive, meaning that a value that is equal to either min or max will pass the check.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withRangedDamage(min as int, max as int) as ItemPredicate
参数类型描述
参数
min
类型
int
描述
The minimum value the damage should be.
参数
max
类型
int
描述
The maximum value the damage should be.

Link to withStoredEnchantmentPredicate

Name: withStoredEnchantmentPredicate

Creates and adds a new EnchantmentPredicate to the list of predicates to match against the item's stored enchantments.

The added predicate is simply added to the list. No validity checks are performed, meaning that there may be multiple predicates that target a single enchantment. In this case, they all need to match, thus they have to have compatible bounds.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withStoredEnchantmentPredicate(builder as Consumer<EnchantmentPredicate>) as ItemPredicate
参数类型描述
参数
生成器
类型
Consumer<EnchantmentPredicate>
描述
A consumer that will be used to configure the EnchantmentPredicate.

Link to withStoredEnchantmentPredicate

Name: withStoredEnchantmentPredicate

Creates and adds a new EnchantmentPredicate for the given MCEnchantment to the list of predicates to match against the item's stored enchantments.

The predicate that will be configured is already configured to target the specified enchantment.

The added predicate is simply added to the list. No validity checks are performed, meaning that there may be multiple predicates that target a single enchantment. In this case, they all need to match, thus they have to have compatible bounds.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withStoredEnchantmentPredicate(enchantment as MCEnchantment, builder as Consumer<EnchantmentPredicate>) as ItemPredicate
参数类型描述
参数
enchantment
类型
MCEnchantment
描述
The enchantment that should be checked.
参数
生成器
类型
Consumer<EnchantmentPredicate>
描述
A consumer that will be used to configure the EnchantmentPredicate.

Name: withTag

Sets the MCTag<T> that this predicate should use for matching.

The predicate will successfully match only if the supplied item is contained within the given tag.

Specifying both a tag and an item to match against will make the tag take precedence over the item.

Returns: This predicate for chaining.
Return Type: ItemPredicate

ZenScript
Copy
ItemPredicate.withTag(tag as MCTag<MCItemDefinition>) as ItemPredicate
参数类型描述
参数
tag #标签
类型
MCTag<MCItemDefinition>
描述
The tag the predicate should use for matching.