Package net.minecraft.enchantment
Class EnchantmentHelper
java.lang.Object
net.minecraft.enchantment.EnchantmentHelper
public class EnchantmentHelper extends Object
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static interfaceEnchantmentHelper.Consumer -
Constructor Summary
Constructors Constructor Description EnchantmentHelper() -
Method Summary
Modifier and Type Method Description static intcalculateRequiredExperienceLevel(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.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.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.static ItemStackenchant(Random random, ItemStack target, int level, boolean treasureAllowed)Enchants thetargetitem stack and returns it.private static voidforEachEnchantment(EnchantmentHelper.Consumer consumer, Iterable<ItemStack> stacks)private static voidforEachEnchantment(EnchantmentHelper.Consumer consumer, ItemStack stack)static Map<Enchantment,Integer>fromTag(ListTag tag)Loads enchantments from an NBT list.static List<EnchantmentLevelEntry>generateEnchantments(Random random, ItemStack stack, int level, boolean treasureAllowed)Generate the enchantments for enchanting thestack.static Map<Enchantment,Integer>get(ItemStack stack)Gets the enchantments on an item stack.static floatgetAttackDamage(ItemStack stack, EntityGroup group)static intgetDepthStrider(LivingEntity entity)static intgetEfficiency(LivingEntity entity)static intgetEquipmentLevel(Enchantment enchantment, LivingEntity entity)Returns the highest level of the passed enchantment in the enchantment's applicable equipment slots' item stacks.static intgetFireAspect(LivingEntity entity)static intgetKnockback(LivingEntity entity)static intgetLevel(Enchantment enchantment, ItemStack stack)Gets the level of an enchantment on an item stack.static intgetLooting(LivingEntity entity)static intgetLoyalty(ItemStack stack)static intgetLuckOfTheSea(ItemStack stack)static intgetLure(ItemStack stack)static List<EnchantmentLevelEntry>getPossibleEntries(int power, ItemStack stack, boolean treasureAllowed)Gets all the possible entries for enchanting thestackat the givenpower.static intgetProtectionAmount(Iterable<ItemStack> equipment, DamageSource source)static intgetRespiration(LivingEntity entity)static intgetRiptide(ItemStack stack)static floatgetSweepingMultiplier(LivingEntity entity)static booleanhasAquaAffinity(LivingEntity entity)static booleanhasBindingCurse(ItemStack stack)static booleanhasChanneling(ItemStack stack)static booleanhasFrostWalker(LivingEntity entity)static booleanhasSoulSpeed(LivingEntity entity)static booleanhasVanishingCurse(ItemStack stack)static booleanisCompatible(Collection<Enchantment> existing, Enchantment candidate)Returns whether thecandidateenchantment is compatible with theexistingenchantments.static voidonTargetDamaged(LivingEntity user, Entity target)static voidonUserDamaged(LivingEntity user, Entity attacker)static voidremoveConflicts(List<EnchantmentLevelEntry> possibleEntries, EnchantmentLevelEntry pickedEntry)Remove entries conflicting with the picked entry from the possible entries.static voidset(Map<Enchantment,Integer> enchantments, ItemStack stack)Sets the enchantments on an item stack.
-
Constructor Details
-
EnchantmentHelper
public EnchantmentHelper()
-
-
Method Details
-
getLevel
Gets the level of an enchantment on an item stack. -
get
Gets the enchantments on an item stack.For enchanted books, it retrieves from the item stack's stored than regular enchantments.
-
fromTag
Loads enchantments from an NBT list. -
set
Sets the enchantments on an item stack.For enchanted books, it sets the enchantments to the item stack's stored enchantments than regular enchantments.
-
forEachEnchantment
-
forEachEnchantment
private static void forEachEnchantment(EnchantmentHelper.Consumer consumer, Iterable<ItemStack> stacks) -
getProtectionAmount
-
getAttackDamage
-
getSweepingMultiplier
-
onUserDamaged
-
onTargetDamaged
-
getEquipmentLevel
Returns the highest level of the passed enchantment in the enchantment's applicable equipment slots' item stacks.- Parameters:
enchantment- the enchantmententity- the entity whose equipment slots are checked
-
getKnockback
-
getFireAspect
-
getRespiration
-
getDepthStrider
-
getEfficiency
-
getLuckOfTheSea
-
getLure
-
getLooting
-
hasAquaAffinity
-
hasFrostWalker
-
hasSoulSpeed
-
hasBindingCurse
-
hasVanishingCurse
-
getLoyalty
-
getRiptide
-
hasChanneling
-
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 haveentity- 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 haveentity- the entity to choose equipments fromcondition- 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 seedslotIndex- the index of the enchanting optionbookshelfCount- the number of bookshelvesstack- the item stack to enchant
-
enchant
public static ItemStack enchant(Random random, ItemStack target, int level, boolean treasureAllowed)Enchants thetargetitem stack and returns it.- Parameters:
random- the seedtarget- the item stack to enchantlevel- the experience leveltreasureAllowed- whether treasure enchantments may appear
-
generateEnchantments
public static List<EnchantmentLevelEntry> generateEnchantments(Random random, ItemStack stack, int level, boolean treasureAllowed)Generate the enchantments for enchanting thestack. -
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 entriespickedEntry- the picked entry
-
isCompatible
Returns whether thecandidateenchantment is compatible with theexistingenchantments. -
getPossibleEntries
public static List<EnchantmentLevelEntry> getPossibleEntries(int power, ItemStack stack, boolean treasureAllowed)Gets all the possible entries for enchanting thestackat the givenpower.
-