Class GetEnchantmentLevelEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.enchanting.GetEnchantmentLevelEvent
public class GetEnchantmentLevelEvent
extends net.neoforged.bus.api.Event
This event is fired whenever the enchantment level of a particular item is requested for gameplay purposes.
It is called from
and
.
It is called from
invalid reference
IItemStackExtension#getEnchantmentLevel(Enchantment)
invalid reference
IItemStackExtension#getAllEnchantments()
It is not fired for interactions with NBT, which means these changes will not reflect in the item tooltip.
-
Field Summary
Modifier and TypeFieldDescriptionprotected final ItemEnchantments.Mutable
protected final HolderLookup.RegistryLookup
<Enchantment> protected final ItemStack
protected final @Nullable Holder
<Enchantment> -
Constructor Summary
ConstructorDescriptionGetEnchantmentLevelEvent
(ItemStack stack, ItemEnchantments.Mutable enchantments, @Nullable Holder<Enchantment> targetEnchant, HolderLookup.RegistryLookup<Enchantment> lookup) -
Method Summary
Modifier and TypeMethodDescriptionReturns the mutable enchantment->level map.getHolder
(ResourceKey<Enchantment> key) Attempts to resolve aHolder.Reference
for a target enchantment.Returns the underlying registry lookup, which can be used to access enchantment Holders.getStack()
Returns the item stack that is being queried against.@Nullable Holder
<Enchantment> This method returns the specific enchantment being queried frominvalid reference
IItemStackExtension#getEnchantmentLevel(Enchantment)
boolean
isTargetting
(Holder<Enchantment> ench) Helper method aroundgetTargetEnchant()
that checks if the target is the specified enchantment, or if the target is null.boolean
isTargetting
(ResourceKey<Enchantment> ench) Helper method aroundgetTargetEnchant()
that checks if the target is the specified enchantment, or if the target is null.
-
Field Details
-
stack
-
enchantments
-
targetEnchant
-
lookup
-
-
Constructor Details
-
GetEnchantmentLevelEvent
public GetEnchantmentLevelEvent(ItemStack stack, ItemEnchantments.Mutable enchantments, @Nullable @Nullable Holder<Enchantment> targetEnchant, HolderLookup.RegistryLookup<Enchantment> lookup)
-
-
Method Details
-
getStack
Returns the item stack that is being queried against. -
getEnchantments
Returns the mutable enchantment->level map. -
getTargetEnchant
This method returns the specific enchantment being queried frominvalid reference
IItemStackExtension#getEnchantmentLevel(Enchantment)
If this is value is present, you only need to adjust the level of that enchantment.
If this value is null, then the event was fired from
invalid reference
IItemStackExtension#getAllEnchantments()
- Returns:
- The specific enchantment being queried, or null, if all enchantments are being requested.
-
isTargetting
Helper method aroundgetTargetEnchant()
that checks if the target is the specified enchantment, or if the target is null.- Parameters:
ench
- The enchantment to check.- Returns:
- If modifications to the passed enchantment are relevant for this event.
- See Also:
-
isTargetting
Helper method aroundgetTargetEnchant()
that checks if the target is the specified enchantment, or if the target is null.- Parameters:
ench
- The enchantment to check.- Returns:
- If modifications to the passed enchantment are relevant for this event.
- See Also:
-
getHolder
Attempts to resolve aHolder.Reference
for a target enchantment. Since enchantments are data, they are not guaranteed to exist.- Parameters:
key
- The target resource key- Returns:
- If the holder was available, an Optional containing it; otherwise an empty Optional.
-
getLookup
Returns the underlying registry lookup, which can be used to access enchantment Holders.- Returns:
- the underlying registry lookup, which can be used to access enchantment Holders
-