Class SizedIngredient

java.lang.Object
net.neoforged.neoforge.common.crafting.SizedIngredient

public final class SizedIngredient extends Object
Standard implementation for an ingredient and a count.

Ingredient does not perform count checks, so this class is used to wrap an ingredient with a count, and provide a standard serialization format.

  • Field Details

    • FLAT_CODEC

      public static final com.mojang.serialization.Codec<SizedIngredient> FLAT_CODEC
      The "flat" codec for SizedIngredient.

      The count is serialized inline with the rest of the ingredient, for example:

      
       {
           "item": "minecraft:apple",
           "count": 3
       }
       
      Array ingredients are serialized using the compound ingredient type:
      
       {
           "type": "neoforge:compound",
           "ingredients": [
               { "item": "minecraft:coal" },
               { "item": "minecraft:charcoal" }
           ],
           "count": 2
       }
       
      See Ingredient.MAP_CODEC_NONEMPTY for details of the ingredient serialization.
    • NESTED_CODEC

      public static final com.mojang.serialization.Codec<SizedIngredient> NESTED_CODEC
      The "nested" codec for SizedIngredient.

      The count is serialized separately from the rest of the ingredient, for example:

      
       {
           "ingredient": {
               "item": "minecraft:apple"
           },
           "count": 3
       }
       
    • STREAM_CODEC

      public static final StreamCodec<RegistryFriendlyByteBuf,SizedIngredient> STREAM_CODEC
    • ingredient

      private final Ingredient ingredient
    • count

      private final int count
    • cachedStacks

      @Nullable private @Nullable ItemStack[] cachedStacks
  • Constructor Details

    • SizedIngredient

      public SizedIngredient(Ingredient ingredient, int count)
  • Method Details

    • of

      public static SizedIngredient of(ItemLike item, int count)
      Helper method to create a simple sized ingredient that matches a single item.
    • of

      public static SizedIngredient of(TagKey<Item> tag, int count)
      Helper method to create a simple sized ingredient that matches items in a tag.
    • ingredient

      public Ingredient ingredient()
    • count

      public int count()
    • test

      public boolean test(ItemStack stack)
      Performs a size-sensitive test on the given stack.
      Returns:
      true if the stack matches the ingredient and has at least the required count.
    • getItems

      public ItemStack[] getItems()
      Returns a list of the stacks from this ingredient, with an updated count.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object