Class EnchantmentHelper
java.lang.Object
net.minecraft.world.item.enchantment.EnchantmentHelper
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic booleancanStoreEnchantments(ItemStack pStack) static voiddoPostAttackEffects(ServerLevel pLevel, Entity pEntity, DamageSource pDamageSource) static voiddoPostAttackEffectsWithItemSource(ServerLevel pLevel, Entity pEntity, DamageSource pDamageSource, ItemStack pItemSource) static ItemStackenchantItem(RandomSource pRandom, ItemStack pStack, int pLevel, Stream<Holder<Enchantment>> pPossibleEnchantments) static ItemStackenchantItem(RandomSource pRandom, ItemStack pStack, int pLevel, RegistryAccess pRegistryAccess, Optional<? extends HolderSet<Enchantment>> pPossibleEnchantments) static voidenchantItemFromProvider(ItemStack pStack, RegistryAccess pRegistries, ResourceKey<EnchantmentProvider> pKey, DifficultyInstance pDifficulty, RandomSource pRandom) static voidfilterCompatibleEnchantments(List<EnchantmentInstance> pDataList, EnchantmentInstance pData) static voidforEachModifier(ItemStack pStack, EquipmentSlotGroup pSlotGroup, BiConsumer<Holder<Attribute>, AttributeModifier> pAction) static voidforEachModifier(ItemStack pStack, EquipmentSlot pSlot, BiConsumer<Holder<Attribute>, AttributeModifier> pAction) static List<EnchantmentInstance> getAvailableEnchantmentResults(int pLevel, ItemStack pStack, Stream<Holder<Enchantment>> pPossibleEnchantments) static DataComponentType<ItemEnchantments> getComponentType(ItemStack pStack) static floatgetDamageProtection(ServerLevel pLevel, LivingEntity pEntity, DamageSource pDamageSource) static intgetEnchantmentCost(RandomSource pRandom, int pEnchantNum, int pPower, ItemStack pStack) Returns the enchantability of itemstack, using a separate calculation for each enchantNum (0, 1 or 2), cutting to the max enchantability power of the table, which is locked to a max of 15.static intgetEnchantmentLevel(Holder<Enchantment> pEnchantment, LivingEntity pEntity) static ItemEnchantmentsgetEnchantmentsForCrafting(ItemStack pStack) static intgetFishingLuckBonus(ServerLevel pLevel, ItemStack pStack, Entity pEntity) static floatgetFishingTimeReduction(ServerLevel pLevel, ItemStack pStack, Entity pEntity) static <T> com.mojang.datafixers.util.Pair<T, Integer> getHighestLevel(ItemStack pStack, DataComponentType<T> pComponentType) static intgetItemEnchantmentLevel(Holder<Enchantment> pEnchantment, ItemStack pStack) Deprecated.static intgetPiercingCount(ServerLevel pLevel, ItemStack pFiredFromWeapon, ItemStack pPickupItemStack) static Optional<EnchantedItemInUse> getRandomItemWith(DataComponentType<?> pComponentType, LivingEntity pEntity, Predicate<ItemStack> pFilter) static intgetTagEnchantmentLevel(Holder<Enchantment> p_346179_, ItemStack p_44845_) Gets the level of an enchantment from NBT.static intgetTridentReturnToOwnerAcceleration(ServerLevel pLevel, ItemStack pStack, Entity pEntity) static floatgetTridentSpinAttackStrength(ItemStack pStack, LivingEntity pEntity) static booleanhas(ItemStack pStack, DataComponentType<?> pComponentType) static booleanhasAnyEnchantments(ItemStack pStack) static booleanhasTag(ItemStack pStack, TagKey<Enchantment> pTag) static booleanisEnchantmentCompatible(Collection<Holder<Enchantment>> pCurrentEnchantments, Holder<Enchantment> pNewEnchantment) static booleanisImmuneToDamage(ServerLevel pLevel, LivingEntity pEntity, DamageSource pDamageSource) static floatmodifyArmorEffectiveness(ServerLevel pLevel, ItemStack pTool, Entity pEntity, DamageSource pDamageSource, float pArmorEffectiveness) static floatmodifyCrossbowChargingTime(ItemStack pStack, LivingEntity pEntity, float pCrossbowChargingTime) static floatmodifyDamage(ServerLevel pLevel, ItemStack pTool, Entity pEntity, DamageSource pDamageSource, float pDamage) static intmodifyDurabilityToRepairFromXp(ServerLevel pLevel, ItemStack pStack, int pDuabilityToRepairFromXp) static floatmodifyFallBasedDamage(ServerLevel pLevel, ItemStack pTool, Entity pEnity, DamageSource pDamageSource, float pFallBasedDamage) static floatmodifyKnockback(ServerLevel pLevel, ItemStack pTool, Entity pEntity, DamageSource pDamageSource, float pKnockback) static voidonHitBlock(ServerLevel pLevel, ItemStack pStack, LivingEntity pOwner, Entity pEntity, EquipmentSlot pSlot, Vec3 pPos, BlockState pState, Consumer<Item> pOnBreak) static voidonProjectileSpawned(ServerLevel pLevel, ItemStack pFiredFromWeapon, AbstractArrow pArrow, Consumer<Item> pOnBreak) static <T> Optional<T> pickHighestLevel(ItemStack pStack, DataComponentType<List<T>> pComponentType) static intprocessAmmoUse(ServerLevel pLevel, ItemStack pWeapon, ItemStack pAmmo, int pCount) static intprocessBlockExperience(ServerLevel pLevel, ItemStack pStack, int pExperience) static intprocessDurabilityChange(ServerLevel pLevel, ItemStack pStack, int pDamage) static floatprocessEquipmentDropChance(ServerLevel pLevel, LivingEntity pEntity, DamageSource pDamageSource, float pEquipmentDropChance) static intprocessMobExperience(ServerLevel pLevel, Entity pKiller, Entity pMob, int pExperience) static intprocessProjectileCount(ServerLevel pLevel, ItemStack pTool, Entity pEntity, int pProjectileCount) static floatprocessProjectileSpread(ServerLevel pLevel, ItemStack pTool, Entity pEntity, float pProjectileSpread) static voidrunIterationOnEquipment(LivingEntity pEntity, EnchantmentHelper.EnchantmentInSlotVisitor pVisitor) static voidrunIterationOnItem(ItemStack pStack, EquipmentSlot pSlot, LivingEntity pEntity, EnchantmentHelper.EnchantmentInSlotVisitor pVisitor) static voidrunIterationOnItem(ItemStack pStack, EnchantmentHelper.EnchantmentVisitor pVisitor) static voidrunLocationChangedEffects(ServerLevel pLevel, LivingEntity pEntity) static voidrunLocationChangedEffects(ServerLevel pLevel, ItemStack pStack, LivingEntity pEntity, EquipmentSlot pSlot) static List<EnchantmentInstance> selectEnchantment(RandomSource pRandom, ItemStack pStack, int pLevel, Stream<Holder<Enchantment>> pPossibleEnchantments) static voidsetEnchantments(ItemStack pStack, ItemEnchantments pEnchantments) static voidstopLocationBasedEffects(LivingEntity pEntity) static voidstopLocationBasedEffects(ItemStack pStack, LivingEntity pEntity, EquipmentSlot pSlot) static voidtickEffects(ServerLevel pLevel, LivingEntity pEntity) static ItemEnchantmentsupdateEnchantments(ItemStack pStack, Consumer<ItemEnchantments.Mutable> pUpdater)
-
Constructor Details
-
EnchantmentHelper
public EnchantmentHelper()
-
-
Method Details
-
getItemEnchantmentLevel
@Deprecated public static int getItemEnchantmentLevel(Holder<Enchantment> pEnchantment, ItemStack pStack) Deprecated.Neo: UsegetTagEnchantmentLevel(Holder, ItemStack)for NBT enchantments, orIItemStackExtension.getEnchantmentLevel(Holder)for gameplay. -
getTagEnchantmentLevel
Gets the level of an enchantment from NBT. UseIItemStackExtension.getEnchantmentLevel(Holder)for gameplay logic. -
updateEnchantments
public static ItemEnchantments updateEnchantments(ItemStack pStack, Consumer<ItemEnchantments.Mutable> pUpdater) -
canStoreEnchantments
-
setEnchantments
-
getEnchantmentsForCrafting
-
getComponentType
-
hasAnyEnchantments
-
processDurabilityChange
-
processAmmoUse
public static int processAmmoUse(ServerLevel pLevel, ItemStack pWeapon, ItemStack pAmmo, int pCount) -
processBlockExperience
-
processMobExperience
public static int processMobExperience(ServerLevel pLevel, @Nullable Entity pKiller, Entity pMob, int pExperience) -
runIterationOnItem
public static void runIterationOnItem(ItemStack pStack, EnchantmentHelper.EnchantmentVisitor pVisitor) -
runIterationOnItem
public static void runIterationOnItem(ItemStack pStack, EquipmentSlot pSlot, LivingEntity pEntity, EnchantmentHelper.EnchantmentInSlotVisitor pVisitor) -
runIterationOnEquipment
public static void runIterationOnEquipment(LivingEntity pEntity, EnchantmentHelper.EnchantmentInSlotVisitor pVisitor) -
isImmuneToDamage
public static boolean isImmuneToDamage(ServerLevel pLevel, LivingEntity pEntity, DamageSource pDamageSource) -
getDamageProtection
public static float getDamageProtection(ServerLevel pLevel, LivingEntity pEntity, DamageSource pDamageSource) -
modifyDamage
public static float modifyDamage(ServerLevel pLevel, ItemStack pTool, Entity pEntity, DamageSource pDamageSource, float pDamage) -
modifyFallBasedDamage
public static float modifyFallBasedDamage(ServerLevel pLevel, ItemStack pTool, Entity pEnity, DamageSource pDamageSource, float pFallBasedDamage) -
modifyArmorEffectiveness
public static float modifyArmorEffectiveness(ServerLevel pLevel, ItemStack pTool, Entity pEntity, DamageSource pDamageSource, float pArmorEffectiveness) -
modifyKnockback
public static float modifyKnockback(ServerLevel pLevel, ItemStack pTool, Entity pEntity, DamageSource pDamageSource, float pKnockback) -
doPostAttackEffects
public static void doPostAttackEffects(ServerLevel pLevel, Entity pEntity, DamageSource pDamageSource) -
doPostAttackEffectsWithItemSource
public static void doPostAttackEffectsWithItemSource(ServerLevel pLevel, Entity pEntity, DamageSource pDamageSource, @Nullable ItemStack pItemSource) -
runLocationChangedEffects
-
runLocationChangedEffects
public static void runLocationChangedEffects(ServerLevel pLevel, ItemStack pStack, LivingEntity pEntity, EquipmentSlot pSlot) -
stopLocationBasedEffects
-
stopLocationBasedEffects
public static void stopLocationBasedEffects(ItemStack pStack, LivingEntity pEntity, EquipmentSlot pSlot) -
tickEffects
-
getEnchantmentLevel
-
processProjectileCount
public static int processProjectileCount(ServerLevel pLevel, ItemStack pTool, Entity pEntity, int pProjectileCount) -
processProjectileSpread
public static float processProjectileSpread(ServerLevel pLevel, ItemStack pTool, Entity pEntity, float pProjectileSpread) -
getPiercingCount
public static int getPiercingCount(ServerLevel pLevel, ItemStack pFiredFromWeapon, ItemStack pPickupItemStack) -
onProjectileSpawned
public static void onProjectileSpawned(ServerLevel pLevel, ItemStack pFiredFromWeapon, AbstractArrow pArrow, Consumer<Item> pOnBreak) -
onHitBlock
public static void onHitBlock(ServerLevel pLevel, ItemStack pStack, @Nullable LivingEntity pOwner, Entity pEntity, @Nullable EquipmentSlot pSlot, Vec3 pPos, BlockState pState, Consumer<Item> pOnBreak) -
modifyDurabilityToRepairFromXp
public static int modifyDurabilityToRepairFromXp(ServerLevel pLevel, ItemStack pStack, int pDuabilityToRepairFromXp) -
processEquipmentDropChance
public static float processEquipmentDropChance(ServerLevel pLevel, LivingEntity pEntity, DamageSource pDamageSource, float pEquipmentDropChance) -
forEachModifier
public static void forEachModifier(ItemStack pStack, EquipmentSlotGroup pSlotGroup, BiConsumer<Holder<Attribute>, AttributeModifier> pAction) -
forEachModifier
public static void forEachModifier(ItemStack pStack, EquipmentSlot pSlot, BiConsumer<Holder<Attribute>, AttributeModifier> pAction) -
getFishingLuckBonus
-
getFishingTimeReduction
-
getTridentReturnToOwnerAcceleration
public static int getTridentReturnToOwnerAcceleration(ServerLevel pLevel, ItemStack pStack, Entity pEntity) -
modifyCrossbowChargingTime
public static float modifyCrossbowChargingTime(ItemStack pStack, LivingEntity pEntity, float pCrossbowChargingTime) -
getTridentSpinAttackStrength
-
hasTag
-
has
-
pickHighestLevel
public static <T> Optional<T> pickHighestLevel(ItemStack pStack, DataComponentType<List<T>> pComponentType) -
getHighestLevel
@Nullable public static <T> com.mojang.datafixers.util.Pair<T,Integer> getHighestLevel(ItemStack pStack, DataComponentType<T> pComponentType) -
getRandomItemWith
public static Optional<EnchantedItemInUse> getRandomItemWith(DataComponentType<?> pComponentType, LivingEntity pEntity, Predicate<ItemStack> pFilter) -
getEnchantmentCost
public static int getEnchantmentCost(RandomSource pRandom, int pEnchantNum, int pPower, ItemStack pStack) Returns the enchantability of itemstack, using a separate calculation for each enchantNum (0, 1 or 2), cutting to the max enchantability power of the table, which is locked to a max of 15. -
enchantItem
public static ItemStack enchantItem(RandomSource pRandom, ItemStack pStack, int pLevel, RegistryAccess pRegistryAccess, Optional<? extends HolderSet<Enchantment>> pPossibleEnchantments) -
enchantItem
public static ItemStack enchantItem(RandomSource pRandom, ItemStack pStack, int pLevel, Stream<Holder<Enchantment>> pPossibleEnchantments) -
selectEnchantment
public static List<EnchantmentInstance> selectEnchantment(RandomSource pRandom, ItemStack pStack, int pLevel, Stream<Holder<Enchantment>> pPossibleEnchantments) -
filterCompatibleEnchantments
public static void filterCompatibleEnchantments(List<EnchantmentInstance> pDataList, EnchantmentInstance pData) -
isEnchantmentCompatible
public static boolean isEnchantmentCompatible(Collection<Holder<Enchantment>> pCurrentEnchantments, Holder<Enchantment> pNewEnchantment) -
getAvailableEnchantmentResults
public static List<EnchantmentInstance> getAvailableEnchantmentResults(int pLevel, ItemStack pStack, Stream<Holder<Enchantment>> pPossibleEnchantments) -
enchantItemFromProvider
public static void enchantItemFromProvider(ItemStack pStack, RegistryAccess pRegistries, ResourceKey<EnchantmentProvider> pKey, DifficultyInstance pDifficulty, RandomSource pRandom)
-
getTagEnchantmentLevel(Holder, ItemStack)for NBT enchantments, orIItemStackExtension.getEnchantmentLevel(Holder)for gameplay.