Record Class CropOverride

java.lang.Object
java.lang.Record
net.darkhax.botanypots.common.api.data.components.CropOverride
Record Components:
crop - The crop to use instead of the default recipe-based lookup.

public record CropOverride(Crop crop) extends Record
This item component allows specific items to define a crop that differs from their default recipe-based behavior. For example, a specific dirt item with this override could grow diamonds while all other instances are not valid seeds and have no crop.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final com.mojang.serialization.Codec<CropOverride>
     
    static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,CropOverride>
     
    static final net.darkhax.bookshelf.common.api.function.CachedSupplier<net.minecraft.core.component.DataComponentType<CropOverride>>
     
    static final net.minecraft.resources.ResourceLocation
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of a CropOverride record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    Returns the value of the crop record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    get(net.minecraft.world.item.ItemStack stack)
    Gets the override value for an item if one exists.
    final int
    Returns a hash code value for this object.
    static void
    set(net.minecraft.world.item.ItemStack stack, Crop crop)
    Applies a crop override to the specified item.
    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
  • Field Details

    • CODEC

      public static final com.mojang.serialization.Codec<CropOverride> CODEC
    • STREAM

      public static final net.minecraft.network.codec.StreamCodec<net.minecraft.network.RegistryFriendlyByteBuf,CropOverride> STREAM
    • TYPE_ID

      public static final net.minecraft.resources.ResourceLocation TYPE_ID
    • TYPE

      public static final net.darkhax.bookshelf.common.api.function.CachedSupplier<net.minecraft.core.component.DataComponentType<CropOverride>> TYPE
  • Constructor Details

    • CropOverride

      public CropOverride(Crop crop)
      Creates an instance of a CropOverride record class.
      Parameters:
      crop - the value for the crop record component
  • Method Details

    • get

      public static Optional<CropOverride> get(net.minecraft.world.item.ItemStack stack)
      Gets the override value for an item if one exists.
      Parameters:
      stack - The stack to query.
      Returns:
      The current crop override as an optional. If an override is specified the optional will be present, otherwise it will be empty.
    • set

      public static void set(net.minecraft.world.item.ItemStack stack, Crop crop)
      Applies a crop override to the specified item.
      Parameters:
      stack - The item to apply the override to.
      crop - The crop to attach as an override.
    • 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. All components in this record class are compared with Objects::equals(Object,Object).
      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.
    • crop

      public Crop crop()
      Returns the value of the crop record component.
      Returns:
      the value of the crop record component