Record Class DifferenceIngredient

java.lang.Object
java.lang.Record
net.neoforged.neoforge.common.crafting.DifferenceIngredient
All Implemented Interfaces:
ICustomIngredient

public record DifferenceIngredient(Ingredient base, Ingredient subtracted) extends Record implements ICustomIngredient
Ingredient that matches everything from the first ingredient that is not included in the second ingredient
  • Field Details

    • base

      private final Ingredient base
      The field for the base record component.
    • subtracted

      private final Ingredient subtracted
      The field for the subtracted record component.
    • CODEC

      public static final com.mojang.serialization.MapCodec<DifferenceIngredient> CODEC
  • Constructor Details

    • DifferenceIngredient

      public DifferenceIngredient(Ingredient base, Ingredient subtracted)
      Creates an instance of a DifferenceIngredient record class.
      Parameters:
      base - the value for the base record component
      subtracted - the value for the subtracted record component
  • Method Details

    • getItems

      public Stream<ItemStack> getItems()
      Description copied from interface: ICustomIngredient
      Returns the list of stacks that this ingredient accepts.

      The following guidelines should be followed for good compatibility:

      • These stacks are generally used for display purposes, and need not be exhaustive or perfectly accurate.
      • An exception is ingredients that are simple, for which it is important that the returned stacks correspond exactly to all the accepted Items.
      • At least one stack must be returned for the ingredient not to be considered accidentally empty.
      • The ingredient should try to return at least one stack with each accepted Item. This allows mods that inspect the ingredient to figure out which stacks it might accept.

      Note: no caching needs to be done by the implementation, this is already handled by the ingredient itself.

      Specified by:
      getItems in interface ICustomIngredient
      Returns:
      the list of stacks that this ingredient accepts
    • test

      public boolean test(ItemStack stack)
      Description copied from interface: ICustomIngredient
      Checks if a stack matches this ingredient. The stack must not be modified in any way.
      Specified by:
      test in interface ICustomIngredient
      Parameters:
      stack - the stack to test
      Returns:
      true if the stack matches this ingredient, false otherwise
    • isSimple

      public boolean isSimple()
      Description copied from interface: ICustomIngredient
      Returns whether this ingredient always requires direct stack testing.
      Specified by:
      isSimple in interface ICustomIngredient
      Returns:
      true if this ingredient ignores NBT data when matching stacks, false otherwise
      See Also:
    • getType

      public IngredientType<?> getType()
      Description copied from interface: ICustomIngredient
      Returns the type of this ingredient.

      The type must be registered to NeoForgeRegistries.INGREDIENT_TYPES.

      Specified by:
      getType in interface ICustomIngredient
      Returns:
      the type of this ingredient
    • of

      public static Ingredient of(Ingredient base, Ingredient subtracted)
      Gets the difference from the two ingredients
      Parameters:
      base - Ingredient the item must match
      subtracted - Ingredient the item must not match
      Returns:
      Ingredient that base anything in base that is not in subtracted
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • base

      public Ingredient base()
      Returns the value of the base record component.
      Returns:
      the value of the base record component
    • subtracted

      public Ingredient subtracted()
      Returns the value of the subtracted record component.
      Returns:
      the value of the subtracted record component