类 Enchantment

java.lang.Object
cn.nukkit.item.enchantment.Enchantment
所有已实现的接口:
Cloneable
直接已知子类:
EnchantmentBindingCurse, EnchantmentBow, EnchantmentCrossbow, EnchantmentDamage, EnchantmentDurability, EnchantmentEfficiency, EnchantmentFireAspect, EnchantmentFrostWalker, EnchantmentKnockback, EnchantmentLoot, EnchantmentLure, EnchantmentMending, EnchantmentProtection, EnchantmentSilkTouch, EnchantmentSoulSpeed, EnchantmentSwiftSneak, EnchantmentThorns, EnchantmentTrident, EnchantmentVanishingCurse, EnchantmentWaterBreath, EnchantmentWaterWalker, EnchantmentWaterWorker

public abstract class Enchantment extends Object implements Cloneable
An enchantment that can be to applied to an item.
作者:
MagicDroidX (Nukkit Project)
  • 字段详细资料

  • 构造器详细资料

    • 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, EnchantmentType type)
      已过时。
      Constructs this instance using the given data and with level 1.
      参数:
      id - The enchantment ID
      name - The translation key without the "%enchantment." suffix
      weight - How rare this enchantment is, from 1 to 10 both inclusive where 1 is the rarest
      type - Where the enchantment can be applied
    • Enchantment

      @Since("1.4.0.0-PN") protected Enchantment(int id, String name, Enchantment.Rarity rarity, EnchantmentType type)
      Constructs this instance using the given data and with level 1.
      参数:
      id - The enchantment ID
      name - The translation key without the "%enchantment." suffix
      rarity - How rare this enchantment is
      type - Where the enchantment can be applied
  • 方法详细资料

    • init

      public static void init()
    • 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)
      已过时。
      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.
      参数:
      id - The enchantment id.
      返回:
      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

      public static Enchantment getEnchantment(int id)
      The same as get(int) but returns a safe copy of the enchantment.
      参数:
      id - The enchantment id
      返回:
      A new enchantment object.
    • getEnchantment

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public static Enchantment getEnchantment(String name)
    • getEnchantments

      @Deprecated @DeprecationDetails(since="1.4.0.0-PN", by="PowerNukkit", reason="The objects returned by this method are not safe to use and the implementation may skip some enchantments", replaceWith="getRegisteredEnchantments()") public static 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 in get(int)
      返回:
      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.
      返回:
      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()
    • getLevel

      public int getLevel()
      The current level of this enchantment. 0 means that the enchantment is not applied.
      返回:
      The level starting from 1.
    • setLevel

      @Nonnull public Enchantment setLevel(int level)
      Changes the level of this enchantment. The level is clamped between the values returned in getMinLevel() and getMaxLevel().
      参数:
      level - The level starting from 1.
      返回:
      This object so you can do chained calls
    • setLevel

      @Nonnull public Enchantment setLevel(int level, boolean safe)
      Changes the level of this enchantment. When the safe param is true, the level is clamped between the values returned in getMinLevel() and getMaxLevel().
      参数:
      level - The level starting from 1.
      safe - If the level should clamped or applied directly
      返回:
      This object so you can do chained calls
    • getId

      public int getId()
      The ID of this enchantment.
    • getRarity

      @Since("1.4.0.0-PN") @Nonnull public Enchantment.Rarity 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()
      已过时。
      How rare this enchantment is, from 1 to 10 where 1 is the rarest.
    • getMinLevel

      public int getMinLevel()
      The minimum safe level which is possible with this enchantment. It is usually 1.
    • 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
      参数:
      level - The level being checked
      返回:
      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
      参数:
      level - The level being checked
      返回:
      The maximum value
    • getProtectionFactor

      public float getProtectionFactor(EntityDamageEvent event)
    • getDamageBonus

      public double getDamageBonus(Entity entity)
    • doPostAttack

      public void doPostAttack(Entity attacker, Entity entity)
    • doAttack

      @Since("FUTURE") public void doAttack(Entity attacker, Entity entity)
    • doPostHurt

      public void doPostHurt(Entity attacker, Entity 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(@Nonnull Enchantment enchantment)
      Returns true if and only if this enchantment is compatible with the other and the other is also compatible with this enchantment.
      参数:
      enchantment - The enchantment which is being checked
      返回:
      If both enchantments are compatible
    • checkCompatibility

      @Since("1.4.0.0-PN") protected boolean checkCompatibility(Enchantment enchantment)
      Checks if this enchantment can be applied to an item that have the give enchantment without doing reverse check.
      参数:
      enchantment - The enchantment to be checked
      返回:
      If this enchantment is compatible with the other enchantment.
    • getName

      public String getName()
    • getOriginalName

      @PowerNukkitXOnly @Since("1.6.0.0-PNX") public String getOriginalName()
    • canEnchant

      public boolean canEnchant(@Nonnull Item item)
      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.
      参数:
      item - The item to be checked
      返回:
      If the type of the item is valid for this enchantment
    • isMajor

      public boolean isMajor()
    • getAttackSideEffects

      @PowerNukkitOnly @Since("1.5.1.0-PN") @Nonnull public SideEffect[] getAttackSideEffects(@Nonnull Entity attacker, @Nonnull Entity entity)
    • clone

      protected Enchantment clone()
      覆盖:
      clone 在类中 Object
    • 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)
      已过时。
      Checks if an item can have this enchantment. It's not strict to the enchantment table.
    • getRandomName

      public static String getRandomName()