Interface UpgradeBase
- All Known Subinterfaces:
IPocketUpgrade
,ITurtleUpgrade
- All Known Implementing Classes:
AbstractPocketUpgrade
,AbstractTurtleUpgrade
ITurtleUpgrade
and IPocketUpgrade
.-
Method Summary
Modifier and TypeMethodDescriptionnet.minecraft.network.chat.Component
A description of this upgrade for use in item names.net.minecraft.world.item.ItemStack
Return an item stack representing the type of item that a computer must be crafted with to create a version which holds this upgrade.static String
getDefaultAdjective
(net.minecraft.resources.ResourceLocation id) Get a suitable default unlocalised adjective for an upgrade ID.UpgradeType
<?> getType()
Get the type of this upgrade.default net.minecraft.core.component.DataComponentPatch
getUpgradeData
(net.minecraft.world.item.ItemStack stack) Extract upgrade data from anItemStack
.default net.minecraft.world.item.ItemStack
getUpgradeItem
(net.minecraft.core.component.DataComponentPatch upgradeData) Returns the item stack representing a currently equipped turtle upgrade.default boolean
isItemSuitable
(net.minecraft.world.item.ItemStack stack) Determine if an item is suitable for being used for this upgrade.
-
Method Details
-
getType
UpgradeType<?> getType()Get the type of this upgrade.- Returns:
- The type of this upgrade.
-
getAdjective
net.minecraft.network.chat.Component getAdjective()A description of this upgrade for use in item names.This should typically be a translation key, rather than a hard coded string.
Examples of built-in adjectives are "Wireless", "Mining" and "Crafty".
- Returns:
- The text component for this upgrade's adjective.
-
getCraftingItem
net.minecraft.world.item.ItemStack getCraftingItem()Return an item stack representing the type of item that a computer must be crafted with to create a version which holds this upgrade. This item stack is also used to determine the upgrade given byturtle.equipLeft()
orpocket.equipBack()
This should be constant over a session (or at least a datapack reload). It is recommended that you cache the stack too, in order to prevent constructing it every time the method is called.
- Returns:
- The item stack to craft with, or
ItemStack.EMPTY
if it cannot be crafted.
-
getUpgradeItem
default net.minecraft.world.item.ItemStack getUpgradeItem(net.minecraft.core.component.DataComponentPatch upgradeData) Returns the item stack representing a currently equipped turtle upgrade.While upgrades can store upgrade data (
ITurtleAccess.getUpgradeData(TurtleSide)
andIPocketAccess.getUpgradeData()
}, by default this data is discarded when an upgrade is unequipped, and the original item stack is returned.By overriding this method, you can create a new
ItemStack
which contains enough data to re-create the upgrade data if the item is re-equipped.When overriding this, you should override
getUpgradeData(ItemStack)
andisItemSuitable(ItemStack)
at the same time,- Parameters:
upgradeData
- The current upgrade data. This should NOT be mutated.- Returns:
- The item stack returned when unequipping.
-
getUpgradeData
default net.minecraft.core.component.DataComponentPatch getUpgradeData(net.minecraft.world.item.ItemStack stack) Extract upgrade data from anItemStack
.This upgrade data will be available with
ITurtleAccess.getUpgradeData(TurtleSide)
orIPocketAccess.getUpgradeData()
.This should be an inverse to
getUpgradeItem(DataComponentPatch)
.- Parameters:
stack
- The stack that was equipped by the turtle or pocket computer. This will have the same item asgetCraftingItem()
.- Returns:
- The upgrade data that should be set on the turtle or pocket computer.
-
isItemSuitable
default boolean isItemSuitable(net.minecraft.world.item.ItemStack stack) Determine if an item is suitable for being used for this upgrade.When un-equipping an upgrade, we return
getCraftingItem()
rather than the original stack. In order to prevent people losing items with enchantments (or repairing items with non-0 damage), we impose additional checks on the item.The default check requires that any NBT is exactly the same as the crafting item, but this may be relaxed for your upgrade.
- Parameters:
stack
- The stack to check. This is guaranteed to be non-empty and have the same item asgetCraftingItem()
.- Returns:
- If this stack may be used to equip this upgrade.
-
getDefaultAdjective
Get a suitable default unlocalised adjective for an upgrade ID. This converts "modid:some_upgrade" to "upgrade.modid.some_upgrade.adjective".- Parameters:
id
- The upgrade ID.- Returns:
- The generated adjective.
- See Also:
-