Class DefaultCustomIngredients
-
Method Summary
Modifier and TypeMethodDescriptionstatic Ingredient
all
(Ingredient... ingredients) Creates an ingredient that matches when its sub-ingredients all match.static Ingredient
any
(Ingredient... ingredients) Creates an ingredient that matches when any of its sub-ingredients matches.static Ingredient
components
(ItemStack stack) Creates an ingredient that matches the components specified in the passed item stack.static Ingredient
components
(Ingredient base, UnaryOperator<ComponentChanges.Builder> operator) static Ingredient
components
(Ingredient base, ComponentChanges components) Creates an ingredient that wraps another ingredient to also check for matching components.static Ingredient
customData
(Ingredient base, NbtCompound nbt) Creates an ingredient that wraps another ingredient to also check for stack's custom data.static Ingredient
difference
(Ingredient base, Ingredient subtracted) Creates an ingredient that matches if its base ingredient matches, and its subtracted ingredient does not match.
-
Method Details
-
all
Creates an ingredient that matches when its sub-ingredients all match.The JSON format is as follows:
{ "fabric:type": "fabric:all", "ingredients": [ // sub-ingredient 1, // sub-ingredient 2, // etc... ] }
- Throws:
IllegalArgumentException
- if the array is empty
-
any
Creates an ingredient that matches when any of its sub-ingredients matches.The JSON format is as follows:
{ "fabric:type": "fabric:any", "ingredients": [ // sub-ingredient 1, // sub-ingredient 2, // etc... ] }
- Throws:
IllegalArgumentException
- if the array is empty
-
difference
Creates an ingredient that matches if its base ingredient matches, and its subtracted ingredient does not match.The JSON format is as follows:
{ "fabric:type": "fabric:difference", "base": // base ingredient, "subtracted": // subtracted ingredient }
-
components
Creates an ingredient that wraps another ingredient to also check for matching components.Use
ComponentChanges.builder()
to add or remove components. Added components are checked to match on the target stack, either as the default or the item stack-specific override. Removed components are checked to not exist in the target stack. The check is "non-strict"; components that are neither added nor removed are ignored.The JSON format is as follows:
{ "fabric:type": "fabric:components", "base": // base ingredient, "components": // components to be checked }
- Throws:
IllegalArgumentException
- if there are no components to check
-
components
public static Ingredient components(Ingredient base, UnaryOperator<ComponentChanges.Builder> operator) - See Also:
-
components
Creates an ingredient that matches the components specified in the passed item stack. Note that the count of the stack is ignored.This does not check for the default component of the item stack that remains unchanged. For example, an undamaged pickaxe matches any pickaxes (regardless of damage), because having zero damage is the default, but a pickaxe with 1 damage would only match another pickaxe with 1 damage. To only match the default value, use the other methods and explicitly specify the default value.
- Throws:
IllegalArgumentException
- ifstack
has no changed components- See Also:
-
customData
Creates an ingredient that wraps another ingredient to also check for stack's custom data. This check is non-strict; the ingredient custom data must be a subset of the stack custom data. This is useful for mods that still rely on NBT-based custom data instead of custom components, such as those requiring vanilla compatibility or interacting with another data packs.Passing a
null
or emptynbt
is not allowed, as it would always match. For strict matching, usecomponents(Ingredient, UnaryOperator)
like this instead:components(base, builder -> builder.add(DataComponentTypes.CUSTOM_DATA, NbtComponent.of(nbt))); // or, to check for absence of custom data: components(base, builder -> builder.remove(DataComponentTypes.CUSTOM_DATA));
See
NbtHelper.matches(net.minecraft.nbt.NbtElement, net.minecraft.nbt.NbtElement, boolean)
for how matching works.The JSON format is as follows:
{ "fabric:type": "fabric:custom_data", "base": // base ingredient, "nbt": // NBT tag to match, either in JSON directly or a string representation }
- Throws:
IllegalArgumentException
- ifnbt
isnull
or empty
-