Package cn.nukkit.item.enchantment
Class Enchantment
java.lang.Object
cn.nukkit.item.enchantment.Enchantment
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
EnchantmentBindingCurse
,EnchantmentBow
,EnchantmentCrossbow
,EnchantmentDamage
,EnchantmentDurability
,EnchantmentEfficiency
,EnchantmentFireAspect
,EnchantmentFrostWalker
,EnchantmentKnockback
,EnchantmentLoot
,EnchantmentLure
,EnchantmentMending
,EnchantmentProtection
,EnchantmentSilkTouch
,EnchantmentSoulSpeed
,EnchantmentSwiftSneak
,EnchantmentThorns
,EnchantmentTrident
,EnchantmentVanishingCurse
,EnchantmentWaterBreath
,EnchantmentWaterWalker
,EnchantmentWaterWorker
An enchantment that can be to applied to an item.
- Author:
- MagicDroidX (Nukkit Project)
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
protected static Map<Identifier,
Enchantment> static final Enchantment[]
protected static Enchantment[]
final int
The internal ID which this enchantment got registered.static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
static final int
protected final Identifier
protected int
The level of this enchantment.protected final String
The name visible by the player, this is used in conjunction withgetName()
, unless modified with an override, the getter will automatically add "%enchantment." as prefix to grab the translation keystatic final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
static final String
The group of objects that this enchantment can be applied.static final String[]
-
Constructor Summary
ConstructorsModifierConstructorDescriptionprotected
Enchantment
(int id, String name, int weight, EnchantmentType type) Deprecated.protected
Enchantment
(int id, String name, Enchantment.Rarity rarity, EnchantmentType type) Constructs this instance using the given data and with level 1.protected
Enchantment
(Identifier identifier, String name, Enchantment.Rarity rarity, EnchantmentType type) 自定义附魔使用的构造函数 -
Method Summary
Modifier and TypeMethodDescriptionboolean
canEnchant
(Item item) Checks if the given item have a type which is compatible with this enchantment.protected boolean
checkCompatibility
(Enchantment enchantment) Checks if this enchantment can be applied to an item that have the give enchantment without doing reverse check.protected Enchantment
clone()
void
当实体attacker使用具有附魔的武器攻击实体entity时触发void
doPostAttack
(Entity attacker, Entity entity) 当实体entity穿着附魔盔甲,被实体attacker攻击时触发void
doPostHurt
(Entity attacker, Entity entity) 目前没有任何作用static Enchantment
get
(int id) Deprecated.double
getDamageBonus
(Entity entity) 当实体武器具有附魔时触发static Enchantment
getEnchantment
(int id) The same asget(int)
but returns a safe copy of the enchantment.static Enchantment
getEnchantment
(String name) 使用附魔标识符来获取附魔,原版附魔可以不加命名空间,但是自定义附魔必须加上命名空间才能获取static Enchantment[]
Gets an array of all registered enchantments, the objects in the array are linked to the registry, it's not safe to change them.int
getId()
The ID of this enchantment.获取该附魔的标识符,只有自定义附魔才有int
getLevel()
The current level of this enchantment.static String
getLevelString
(int level) int
getMaxEnchantAbility
(int level) The maximum enchantability for the given level as described in https://minecraft.gamepedia.com/Enchanting/Levelsint
The maximum level that can be obtained using an enchanting table.int
The maximum safe level which is possible with this enchantment.int
getMinEnchantAbility
(int level) The minimum enchantability for the given level as described in https://minecraft.gamepedia.com/Enchanting/Levelsint
The minimum safe level which is possible with this enchantment.getName()
float
当实体盔甲具有附魔时触发static String
How rare this enchantment is.static Collection<Enchantment>
Gets a collection with a safe copy of all enchantments that are currently registered.int
Deprecated.static void
init()
boolean
isCompatibleWith
(Enchantment enchantment) Returns true if and only if this enchantment is compatible with the other and the other is also compatible with this enchantment.boolean
isItemAcceptable
(Item item) Deprecated.boolean
isMajor()
static OK<?>
register
(Enchantment... enchantments) static OK<?>
register
(Enchantment enchantment, boolean registerItem) setLevel
(int level) Changes the level of this enchantment.setLevel
(int level, boolean safe) Changes the level of this enchantment.
-
Field Details
-
EMPTY_ARRAY
-
CUSTOM_ENCHANTMENT_ID
-
enchantments
-
customEnchantments
@PowerNukkitXOnly @Since("1.19.60-r1") protected static Map<Identifier,Enchantment> customEnchantments -
ID_PROTECTION_ALL
public static final int ID_PROTECTION_ALL- See Also:
-
NAME_PROTECTION_ALL
- See Also:
-
ID_PROTECTION_FIRE
public static final int ID_PROTECTION_FIRE- See Also:
-
NAME_PROTECTION_FIRE
- See Also:
-
ID_PROTECTION_FALL
public static final int ID_PROTECTION_FALL- See Also:
-
NAME_PROTECTION_FALL
- See Also:
-
ID_PROTECTION_EXPLOSION
public static final int ID_PROTECTION_EXPLOSION- See Also:
-
NAME_PROTECTION_EXPLOSION
- See Also:
-
ID_PROTECTION_PROJECTILE
public static final int ID_PROTECTION_PROJECTILE- See Also:
-
NAME_PROTECTION_PROJECTILE
- See Also:
-
ID_THORNS
public static final int ID_THORNS- See Also:
-
NAME_THORNS
- See Also:
-
ID_WATER_BREATHING
public static final int ID_WATER_BREATHING- See Also:
-
NAME_WATER_BREATHING
- See Also:
-
ID_WATER_WALKER
public static final int ID_WATER_WALKER- See Also:
-
NAME_WATER_WALKER
- See Also:
-
ID_WATER_WORKER
public static final int ID_WATER_WORKER- See Also:
-
NAME_WATER_WORKER
- See Also:
-
ID_DAMAGE_ALL
public static final int ID_DAMAGE_ALL- See Also:
-
NAME_DAMAGE_ALL
- See Also:
-
ID_DAMAGE_SMITE
public static final int ID_DAMAGE_SMITE- See Also:
-
NAME_DAMAGE_SMITE
- See Also:
-
ID_DAMAGE_ARTHROPODS
public static final int ID_DAMAGE_ARTHROPODS- See Also:
-
NAME_DAMAGE_ARTHROPODS
- See Also:
-
ID_KNOCKBACK
public static final int ID_KNOCKBACK- See Also:
-
NAME_KNOCKBACK
- See Also:
-
ID_FIRE_ASPECT
public static final int ID_FIRE_ASPECT- See Also:
-
NAME_FIRE_ASPECT
- See Also:
-
ID_LOOTING
public static final int ID_LOOTING- See Also:
-
NAME_LOOTING
- See Also:
-
ID_EFFICIENCY
public static final int ID_EFFICIENCY- See Also:
-
NAME_EFFICIENCY
- See Also:
-
ID_SILK_TOUCH
public static final int ID_SILK_TOUCH- See Also:
-
NAME_SILK_TOUCH
- See Also:
-
ID_DURABILITY
public static final int ID_DURABILITY- See Also:
-
NAME_DURABILITY
- See Also:
-
ID_FORTUNE_DIGGING
public static final int ID_FORTUNE_DIGGING- See Also:
-
NAME_FORTUNE_DIGGING
- See Also:
-
ID_BOW_POWER
public static final int ID_BOW_POWER- See Also:
-
NAME_BOW_POWER
- See Also:
-
ID_BOW_KNOCKBACK
public static final int ID_BOW_KNOCKBACK- See Also:
-
NAME_BOW_KNOCKBACK
- See Also:
-
ID_BOW_FLAME
public static final int ID_BOW_FLAME- See Also:
-
NAME_BOW_FLAME
- See Also:
-
ID_BOW_INFINITY
public static final int ID_BOW_INFINITY- See Also:
-
NAME_BOW_INFINITY
- See Also:
-
ID_FORTUNE_FISHING
public static final int ID_FORTUNE_FISHING- See Also:
-
NAME_FORTUNE_FISHING
- See Also:
-
ID_LURE
public static final int ID_LURE- See Also:
-
NAME_LURE
- See Also:
-
ID_FROST_WALKER
public static final int ID_FROST_WALKER- See Also:
-
NAME_FROST_WALKER
- See Also:
-
ID_MENDING
public static final int ID_MENDING- See Also:
-
NAME_MENDING
- See Also:
-
ID_BINDING_CURSE
public static final int ID_BINDING_CURSE- See Also:
-
NAME_BINDING_CURSE
- See Also:
-
ID_VANISHING_CURSE
public static final int ID_VANISHING_CURSE- See Also:
-
NAME_VANISHING_CURSE
- See Also:
-
ID_TRIDENT_IMPALING
public static final int ID_TRIDENT_IMPALING- See Also:
-
NAME_TRIDENT_IMPALING
- See Also:
-
ID_TRIDENT_RIPTIDE
public static final int ID_TRIDENT_RIPTIDE- See Also:
-
NAME_TRIDENT_RIPTIDE
- See Also:
-
ID_TRIDENT_LOYALTY
public static final int ID_TRIDENT_LOYALTY- See Also:
-
NAME_TRIDENT_LOYALTY
- See Also:
-
ID_TRIDENT_CHANNELING
public static final int ID_TRIDENT_CHANNELING- See Also:
-
NAME_TRIDENT_CHANNELING
- See Also:
-
ID_CROSSBOW_MULTISHOT
- See Also:
-
NAME_CROSSBOW_MULTISHOT
- See Also:
-
ID_CROSSBOW_PIERCING
- See Also:
-
NAME_CROSSBOW_PIERCING
- See Also:
-
ID_CROSSBOW_QUICK_CHARGE
- See Also:
-
NAME_CROSSBOW_QUICK_CHARGE
- See Also:
-
ID_SOUL_SPEED
- See Also:
-
NAME_SOUL_SPEED
- See Also:
-
ID_SWIFT_SNEAK
- See Also:
-
NAME_SWIFT_SNEAK
- See Also:
-
id
public final int idThe internal ID which this enchantment got registered. -
type
The group of objects that this enchantment can be applied. -
level
protected int levelThe level of this enchantment. Starting from1
. -
name
The name visible by the player, this is used in conjunction withgetName()
, unless modified with an override, the getter will automatically add "%enchantment." as prefix to grab the translation key -
identifier
-
words
-
-
Constructor Details
-
Enchantment
@PowerNukkitOnly("Was removed from Nukkit in 1.4.0.0-PN, keeping it in PowerNukkit for backward compatibility") @Deprecated @DeprecationDetails(by="Cloudburst Nukkit", since="1.4.0.0-PN", reason="Changed the signature without backward compatibility", replaceWith="Enchantment(int, String, Rarity, EnchantmentType)") protected Enchantment(int id, String name, int weight, @NotNull EnchantmentType type) Deprecated.Constructs this instance using the given data and with level 1.- Parameters:
id
- The enchantment IDname
- The translation key without the "%enchantment." suffixweight
- How rare this enchantment is, from1
to10
both inclusive where1
is the raresttype
- Where the enchantment can be applied
-
Enchantment
@Since("1.4.0.0-PN") protected Enchantment(int id, String name, Enchantment.Rarity rarity, @NotNull EnchantmentType type) Constructs this instance using the given data and with level 1.- Parameters:
id
- The enchantment IDname
- The translation key without the "%enchantment." suffixrarity
- How rare this enchantment istype
- Where the enchantment can be applied
-
Enchantment
@PowerNukkitXOnly @Since("1.19.60-r1") protected Enchantment(@NotNull Identifier identifier, String name, Enchantment.Rarity rarity, @NotNull EnchantmentType type) 自定义附魔使用的构造函数- Parameters:
name
- The translation key without the "%enchantment." suffixrarity
- How rare this enchantment istype
- Where the enchantment can be applied
-
-
Method Details
-
init
public static void init() -
getLevelString
-
register
@PowerNukkitXOnly @Since("1.19.60-r1") public static OK<?> register(Enchantment enchantment, boolean registerItem) -
register
-
get
@Deprecated @DeprecationDetails(by="PowerNukkit", reason="This is very insecure and can break the environment", since="1.4.0.0-PN", replaceWith="getEnchantment(int)") public static Enchantment get(int id) Deprecated.Returns the enchantment object registered with this ID, any change to the returned object affects the creation of new enchantments as the returned object is not a copy.- Parameters:
id
- The enchantment id.- Returns:
- The enchantment, if no enchantment is found with that id,
Enchantment.UnknownEnchantment
is returned. The UnknownEnchantment will be always a new instance and changes to it does not affects other calls.
-
getEnchantment
The same asget(int)
but returns a safe copy of the enchantment.- Parameters:
id
- The enchantment id- Returns:
- A new enchantment object.
-
getEnchantment
使用附魔标识符来获取附魔,原版附魔可以不加命名空间,但是自定义附魔必须加上命名空间才能获取Gets enchantment.
- Parameters:
name
- Enchantment Identifier- Returns:
- the enchantment
-
getEnchantments
Gets an array of all registered enchantments, the objects in the array are linked to the registry, it's not safe to change them. Changing them can cause the same issue as documented inget(int)
- Returns:
- An array with the enchantment objects, the array may contain null objects but is very unlikely.
-
getRegisteredEnchantments
@PowerNukkitOnly @Since("1.4.0.0-PN") public static Collection<Enchantment> getRegisteredEnchantments()Gets a collection with a safe copy of all enchantments that are currently registered.- Returns:
- The objects can be modified without affecting the registry and the collection will not have null values.
-
getEnchantmentName2IDMap
@PowerNukkitXOnly @Since("1.6.0.0-PNX") public static Map<String,Integer> getEnchantmentName2IDMap() -
getIdentifier
获取该附魔的标识符,只有自定义附魔才有- Returns:
- the identifier
-
getLevel
public int getLevel()The current level of this enchantment.0
means that the enchantment is not applied.- Returns:
- The level starting from
1
.
-
setLevel
Changes the level of this enchantment. The level is clamped between the values returned ingetMinLevel()
andgetMaxLevel()
.- Parameters:
level
- The level starting from1
.- Returns:
- This object so you can do chained calls
-
setLevel
Changes the level of this enchantment. When thesafe
param istrue
, the level is clamped between the values returned ingetMinLevel()
andgetMaxLevel()
.- Parameters:
level
- The level starting from1
.safe
- If the level should clamped or applied directly- Returns:
- This object so you can do chained calls
-
getId
public int getId()The ID of this enchantment. -
getRarity
How rare this enchantment is. -
getWeight
@DeprecationDetails(since="1.4.0.0-PN", by="Cloudburst Nukkit", reason="Refactored enchantments and now uses a Rarity enum", replaceWith="getRarity().getWeight()") @Deprecated public int getWeight()Deprecated.useEnchantment.Rarity.getWeight()
insteadHow rare this enchantment is, from1
to10
where1
is the rarest. -
getMinLevel
public int getMinLevel()The minimum safe level which is possible with this enchantment. It is usually1
. -
getMaxLevel
public int getMaxLevel()The maximum safe level which is possible with this enchantment. -
getMaxEnchantableLevel
public int getMaxEnchantableLevel()The maximum level that can be obtained using an enchanting table. -
getMinEnchantAbility
public int getMinEnchantAbility(int level) The minimum enchantability for the given level as described in https://minecraft.gamepedia.com/Enchanting/Levels- Parameters:
level
- The level being checked- Returns:
- The minimum value
-
getMaxEnchantAbility
public int getMaxEnchantAbility(int level) The maximum enchantability for the given level as described in https://minecraft.gamepedia.com/Enchanting/Levels- Parameters:
level
- The level being checked- Returns:
- The maximum value
-
getProtectionFactor
- Parameters:
event
- 该实体被攻击的事件- Returns:
- the protection factor
-
getDamageBonus
当实体武器具有附魔时触发覆写该方法提供当实体使用附魔武器攻击所增益的攻击力
目前只生效于
Player
和 使用了MeleeAttackExecutor
行为的实体- Parameters:
entity
- 攻击的目标实体- Returns:
- the damage value
-
doPostAttack
@PowerNukkitXDifference(info="\u79fb\u9664\u5728InventoryTransactionPacket.USE_ITEM_ON_ENTITY_ACTION_ATTACK\u4e2d\u7684\u5207\u5165\u70b9\uff0c\u56e0\u4e3a\u8fd9\u4f1a\u4e0e#doAttack\u6df7\u6dc6\uff0c\u4ed6\u4eec\u662f\u4e00\u6837\u7684\u4f5c\u7528") public void doPostAttack(Entity attacker, Entity entity) 当实体entity穿着附魔盔甲,被实体attacker攻击时触发覆写该方法实现该过程中的逻辑
- Parameters:
attacker
- the attackerentity
- the entity
-
doAttack
当实体attacker使用具有附魔的武器攻击实体entity时触发覆写该方法实现该过程中的逻辑
- Parameters:
attacker
- the attackerentity
- the entity
-
doPostHurt
目前没有任何作用- Parameters:
attacker
- the attackerentity
- the entity
-
isCompatibleWith
@PowerNukkitDifference(since="1.4.0.0-PN", info="Cloudburst Nukkit added the final modifier, we removed it to maintain backward compatibility. The right way to implement compatibility now is to override checkCompatibility(Enchantment enchantment) and also make sure to keep it protected! Some overrides was incorrectly made public, let\'s avoid this mistake.") public boolean isCompatibleWith(@NotNull Enchantment enchantment) Returns true if and only if this enchantment is compatible with the other and the other is also compatible with this enchantment.- Parameters:
enchantment
- The enchantment which is being checked- Returns:
- If both enchantments are compatible
-
checkCompatibility
Checks if this enchantment can be applied to an item that have the give enchantment without doing reverse check.- Parameters:
enchantment
- The enchantment to be checked- Returns:
- If this enchantment is compatible with the other enchantment.
-
getName
-
getOriginalName
-
canEnchant
Checks if the given item have a type which is compatible with this enchantment. This method does not check if the item already have incompatible enchantments.- Parameters:
item
- The item to be checked- Returns:
- If the type of the item is valid for this enchantment
-
isMajor
public boolean isMajor() -
clone
-
isItemAcceptable
@PowerNukkitOnly @Since("1.2.1.0-PN") @Deprecated @DeprecationDetails(by="PowerNukkit", since="1.4.0.0-PN", reason="Does the same as canEnchant(item)", replaceWith="canEnchant(item)") public boolean isItemAcceptable(Item item) Deprecated.Checks if an item can have this enchantment. It's not strict to the enchantment table. -
getRandomName
-
Enchantment.Rarity.getWeight()
instead