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.
tag - The NBT tag
chance -
All Implemented Interfaces:
IProduct

public record Product(net.minecraft.world.item.Item item, int count, @Nullable net.minecraft.nbt.CompoundTag tag, 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>
     

    Fields inherited from interface forestry.api.core.IProduct

    ITEM_ONLY_STRATEGY
  • Constructor Summary

    Constructors
    Constructor
    Description
    Product(net.minecraft.world.item.Item item, int count, net.minecraft.nbt.CompoundTag tag, 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.
    static Product
    fromNetwork(net.minecraft.network.FriendlyByteBuf buffer)
     
    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.nbt.CompoundTag
    tag()
    Returns the value of the tag record component.
    static void
    toNetwork(net.minecraft.network.FriendlyByteBuf buffer, Product product)
     
    final String
    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 forestry.api.core.IProduct

    createRandomStack
  • Field Details

    • CODEC

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

    • Product

      public Product(net.minecraft.world.item.Item item, int count, @Nullable net.minecraft.nbt.CompoundTag tag, 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
      tag - the value for the tag record component
      chance - the value for the chance record component
  • Method Details

    • 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)
    • toNetwork

      public static void toNetwork(net.minecraft.network.FriendlyByteBuf buffer, Product product)
    • fromNetwork

      public static Product fromNetwork(net.minecraft.network.FriendlyByteBuf buffer)
    • 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
    • tag

      @Nullable public net.minecraft.nbt.CompoundTag tag()
      Returns the value of the tag record component.
      Returns:
      the value of the tag 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