public class EnchantmentHelper extends Object
Modifier and Type | Class and Description |
---|---|
(package private) static interface |
EnchantmentHelper.Consumer |
Constructor and Description |
---|
EnchantmentHelper() |
Modifier and Type | Method and 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 the
target item stack and returns it. |
private static void |
forEachEnchantment(EnchantmentHelper.Consumer consumer,
ItemStack stack) |
private static void |
forEachEnchantment(EnchantmentHelper.Consumer consumer,
Iterable<ItemStack> stacks) |
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 the
stack . |
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 the
stack at the
given power . |
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 the
candidate enchantment is compatible with the
existing 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.
|
public static int getLevel(Enchantment enchantment, ItemStack stack)
public static Map<Enchantment,Integer> get(ItemStack stack)
For enchanted books, it retrieves from the item stack's stored than regular enchantments.
public static Map<Enchantment,Integer> fromTag(ListTag tag)
public static void set(Map<Enchantment,Integer> enchantments, ItemStack stack)
For enchanted books, it sets the enchantments to the item stack's stored enchantments than regular enchantments.
private static void forEachEnchantment(EnchantmentHelper.Consumer consumer, ItemStack stack)
private static void forEachEnchantment(EnchantmentHelper.Consumer consumer, Iterable<ItemStack> stacks)
public static int getProtectionAmount(Iterable<ItemStack> equipment, DamageSource source)
public static float getAttackDamage(ItemStack stack, EntityGroup group)
public static float getSweepingMultiplier(LivingEntity entity)
public static void onUserDamaged(LivingEntity user, Entity attacker)
public static void onTargetDamaged(LivingEntity user, Entity target)
public static int getEquipmentLevel(Enchantment enchantment, LivingEntity entity)
enchantment
- the enchantmententity
- the entity whose equipment slots are checkedpublic static int getKnockback(LivingEntity entity)
public static int getFireAspect(LivingEntity entity)
public static int getRespiration(LivingEntity entity)
public static int getDepthStrider(LivingEntity entity)
public static int getEfficiency(LivingEntity entity)
public static int getLuckOfTheSea(ItemStack stack)
public static int getLure(ItemStack stack)
public static int getLooting(LivingEntity entity)
public static boolean hasAquaAffinity(LivingEntity entity)
public static boolean hasFrostWalker(LivingEntity entity)
public static boolean hasSoulSpeed(LivingEntity entity)
public static boolean hasBindingCurse(ItemStack stack)
public static boolean hasVanishingCurse(ItemStack stack)
public static int getLoyalty(ItemStack stack)
public static int getRiptide(ItemStack stack)
public static boolean hasChanneling(ItemStack stack)
@Nullable public static Map.Entry<EquipmentSlot,ItemStack> chooseEquipmentWith(Enchantment enchantment, LivingEntity entity)
If multiple equipment slots' item stacks are valid, a random pair is returned.
enchantment
- the enchantment the equipped item stack must haveentity
- the entity to choose equipments from@Nullable public static Map.Entry<EquipmentSlot,ItemStack> chooseEquipmentWith(Enchantment enchantment, LivingEntity entity, Predicate<ItemStack> condition)
If multiple equipment slots' item stacks are valid, a random pair is returned.
enchantment
- the enchantment the equipped item stack must haveentity
- the entity to choose equipments fromcondition
- extra conditions for the item stack to pass for selectionpublic static int calculateRequiredExperienceLevel(Random random, int slotIndex, int bookshelfCount, ItemStack stack)
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 enchantpublic static ItemStack enchant(Random random, ItemStack target, int level, boolean treasureAllowed)
target
item stack and returns it.random
- the seedtarget
- the item stack to enchantlevel
- the experience leveltreasureAllowed
- whether treasure enchantments may appearpublic static List<EnchantmentLevelEntry> generateEnchantments(Random random, ItemStack stack, int level, boolean treasureAllowed)
stack
.public static void removeConflicts(List<EnchantmentLevelEntry> possibleEntries, EnchantmentLevelEntry pickedEntry)
possibleEntries
- the possible entriespickedEntry
- the picked entrypublic static boolean isCompatible(Collection<Enchantment> existing, Enchantment candidate)
candidate
enchantment is compatible with the
existing
enchantments.public static List<EnchantmentLevelEntry> getPossibleEntries(int power, ItemStack stack, boolean treasureAllowed)
stack
at the
given power
.