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:
upgrade - The current upgrade.
data - The upgrade's data.

public record UpgradeData<T extends UpgradeBase>(T extends UpgradeBase upgrade, net.minecraft.nbt.CompoundTag data) extends Record
An upgrade (i.e. a ITurtleUpgrade) and its current upgrade data.

IMPORTANT: The data() in an upgrade data is often a reference to the original upgrade data. Be careful to take a defensive copy if you plan to use the data in this upgrade.

  • Constructor Details

    • UpgradeData

      public UpgradeData(T upgrade, net.minecraft.nbt.CompoundTag data)
      Creates an instance of a UpgradeData record class.
      Parameters:
      upgrade - the value for the upgrade record component
      data - the value for the data record component
  • Method Details

    • of

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

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

      @Contract("!null -> !null; null -> null") @Nullable public static <T extends UpgradeBase> UpgradeData<T> copyOf(@Nullable UpgradeData<T> upgrade)
      Take a copy of a (possibly null) UpgradeData instance.
      Type Parameters:
      T - The type of upgrade.
      Parameters:
      upgrade - The copied upgrade data.
      Returns:
      The newly created upgrade data.
    • 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.
    • copy

      public UpgradeData<T> copy()
      Take a copy of this UpgradeData. This returns a new instance with the same upgrade and a fresh copy of the upgrade data.
      Returns:
      A copy of the current instance.
    • 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.
    • upgrade

      public T upgrade()
      Returns the value of the upgrade record component.
      Returns:
      the value of the upgrade record component
    • data

      public net.minecraft.nbt.CompoundTag data()
      Returns the value of the data record component.
      Returns:
      the value of the data record component