类 ItemAttributeModifierEvent
java.lang.Object
net.neoforged.bus.api.Event
net.neoforged.neoforge.event.ItemAttributeModifierEvent
public class ItemAttributeModifierEvent
extends net.neoforged.bus.api.Event
This event is fired when the attributes for an item stack are queried (for any reason) through
This event is fired regardless of if the stack has
IItemStackExtension.getAttributeModifiers()
.
This event is fired regardless of if the stack has
DataComponents.ATTRIBUTE_MODIFIERS
or not. If your attribute should be
ignored when attributes are overridden, you can check for the presence of the component.
This event may be fired on both the logical server and logical client.
-
嵌套类概要
嵌套类修饰符和类型类说明private static class
Advanced version ofItemAttributeModifiers.Builder
which supports removal and better sanity-checking. -
字段概要
字段 -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明boolean
addModifier
(Holder<Attribute> attribute, AttributeModifier modifier, EquipmentSlotGroup slot) Adds a new attribute modifier to the given stack.build()
Builds a newItemAttributeModifiers
with the results of this event, returning the default modifiers if no changes were made.void
Removes all modifiers for all attributes.Returns the builder used for adjusting the attribute modifiers, creating it if it does not already exist.返回 the default attribute modifiers before changes made by the event。返回 the item stack whose attribute modifiers are being computed。Returns an unmodifiable view of the attribute modifier entries.boolean
removeAllModifiersFor
(Holder<Attribute> attribute) Removes all modifiers for the given attribute.boolean
removeIf
(Predicate<ItemAttributeModifiers.Entry> condition) Removes modifiers based on a condition.boolean
removeModifier
(Holder<Attribute> attribute, ResourceLocation id) Removes an attribute modifier for the target attribute by idvoid
replaceModifier
(Holder<Attribute> attribute, AttributeModifier modifier, EquipmentSlotGroup slot) Adds a new attribute modifier to the given stack, optionally replacing any existing modifiers with the same id.
-
字段详细资料
-
stack
-
defaultModifiers
-
builder
-
-
构造器详细资料
-
ItemAttributeModifierEvent
@Internal public ItemAttributeModifierEvent(ItemStack stack, ItemAttributeModifiers defaultModifiers)
-
-
方法详细资料
-
getItemStack
返回 the item stack whose attribute modifiers are being computed。- 返回:
- the item stack whose attribute modifiers are being computed
-
getDefaultModifiers
返回 the default attribute modifiers before changes made by the event。- 返回:
- the default attribute modifiers before changes made by the event
-
getModifiers
Returns an unmodifiable view of the attribute modifier entries. Do not use the returned value to create anItemAttributeModifiers
since the underlying list is not immutable.If you need an
ItemAttributeModifiers
, you may need to callbuild()
- API Note:
- Use other methods from this event to adjust the modifiers.
-
addModifier
public boolean addModifier(Holder<Attribute> attribute, AttributeModifier modifier, EquipmentSlotGroup slot) Adds a new attribute modifier to the given stack. Two modifiers with the same id may not exist for the same attribute, and this method will fail if one exists.- 参数:
attribute
- The attribute the modifier is formodifier
- The new attribute modifierslot
- The equipment slots for which the modifier should apply- 返回:
- True if the modifier was added, false if it was already present
- API Note:
- Modifiers must have a unique and consistent
ResourceLocation
id, or the modifier will not be removed when the item is unequipped.
-
removeModifier
Removes an attribute modifier for the target attribute by id- 返回:
- True if an attribute modifier was removed, false otherwise
-
replaceModifier
public void replaceModifier(Holder<Attribute> attribute, AttributeModifier modifier, EquipmentSlotGroup slot) Adds a new attribute modifier to the given stack, optionally replacing any existing modifiers with the same id.- 参数:
attribute
- The attribute the modifier is formodifier
- The new attribute modifierslot
- The equipment slots for which the modifier should apply- API Note:
- Modifiers must have a unique and consistent
ResourceLocation
id, or the modifier will not be removed when the item is unequipped.
-
removeIf
Removes modifiers based on a condition.- 返回:
- true if any modifiers were removed
-
removeAllModifiersFor
Removes all modifiers for the given attribute.- 返回:
- true if any modifiers were removed
-
clearModifiers
public void clearModifiers()Removes all modifiers for all attributes. -
build
Builds a newItemAttributeModifiers
with the results of this event, returning the default modifiers if no changes were made. -
getBuilder
Returns the builder used for adjusting the attribute modifiers, creating it if it does not already exist.
-