Class EnchantmentHelper

java.lang.Object
net.minecraft.enchantment.EnchantmentHelper

public class EnchantmentHelper
extends Object
  • Constructor Details

    • EnchantmentHelper

      public EnchantmentHelper()
  • Method Details

    • getLevel

      public static int getLevel​(Enchantment enchantment, ItemStack stack)
      Gets the level of an enchantment on an item stack.
    • get

      public static Map<Enchantment,​Integer> get​(ItemStack stack)
      Gets the enchantments on an item stack.

      For enchanted books, it retrieves from the item stack's stored than regular enchantments.

      See Also:
      ItemStack.getEnchantments(), EnchantedBookItem.getEnchantmentTag(net.minecraft.item.ItemStack)
    • fromTag

      public static Map<Enchantment,​Integer> fromTag​(ListTag tag)
      Loads enchantments from an NBT list.
    • set

      public static void set​(Map<Enchantment,​Integer> enchantments, ItemStack stack)
      Sets the enchantments on an item stack.

      For enchanted books, it sets the enchantments to the item stack's stored enchantments than regular enchantments.

      See Also:
      ItemStack.getEnchantments(), EnchantedBookItem.getEnchantmentTag(net.minecraft.item.ItemStack)
    • forEachEnchantment

      private static void forEachEnchantment​(EnchantmentHelper.Consumer consumer, ItemStack stack)
    • forEachEnchantment

      private static void forEachEnchantment​(EnchantmentHelper.Consumer consumer, Iterable<ItemStack> stacks)
    • getProtectionAmount

      public static int getProtectionAmount​(Iterable<ItemStack> equipment, DamageSource source)
    • getAttackDamage

      public static float getAttackDamage​(ItemStack stack, EntityGroup group)
    • getSweepingMultiplier

      public static float getSweepingMultiplier​(LivingEntity entity)
    • onUserDamaged

      public static void onUserDamaged​(LivingEntity user, Entity attacker)
    • onTargetDamaged

      public static void onTargetDamaged​(LivingEntity user, Entity target)
    • getEquipmentLevel

      public static int getEquipmentLevel​(Enchantment enchantment, LivingEntity entity)
      Returns the highest level of the passed enchantment in the enchantment's applicable equipment slots' item stacks.
      Parameters:
      enchantment - the enchantment
      entity - the entity whose equipment slots are checked
    • getKnockback

      public static int getKnockback​(LivingEntity entity)
    • getFireAspect

      public static int getFireAspect​(LivingEntity entity)
    • getRespiration

      public static int getRespiration​(LivingEntity entity)
    • getDepthStrider

      public static int getDepthStrider​(LivingEntity entity)
    • getEfficiency

      public static int getEfficiency​(LivingEntity entity)
    • getLuckOfTheSea

      public static int getLuckOfTheSea​(ItemStack stack)
    • getLure

      public static int getLure​(ItemStack stack)
    • getLooting

      public static int getLooting​(LivingEntity entity)
    • hasAquaAffinity

      public static boolean hasAquaAffinity​(LivingEntity entity)
    • hasFrostWalker

      public static boolean hasFrostWalker​(LivingEntity entity)
    • hasSoulSpeed

      public static boolean hasSoulSpeed​(LivingEntity entity)
    • hasBindingCurse

      public static boolean hasBindingCurse​(ItemStack stack)
    • hasVanishingCurse

      public static boolean hasVanishingCurse​(ItemStack stack)
    • getLoyalty

      public static int getLoyalty​(ItemStack stack)
    • getRiptide

      public static int getRiptide​(ItemStack stack)
    • hasChanneling

      public static boolean hasChanneling​(ItemStack stack)
    • chooseEquipmentWith

      @Nullable public static Map.Entry<EquipmentSlot,​ItemStack> chooseEquipmentWith​(Enchantment enchantment, LivingEntity entity)
      Returns a pair of an equipment slot and the item stack in the supplied entity's slot, indicating the item stack has the enchantment supplied.

      If multiple equipment slots' item stacks are valid, a random pair is returned.

      Parameters:
      enchantment - the enchantment the equipped item stack must have
      entity - the entity to choose equipments from
    • chooseEquipmentWith

      @Nullable public static Map.Entry<EquipmentSlot,​ItemStack> chooseEquipmentWith​(Enchantment enchantment, LivingEntity entity, Predicate<ItemStack> condition)
      Returns a pair of an equipment slot and the item stack in the supplied entity's slot, indicating the item stack has the enchantment supplied and fulfills the extra condition.

      If multiple equipment slots' item stacks are valid, a random pair is returned.

      Parameters:
      enchantment - the enchantment the equipped item stack must have
      entity - the entity to choose equipments from
      condition - extra conditions for the item stack to pass for selection
    • calculateRequiredExperienceLevel

      public static int calculateRequiredExperienceLevel​(Random random, int slotIndex, int bookshelfCount, ItemStack stack)
      Returns the required experience level for an enchanting option in the enchanting table's screen, or the enchantment screen.
      Parameters:
      random - the random, which guarantees consistent results with the same seed
      slotIndex - the index of the enchanting option
      bookshelfCount - the number of bookshelves
      stack - the item stack to enchant
    • enchant

      public static ItemStack enchant​(Random random, ItemStack target, int level, boolean treasureAllowed)
      Enchants the target item stack and returns it.
      Parameters:
      random - the seed
      target - the item stack to enchant
      level - the experience level
      treasureAllowed - whether treasure enchantments may appear
    • generateEnchantments

      public static List<EnchantmentLevelEntry> generateEnchantments​(Random random, ItemStack stack, int level, boolean treasureAllowed)
      Generate the enchantments for enchanting the stack.
    • removeConflicts

      public static void removeConflicts​(List<EnchantmentLevelEntry> possibleEntries, EnchantmentLevelEntry pickedEntry)
      Remove entries conflicting with the picked entry from the possible entries.
      Parameters:
      possibleEntries - the possible entries
      pickedEntry - the picked entry
    • isCompatible

      public static boolean isCompatible​(Collection<Enchantment> existing, Enchantment candidate)
      Returns whether the candidate enchantment is compatible with the existing enchantments.
    • getPossibleEntries

      public static List<EnchantmentLevelEntry> getPossibleEntries​(int power, ItemStack stack, boolean treasureAllowed)
      Gets all the possible entries for enchanting the stack at the given power.