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, eitherITurtleUpgrade
orIPocketUpgrade
.- 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 Summary
ConstructorsConstructorDescriptionUpgradeData
(T upgrade, net.minecraft.nbt.CompoundTag data) Creates an instance of aUpgradeData
record class. -
Method Summary
Modifier and TypeMethodDescriptioncopy()
Take a copy of thisUpgradeData
.static <T extends UpgradeBase>
@Nullable UpgradeData<T>copyOf
(@Nullable UpgradeData<T> upgrade) Take a copy of a (possiblynull
)UpgradeData
instance.net.minecraft.nbt.CompoundTag
data()
Returns the value of thedata
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
hashCode()
Returns a hash code value for this object.static <T extends UpgradeBase>
UpgradeData<T>of
(T upgrade, net.minecraft.nbt.CompoundTag data) A utility method to construct a newUpgradeData
instance.static <T extends UpgradeBase>
UpgradeData<T>ofDefault
(T upgrade) Create anUpgradeData
containing the default data for an upgrade.final String
toString()
Returns a string representation of this record class.upgrade()
Returns the value of theupgrade
record component.
-
Constructor Details
-
Method Details
-
of
public static <T extends UpgradeBase> UpgradeData<T> of(T upgrade, net.minecraft.nbt.CompoundTag data) A utility method to construct a newUpgradeData
instance.- Type Parameters:
T
- The type of upgrade.- Parameters:
upgrade
- An upgrade.data
- The upgrade's data.- Returns:
- The new
UpgradeData
instance.
-
ofDefault
Create anUpgradeData
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") public static <T extends UpgradeBase> @Nullable UpgradeData<T> copyOf(@Nullable UpgradeData<T> upgrade) Take a copy of a (possiblynull
)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
Take a copy of thisUpgradeData
. 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
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. All components in this record class are compared withObjects::equals(Object,Object)
. -
upgrade
Returns the value of theupgrade
record component.- Returns:
- the value of the
upgrade
record component
-
data
public net.minecraft.nbt.CompoundTag data()Returns the value of thedata
record component.- Returns:
- the value of the
data
record component
-