Record Class DifferenceIngredient
java.lang.Object
java.lang.Record
net.neoforged.neoforge.common.crafting.DifferenceIngredient
- All Implemented Interfaces:
ICustomIngredient
public record DifferenceIngredient(net.minecraft.world.item.crafting.Ingredient base, net.minecraft.world.item.crafting.Ingredient subtracted)
extends Record
implements ICustomIngredient
Ingredient that matches everything from the first ingredient that is not included in the second ingredient
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final net.minecraft.world.item.crafting.Ingredient
The field for thebase
record component.static final com.mojang.serialization.MapCodec
<DifferenceIngredient> private final net.minecraft.world.item.crafting.Ingredient
The field for thesubtracted
record component. -
Constructor Summary
ConstructorsConstructorDescriptionDifferenceIngredient
(net.minecraft.world.item.crafting.Ingredient base, net.minecraft.world.item.crafting.Ingredient subtracted) Creates an instance of aDifferenceIngredient
record class. -
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.world.item.crafting.Ingredient
base()
Returns the value of thebase
record component.final boolean
Indicates whether some other object is "equal to" this one.getType()
Returns the type of this ingredient.final int
hashCode()
Returns a hash code value for this object.boolean
isSimple()
Returns whether this ingredient always requires direct stack testing.Stream
<net.minecraft.core.Holder<net.minecraft.world.item.Item>> items()
Returns the list of items that this ingredient accepts.static net.minecraft.world.item.crafting.Ingredient
of
(net.minecraft.world.item.crafting.Ingredient base, net.minecraft.world.item.crafting.Ingredient subtracted) Gets the difference from the two ingredientsnet.minecraft.world.item.crafting.Ingredient
Returns the value of thesubtracted
record component.boolean
test
(net.minecraft.world.item.ItemStack stack) Checks if a stack matches this ingredient.final String
toString()
Returns a string representation of this record class.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
Methods inherited from interface net.neoforged.neoforge.common.crafting.ICustomIngredient
display, toVanilla
-
Field Details
-
base
private final net.minecraft.world.item.crafting.Ingredient baseThe field for thebase
record component. -
subtracted
private final net.minecraft.world.item.crafting.Ingredient subtractedThe field for thesubtracted
record component. -
CODEC
-
-
Constructor Details
-
DifferenceIngredient
public DifferenceIngredient(net.minecraft.world.item.crafting.Ingredient base, net.minecraft.world.item.crafting.Ingredient subtracted) Creates an instance of aDifferenceIngredient
record class.- Parameters:
base
- the value for thebase
record componentsubtracted
- the value for thesubtracted
record component
-
-
Method Details
-
items
Description copied from interface:ICustomIngredient
Returns the list of items that this ingredient accepts.The following guidelines should be followed for good compatibility:
- At least one item must be returned for the ingredient not to be considered empty. Empty ingredients invalidate the entire recipe.
- The ingredient should return all
Item
s it might possible accept. This allows mods that inspect the ingredient to figure out which stacks it might accept. - Returned items might not always be accepted by the ingredient, as an ingredient might still perform additional NBT-dependent tests.
- An exception is ingredients that are simple,
for which
testing a stack
is equivalent to testing if the item is in the returned list.
Note: no caching needs to be done by the implementation, this is already handled by the ingredient itself.
- Specified by:
items
in interfaceICustomIngredient
- Returns:
- the list of items that this ingredient accepts
-
test
public boolean test(net.minecraft.world.item.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 interfaceICustomIngredient
- 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 interfaceICustomIngredient
- Returns:
true
if this ingredient ignores NBT data when matching stacks,false
otherwise- See Also:
-
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 interfaceICustomIngredient
- Returns:
- the type of this ingredient
-
of
public static net.minecraft.world.item.crafting.Ingredient of(net.minecraft.world.item.crafting.Ingredient base, net.minecraft.world.item.crafting.Ingredient subtracted) Gets the difference from the two ingredients- Parameters:
base
- Ingredient the item must matchsubtracted
- Ingredient the item must not match- Returns:
- Ingredient that
base
anything in base that is not insubtracted
-
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. -
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. -
equals
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 withObjects::equals(Object,Object)
. -
base
public net.minecraft.world.item.crafting.Ingredient base()Returns the value of thebase
record component.- Returns:
- the value of the
base
record component
-
subtracted
public net.minecraft.world.item.crafting.Ingredient subtracted()Returns the value of thesubtracted
record component.- Returns:
- the value of the
subtracted
record component
-