Package forestry.api.core
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. UseDataComponentPatch.EMPTYin place ofnull.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
FieldsModifier and TypeFieldDescriptionstatic 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
ConstructorsConstructorDescriptionProduct(net.minecraft.world.item.Item item, int count, net.minecraft.core.component.DataComponentPatch patch, float chance) Creates an instance of aProductrecord class. -
Method Summary
Modifier and TypeMethodDescriptionfloatchance()Returns the value of thechancerecord component.intcount()Returns the value of thecountrecord component.net.minecraft.world.item.ItemStackfinal booleanIndicates whether some other object is "equal to" this one.final inthashCode()Returns a hash code value for this object.net.minecraft.world.item.Itemitem()Returns the value of theitemrecord component.static Productof(net.minecraft.world.item.Item item) static Productof(net.minecraft.world.item.Item item, int amount, float chance) net.minecraft.core.component.DataComponentPatchpatch()Returns the value of thepatchrecord component.final StringtoString()Returns a string representation of this record class.ProductType<?> type()The type of this product, used to (de)serialize it viaIProduct.CODEC.Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface forestry.api.core.IProduct
createRandomStack
-
Field Details
-
MAP_CODEC
-
CODEC
-
STREAM_CODEC
public static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,Product> STREAM_CODEC -
TYPE
The default product type. The dispatch codecIProduct.CODECtreats 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 aProductrecord class.
-
-
Method Details
-
type
Description copied from interface:IProductThe type of this product, used to (de)serialize it viaIProduct.CODEC. Most products are plainProductinstances and returnTYPE, 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. -
createStack
public net.minecraft.world.item.ItemStack createStack()- Specified by:
createStackin interfaceIProduct- Returns:
- A new stack of this product. If your product is dynamic, return a "default" nonempty stack.
-
of
-
of
-
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. Reference components are compared withObjects::equals(Object,Object); primitive components are compared with '=='. -
item
public net.minecraft.world.item.Item item()Returns the value of theitemrecord component. -
count
public int count()Returns the value of thecountrecord component.- Returns:
- the value of the
countrecord component
-
patch
public net.minecraft.core.component.DataComponentPatch patch()Returns the value of thepatchrecord component.- Returns:
- the value of the
patchrecord component
-
chance
public float chance()Returns the value of thechancerecord component.
-