Record Class Enchantment
java.lang.Object
java.lang.Record
net.minecraft.world.item.enchantment.Enchantment
public record Enchantment(Component description, Enchantment.EnchantmentDefinition definition, HolderSet<Enchantment> exclusiveSet, DataComponentMap effects)
extends Record
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
static final record
static final record
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final com.mojang.serialization.Codec
<Holder<Enchantment>> private final Enchantment.EnchantmentDefinition
The field for thedefinition
record component.private final Component
The field for thedescription
record component.static final com.mojang.serialization.Codec
<Enchantment> private final DataComponentMap
The field for theeffects
record component.private final HolderSet
<Enchantment> The field for theexclusiveSet
record component.static final int
static final StreamCodec
<RegistryFriendlyByteBuf, Holder<Enchantment>> -
Constructor Summary
ConstructorsConstructorDescriptionEnchantment
(Component description, Enchantment.EnchantmentDefinition definition, HolderSet<Enchantment> exclusiveSet, DataComponentMap effects) Creates an instance of aEnchantment
record class. -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> void
applyEffects
(List<ConditionalEffect<T>> effects, LootContext context, Consumer<T> applier) static boolean
areCompatible
(Holder<Enchantment> first, Holder<Enchantment> second) static LootContext
blockHitContext
(ServerLevel level, int enchantmentLevel, Entity entity, Vec3 origin, BlockState state) boolean
canEnchant
(ItemStack stack) Deprecated.static Enchantment.Cost
constantCost
(int cost) static LootContext
damageContext
(ServerLevel level, int enchantmentLevel, Entity entity, DamageSource damageSource) Returns the value of thedefinition
record component.definition
(HolderSet<Item> supportedItems, int weight, int maxLevel, Enchantment.Cost minCost, Enchantment.Cost maxCost, int anvilCost, EquipmentSlotGroup... slots) definition
(HolderSet<Item> supportedItems, HolderSet<Item> primaryItems, int weight, int maxLevel, Enchantment.Cost minCost, Enchantment.Cost maxCost, int anvilCost, EquipmentSlotGroup... slots) Returns the value of thedescription
record component.void
doPostAttack
(ServerLevel level, int enchantmentLevel, EnchantedItemInUse item, EnchantmentTarget target, Entity entity, DamageSource damageSource) static void
doPostAttack
(TargetedConditionalEffect<EnchantmentEntityEffect> effect, ServerLevel level, int enchantmentLevel, EnchantedItemInUse item, Entity p_entity, DamageSource damageSource) static Enchantment.Cost
dynamicCost
(int base, int perLevel) effects()
Returns the value of theeffects
record component.static Enchantment.Builder
enchantment
(Enchantment.EnchantmentDefinition definition) static LootContext
entityContext
(ServerLevel level, int enchantmentLevel, Entity entity, Vec3 origin) final boolean
Indicates whether some other object is "equal to" this one.Returns the value of theexclusiveSet
record component.int
<T> List
<T> getEffects
(DataComponentType<List<T>> component) static Component
getFullname
(Holder<Enchantment> enchantment, int level) int
getMaxCost
(int level) int
int
getMinCost
(int level) Returns the minimal value of enchantability needed on the enchantment level passed.int
getSlotItems
(LivingEntity entity) Creates a new map containing all items equipped by an entity ininvalid reference
slots that the enchantment cares about
Deprecated.int
final int
hashCode()
Returns a hash code value for this object.boolean
isImmuneToDamage
(ServerLevel level, int enchantmentLevel, Entity entity, DamageSource damageSource) boolean
isPrimaryItem
(ItemStack stack) Deprecated.Neo: UseIItemStackExtension.isPrimaryItemFor(Holder)
This method does not respectIItemStackExtension.supportsEnchantment(Holder)
since theHolder
is not available, which makes the result of calling it invalid.boolean
isSupportedItem
(ItemStack item) Deprecated.static LootContext
itemContext
(ServerLevel level, int enchantmentLevel, ItemStack tool) static LootContext
locationContext
(ServerLevel level, int enchantmentLevel, Entity entity, boolean enchantmentActive) boolean
matchingSlot
(EquipmentSlot slot) void
modifyAmmoCount
(ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat ammoCount) void
modifyArmorEffectivness
(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat armorEffectiveness) void
modifyBlockExperience
(ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat blockExperience) void
modifyCrossbowChargeTime
(RandomSource random, int enchantmentLevel, org.apache.commons.lang3.mutable.MutableFloat value) void
modifyDamage
(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat damage) void
modifyDamageFilteredValue
(DataComponentType<List<ConditionalEffect<EnchantmentValueEffect>>> componentType, ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat value) void
modifyDamageProtection
(ServerLevel level, int enchantmentLevel, ItemStack stack, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat damageProtection) void
modifyDurabilityChange
(ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat durabilityChange) void
modifyDurabilityToRepairFromXp
(ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat durabilityToRepairFromXp) void
modifyEntityFilteredValue
(DataComponentType<List<ConditionalEffect<EnchantmentValueEffect>>> componentType, ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat value) void
modifyFallBasedDamage
(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat fallBasedDamage) void
modifyFishingLuckBonus
(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat fishingLuckBonus) void
modifyFishingTimeReduction
(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat fishingTimeReduction) void
modifyItemFilteredCount
(DataComponentType<List<ConditionalEffect<EnchantmentValueEffect>>> componentType, ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat value) void
modifyKnockback
(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat knockback) void
modifyMobExperience
(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat mobExperience) void
modifyPiercingCount
(ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat piercingCount) void
modifyProjectileCount
(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat projectileCount) void
modifyProjectileSpread
(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat projectileSpread) void
modifyTridentReturnToOwnerAcceleration
(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat tridentReturnToOwnerAcceleration) void
modifyTridentSpinAttackStrength
(RandomSource random, int enchantmentLevel, org.apache.commons.lang3.mutable.MutableFloat value) void
modifyUnfilteredValue
(DataComponentType<EnchantmentValueEffect> componentType, RandomSource random, int enchantmentLevel, org.apache.commons.lang3.mutable.MutableFloat value) void
onHitBlock
(ServerLevel level, int enchantmentLevel, EnchantedItemInUse item, Entity entity, Vec3 pos, BlockState state) void
onProjectileSpawned
(ServerLevel level, int enchantmentLevel, EnchantedItemInUse item, Entity entity) void
runLocationChangedEffects
(ServerLevel level, int enchantmentLevel, EnchantedItemInUse item, LivingEntity entity) void
stopLocationBasedEffects
(int enchantmentLevel, EnchantedItemInUse item, LivingEntity entity) void
tick
(ServerLevel level, int enchantmentLevel, EnchantedItemInUse item, Entity entity) toString()
Returns a string representation of this record class.
-
Field Details
-
description
The field for thedescription
record component. -
definition
The field for thedefinition
record component. -
exclusiveSet
The field for theexclusiveSet
record component. -
effects
The field for theeffects
record component. -
MAX_LEVEL
public static final int MAX_LEVEL- See Also:
-
DIRECT_CODEC
-
CODEC
-
STREAM_CODEC
-
-
Constructor Details
-
Enchantment
public Enchantment(Component description, Enchantment.EnchantmentDefinition definition, HolderSet<Enchantment> exclusiveSet, DataComponentMap effects) Creates an instance of aEnchantment
record class.- Parameters:
description
- the value for thedescription
record componentdefinition
- the value for thedefinition
record componentexclusiveSet
- the value for theexclusiveSet
record componenteffects
- the value for theeffects
record component
-
-
Method Details
-
constantCost
-
dynamicCost
-
definition
public static Enchantment.EnchantmentDefinition definition(HolderSet<Item> supportedItems, HolderSet<Item> primaryItems, int weight, int maxLevel, Enchantment.Cost minCost, Enchantment.Cost maxCost, int anvilCost, EquipmentSlotGroup... slots) -
definition
public static Enchantment.EnchantmentDefinition definition(HolderSet<Item> supportedItems, int weight, int maxLevel, Enchantment.Cost minCost, Enchantment.Cost maxCost, int anvilCost, EquipmentSlotGroup... slots) -
getSlotItems
Creates a new map containing all items equipped by an entity ininvalid reference
slots that the enchantment cares about
- Parameters:
entity
- The entity to collect equipment for.
-
getSupportedItems
Deprecated. -
matchingSlot
-
isPrimaryItem
Deprecated.Neo: UseIItemStackExtension.isPrimaryItemFor(Holder)
This method does not respectIItemStackExtension.supportsEnchantment(Holder)
since theHolder
is not available, which makes the result of calling it invalid. -
isSupportedItem
Deprecated. -
getWeight
public int getWeight() -
getAnvilCost
public int getAnvilCost() -
getMinLevel
public int getMinLevel() -
getMaxLevel
public int getMaxLevel() -
getMinCost
public int getMinCost(int level) Returns the minimal value of enchantability needed on the enchantment level passed. -
getMaxCost
public int getMaxCost(int level) -
toString
Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components. -
areCompatible
-
getFullname
-
canEnchant
Deprecated.Checks if the enchantment can be applied to a given ItemStack.- Parameters:
stack
- The ItemStack to test.
-
getEffects
-
isImmuneToDamage
public boolean isImmuneToDamage(ServerLevel level, int enchantmentLevel, Entity entity, DamageSource damageSource) -
modifyDamageProtection
public void modifyDamageProtection(ServerLevel level, int enchantmentLevel, ItemStack stack, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat damageProtection) -
modifyDurabilityChange
public void modifyDurabilityChange(ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat durabilityChange) -
modifyAmmoCount
public void modifyAmmoCount(ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat ammoCount) -
modifyPiercingCount
public void modifyPiercingCount(ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat piercingCount) -
modifyBlockExperience
public void modifyBlockExperience(ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat blockExperience) -
modifyMobExperience
public void modifyMobExperience(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat mobExperience) -
modifyDurabilityToRepairFromXp
public void modifyDurabilityToRepairFromXp(ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat durabilityToRepairFromXp) -
modifyTridentReturnToOwnerAcceleration
public void modifyTridentReturnToOwnerAcceleration(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat tridentReturnToOwnerAcceleration) -
modifyTridentSpinAttackStrength
public void modifyTridentSpinAttackStrength(RandomSource random, int enchantmentLevel, org.apache.commons.lang3.mutable.MutableFloat value) -
modifyFishingTimeReduction
public void modifyFishingTimeReduction(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat fishingTimeReduction) -
modifyFishingLuckBonus
public void modifyFishingLuckBonus(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat fishingLuckBonus) -
modifyDamage
public void modifyDamage(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat damage) -
modifyFallBasedDamage
public void modifyFallBasedDamage(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat fallBasedDamage) -
modifyKnockback
public void modifyKnockback(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat knockback) -
modifyArmorEffectivness
public void modifyArmorEffectivness(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat armorEffectiveness) -
doPostAttack
public static void doPostAttack(TargetedConditionalEffect<EnchantmentEntityEffect> effect, ServerLevel level, int enchantmentLevel, EnchantedItemInUse item, Entity p_entity, DamageSource damageSource) -
doPostAttack
public void doPostAttack(ServerLevel level, int enchantmentLevel, EnchantedItemInUse item, EnchantmentTarget target, Entity entity, DamageSource damageSource) -
modifyProjectileCount
public void modifyProjectileCount(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat projectileCount) -
modifyProjectileSpread
public void modifyProjectileSpread(ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat projectileSpread) -
modifyCrossbowChargeTime
public void modifyCrossbowChargeTime(RandomSource random, int enchantmentLevel, org.apache.commons.lang3.mutable.MutableFloat value) -
modifyUnfilteredValue
public void modifyUnfilteredValue(DataComponentType<EnchantmentValueEffect> componentType, RandomSource random, int enchantmentLevel, org.apache.commons.lang3.mutable.MutableFloat value) -
tick
-
onProjectileSpawned
public void onProjectileSpawned(ServerLevel level, int enchantmentLevel, EnchantedItemInUse item, Entity entity) -
onHitBlock
public void onHitBlock(ServerLevel level, int enchantmentLevel, EnchantedItemInUse item, Entity entity, Vec3 pos, BlockState state) -
modifyItemFilteredCount
public void modifyItemFilteredCount(DataComponentType<List<ConditionalEffect<EnchantmentValueEffect>>> componentType, ServerLevel level, int enchantmentLevel, ItemStack tool, org.apache.commons.lang3.mutable.MutableFloat value) -
modifyEntityFilteredValue
public void modifyEntityFilteredValue(DataComponentType<List<ConditionalEffect<EnchantmentValueEffect>>> componentType, ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, org.apache.commons.lang3.mutable.MutableFloat value) -
modifyDamageFilteredValue
public void modifyDamageFilteredValue(DataComponentType<List<ConditionalEffect<EnchantmentValueEffect>>> componentType, ServerLevel level, int enchantmentLevel, ItemStack tool, Entity entity, DamageSource damageSource, org.apache.commons.lang3.mutable.MutableFloat value) -
damageContext
public static LootContext damageContext(ServerLevel level, int enchantmentLevel, Entity entity, DamageSource damageSource) -
itemContext
-
locationContext
public static LootContext locationContext(ServerLevel level, int enchantmentLevel, Entity entity, boolean enchantmentActive) -
entityContext
public static LootContext entityContext(ServerLevel level, int enchantmentLevel, Entity entity, Vec3 origin) -
blockHitContext
public static LootContext blockHitContext(ServerLevel level, int enchantmentLevel, Entity entity, Vec3 origin, BlockState state) -
applyEffects
public static <T> void applyEffects(List<ConditionalEffect<T>> effects, LootContext context, Consumer<T> applier) -
runLocationChangedEffects
public void runLocationChangedEffects(ServerLevel level, int enchantmentLevel, EnchantedItemInUse item, LivingEntity entity) -
stopLocationBasedEffects
public void stopLocationBasedEffects(int enchantmentLevel, EnchantedItemInUse item, LivingEntity entity) -
enchantment
-
hashCode
public final int hashCode()Returns a hash code value for this object. The value is derived from the hash code of each of the record components. -
equals
Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared withObjects::equals(Object,Object)
. -
description
Returns the value of thedescription
record component.- Returns:
- the value of the
description
record component
-
definition
Returns the value of thedefinition
record component.- Returns:
- the value of the
definition
record component
-
exclusiveSet
Returns the value of theexclusiveSet
record component.- Returns:
- the value of the
exclusiveSet
record component
-
effects
Returns the value of theeffects
record component.- Returns:
- the value of the
effects
record component
-
IItemStackExtension.supportsEnchantment(Holder)