Record Class Product

java.lang.Object
java.lang.Record
forestry.api.core.Product
Record Components:
item - The item this product represents.
count - The count the produced stack should have.
patch - The data components to apply to the item. Use DataComponentPatch.EMPTY in place of null.
chance - The chance (from 0.0 to 1.0) that this product is produced. Support for values higher than 1.0 varies by machine.
All Implemented Interfaces:
IProduct

public record Product(net.minecraft.world.item.Item item, int count, net.minecraft.core.component.DataComponentPatch patch, float chance) extends Record implements IProduct
Default implementation of IProduct. Used in most cases.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<Product>
     
    static final com.mojang.serialization.MapCodec<Product>
     
    static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,Product>
     
    static final ProductType<Product>
    The default product type.

    Fields inherited from interface forestry.api.core.IProduct

    ITEM_ONLY_STRATEGY, LIST_CODEC, LIST_STREAM_CODEC
  • Constructor Summary

    Constructors
    Constructor
    Description
    Product(net.minecraft.world.item.Item item, int count, net.minecraft.core.component.DataComponentPatch patch, float chance)
    Creates an instance of a Product record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    float
    Returns the value of the chance record component.
    int
    Returns the value of the count record component.
    net.minecraft.world.item.ItemStack
     
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    net.minecraft.world.item.Item
    Returns the value of the item record component.
    static Product
    of(net.minecraft.world.item.Item item)
     
    static Product
    of(net.minecraft.world.item.Item item, int amount, float chance)
     
    net.minecraft.core.component.DataComponentPatch
    Returns the value of the patch record component.
    final String
    Returns a string representation of this record class.
    The type of this product, used to (de)serialize it via IProduct.CODEC.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface forestry.api.core.IProduct

    createRandomStack
  • Field Details

    • MAP_CODEC

      public static final com.mojang.serialization.MapCodec<Product> MAP_CODEC
    • CODEC

      public static final com.mojang.serialization.Codec<Product> CODEC
    • STREAM_CODEC

      public static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,Product> STREAM_CODEC
    • TYPE

      public static final ProductType<Product> TYPE
      The default product type. The dispatch codec IProduct.CODEC treats this type specially: products of this type serialize without a "type" key, and a missing "type" key on decode resolves back to it. This keeps the common case (a plain item) as clean, backwards-compatible JSON.
  • Constructor Details

    • Product

      public Product(net.minecraft.world.item.Item item, int count, net.minecraft.core.component.DataComponentPatch patch, float chance)
      Creates an instance of a Product record class.
      Parameters:
      item - the value for the item record component
      count - the value for the count record component
      patch - the value for the patch record component
      chance - the value for the chance record component
  • Method Details

    • type

      public ProductType<?> type()
      Description copied from interface: IProduct
      The type of this product, used to (de)serialize it via IProduct.CODEC. Most products are plain Product instances and return TYPE, which the dispatch codec treats as the default: it serializes without a "type" key. Dynamic products (e.g. a randomized firework) return their own type so their randomness survives the round-trip through JSON and network sync.
      Specified by:
      type in interface IProduct
      Returns:
      The type of this product.
    • createStack

      public net.minecraft.world.item.ItemStack createStack()
      Specified by:
      createStack in interface IProduct
      Returns:
      A new stack of this product. If your product is dynamic, return a "default" nonempty stack.
    • of

      public static Product of(net.minecraft.world.item.Item item)
    • of

      public static Product of(net.minecraft.world.item.Item item, int amount, float chance)
    • 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. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      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.
    • item

      public net.minecraft.world.item.Item item()
      Returns the value of the item record component.
      Specified by:
      item in interface IProduct
      Returns:
      the value of the item record component
    • count

      public int count()
      Returns the value of the count record component.
      Returns:
      the value of the count record component
    • patch

      public net.minecraft.core.component.DataComponentPatch patch()
      Returns the value of the patch record component.
      Returns:
      the value of the patch record component
    • chance

      public float chance()
      Returns the value of the chance record component.
      Specified by:
      chance in interface IProduct
      Returns:
      the value of the chance record component