Record Class UpgradeData<T extends UpgradeBase>

java.lang.Object
java.lang.Record
dan200.computercraft.api.upgrades.UpgradeData<T>
Type Parameters:
T - The type of upgrade, either ITurtleUpgrade or IPocketUpgrade.
Record Components:
holder - The current upgrade holder.
data - The upgrade's data.

public record UpgradeData<T extends UpgradeBase>(net.minecraft.core.Holder.Reference<T extends UpgradeBase> holder, net.minecraft.core.component.DataComponentPatch data) extends Record
An upgrade (i.e. a ITurtleUpgrade) and its current upgrade data.
  • Constructor Summary

    Constructors
    Constructor
    Description
    UpgradeData(net.minecraft.core.Holder.Reference<T> holder, net.minecraft.core.component.DataComponentPatch data)
    Creates an instance of a UpgradeData record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    net.minecraft.core.component.DataComponentPatch
    Returns the value of the data record component.
    final boolean
    Indicates whether some other object is "equal to" this one.
    net.minecraft.world.item.ItemStack
    Get the upgrade item for this upgrade.
    final int
    Returns a hash code value for this object.
    net.minecraft.core.Holder.Reference<T>
    Returns the value of the holder record component.
    static <T extends UpgradeBase>
    UpgradeData<T>
    of(net.minecraft.core.Holder.Reference<T> holder, net.minecraft.core.component.DataComponentPatch data)
    A utility method to construct a new UpgradeData instance.
    static <T extends UpgradeBase>
    UpgradeData<T>
    ofDefault(net.minecraft.core.Holder.Reference<T> holder)
    Create an UpgradeData containing the default data for an upgrade.
    final String
    Returns a string representation of this record class.
    Get the current upgrade.

    Methods inherited from class java.lang.Object

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

    • UpgradeData

      public UpgradeData(net.minecraft.core.Holder.Reference<T> holder, net.minecraft.core.component.DataComponentPatch data)
      Creates an instance of a UpgradeData record class.
      Parameters:
      holder - the value for the holder record component
      data - the value for the data record component
  • Method Details

    • of

      public static <T extends UpgradeBase> UpgradeData<T> of(net.minecraft.core.Holder.Reference<T> holder, net.minecraft.core.component.DataComponentPatch data)
      A utility method to construct a new UpgradeData instance.
      Type Parameters:
      T - The type of upgrade.
      Parameters:
      holder - An upgrade.
      data - The upgrade's data.
      Returns:
      The new UpgradeData instance.
    • ofDefault

      public static <T extends UpgradeBase> UpgradeData<T> ofDefault(net.minecraft.core.Holder.Reference<T> holder)
      Create an UpgradeData containing the default data for an upgrade.
      Type Parameters:
      T - The type of upgrade.
      Parameters:
      holder - The upgrade instance.
      Returns:
      The default upgrade data.
    • upgrade

      public T upgrade()
      Get the current upgrade.
      Returns:
      The current upgrade.
    • getUpgradeItem

      public net.minecraft.world.item.ItemStack getUpgradeItem()
      Get the upgrade item for this upgrade.

      This returns a defensive copy of the item, to prevent accidental mutation of the upgrade data or original upgrade stack.

      Returns:
      This upgrade's item.
    • 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.
    • holder

      public net.minecraft.core.Holder.Reference<T> holder()
      Returns the value of the holder record component.
      Returns:
      the value of the holder record component
    • data

      public net.minecraft.core.component.DataComponentPatch data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component