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 Summary

    Fields
    Modifier and Type
    Field
    Description
    private final int
     
    private final net.minecraft.world.item.crafting.Ingredient
     
    static final com.mojang.serialization.Codec<SizedIngredient>
    The "nested" codec for SizedIngredient.
    static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,SizedIngredient>
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    SizedIngredient(net.minecraft.world.item.crafting.Ingredient ingredient, int count)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    int
     
    boolean
     
    int
     
    net.minecraft.world.item.crafting.Ingredient
     
    of(net.minecraft.world.level.ItemLike item, int count)
    Helper method to create a simple sized ingredient that matches a single item.
    boolean
    test(net.minecraft.world.item.ItemStack stack)
    Performs a size-sensitive test on the given stack.
     

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • 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": "minecraft:apple",
           "count": 3
       }
       
    • STREAM_CODEC

      public static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,SizedIngredient> STREAM_CODEC
    • ingredient

      private final net.minecraft.world.item.crafting.Ingredient ingredient
    • count

      private final int count
  • Constructor Details

    • SizedIngredient

      public SizedIngredient(net.minecraft.world.item.crafting.Ingredient ingredient, int count)
  • Method Details

    • of

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

      public net.minecraft.world.item.crafting.Ingredient ingredient()
    • count

      public int count()
    • test

      public boolean test(net.minecraft.world.item.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.
    • 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