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 interface
EnchantmentHelper.Consumer
-
Constructor Summary
Constructors Constructor Description EnchantmentHelper()
-
Method Summary
Modifier and Type Method Description 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.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 ItemStack
enchant(Random random, ItemStack target, int level, boolean treasureAllowed)
Enchants thetarget
item stack and returns it.private static void
forEachEnchantment(EnchantmentHelper.Consumer consumer, Iterable<ItemStack> stacks)
private static void
forEachEnchantment(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 float
getAttackDamage(ItemStack stack, EntityGroup group)
static int
getDepthStrider(LivingEntity entity)
static int
getEfficiency(LivingEntity entity)
static int
getEquipmentLevel(Enchantment enchantment, LivingEntity entity)
Returns the highest level of the passed enchantment in the enchantment's applicable equipment slots' item stacks.static int
getFireAspect(LivingEntity entity)
static int
getKnockback(LivingEntity entity)
static int
getLevel(Enchantment enchantment, ItemStack stack)
Gets the level of an enchantment on an item stack.static int
getLooting(LivingEntity entity)
static int
getLoyalty(ItemStack stack)
static int
getLuckOfTheSea(ItemStack stack)
static int
getLure(ItemStack stack)
static List<EnchantmentLevelEntry>
getPossibleEntries(int power, ItemStack stack, boolean treasureAllowed)
Gets all the possible entries for enchanting thestack
at the givenpower
.static int
getProtectionAmount(Iterable<ItemStack> equipment, DamageSource source)
static int
getRespiration(LivingEntity entity)
static int
getRiptide(ItemStack stack)
static float
getSweepingMultiplier(LivingEntity entity)
static boolean
hasAquaAffinity(LivingEntity entity)
static boolean
hasBindingCurse(ItemStack stack)
static boolean
hasChanneling(ItemStack stack)
static boolean
hasFrostWalker(LivingEntity entity)
static boolean
hasSoulSpeed(LivingEntity entity)
static boolean
hasVanishingCurse(ItemStack stack)
static boolean
isCompatible(Collection<Enchantment> existing, Enchantment candidate)
Returns whether thecandidate
enchantment is compatible with theexisting
enchantments.static void
onTargetDamaged(LivingEntity user, Entity target)
static void
onUserDamaged(LivingEntity user, Entity attacker)
static void
removeConflicts(List<EnchantmentLevelEntry> possibleEntries, EnchantmentLevelEntry pickedEntry)
Remove entries conflicting with the picked entry from the possible entries.static void
set(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 thetarget
item 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 thecandidate
enchantment is compatible with theexisting
enchantments. -
getPossibleEntries
public static List<EnchantmentLevelEntry> getPossibleEntries(int power, ItemStack stack, boolean treasureAllowed)Gets all the possible entries for enchanting thestack
at the givenpower
.
-