类 AttributeUtil
java.lang.Object
net.neoforged.neoforge.common.util.AttributeUtil
Utility code to support
IAttributeExtension
.-
嵌套类概要
嵌套类修饰符和类型类说明private static final record
Stores a single base modifier (determined byIAttributeExtension.getBaseId()
) and any other children non-base modifiers for the same attribute.private static class
State-tracking object used to merge attribute modifier tooltips inapplyTextFor(net.minecraft.world.item.ItemStack, java.util.function.Consumer<net.minecraft.network.chat.Component>, com.google.common.collect.Multimap<net.minecraft.core.Holder<net.minecraft.world.entity.ai.attributes.Attribute>, net.minecraft.world.entity.ai.attributes.AttributeModifier>, net.neoforged.neoforge.common.util.AttributeTooltipContext)
. -
字段概要
字段修饰符和类型字段说明static final Comparator
<AttributeModifier> Comparator forAttributeModifier
.static final ResourceLocation
ID of the base modifier for Attack Damagestatic final ResourceLocation
ID of the base modifier for Attack Speedstatic final ResourceLocation
ID of the base modifier for Attack Rangestatic final ResourceLocation
ID used for attribute modifiers used to hold merged values whenNeoForgeMod.enableMergedAttributeTooltips()
is active.private static final org.apache.logging.log4j.Logger
-
构造器概要
构造器 -
方法概要
修饰符和类型方法说明static void
addAttributeTooltips
(ItemStack stack, Consumer<Component> tooltip, TooltipDisplay tooltipDisplay, AttributeTooltipContext ctx) Checks if attribute modifier tooltips should show, and if they should, adds tooltips for all attribute modifiers present on an item stack to the stack's tooltip lines.static void
addPotionTooltip
(List<com.mojang.datafixers.util.Pair<Holder<Attribute>, AttributeModifier>> list, Consumer<Component> tooltips) Adds tooltip lines for the attribute modifiers contained in aPotionContents
.static void
applyModifierTooltips
(ItemStack stack, Consumer<Component> tooltip, AttributeTooltipContext ctx) Applies the attribute modifier tooltips for all attribute modifiers present on the item stack.static void
applyTextFor
(ItemStack stack, Consumer<Component> tooltip, com.google.common.collect.Multimap<Holder<Attribute>, AttributeModifier> modifierMap, AttributeTooltipContext ctx) Applies the text for the provided attribute modifiers to the tooltip for a given item stack.static com.google.common.collect.Multimap
<Holder<Attribute>, AttributeModifier> getSortedModifiers
(ItemStack stack, EquipmentSlotGroup slot) Returns a sorted, mutableMultimap
containing all the attribute modifiers on an item stack for the given group.private static MutableComponent
Creates a mutable component starting with the char used to represent a drop-down list.static com.google.common.collect.Multimap
<Holder<Attribute>, AttributeModifier> Creates a sortedTreeMultimap
used to ensure a stable iteration order of item attribute modifiers.
-
字段详细资料
-
BASE_ATTACK_DAMAGE_ID
ID of the base modifier for Attack Damage -
BASE_ATTACK_SPEED_ID
ID of the base modifier for Attack Speed -
BASE_ENTITY_REACH_ID
ID of the base modifier for Attack Range -
FAKE_MERGED_ID
ID used for attribute modifiers used to hold merged values whenNeoForgeMod.enableMergedAttributeTooltips()
is active.Should not be used by any real attribute modifiers for gameplay purposes.
-
ATTRIBUTE_MODIFIER_COMPARATOR
Comparator forAttributeModifier
. First compares by operation, then amount, then the ID. -
LOGGER
private static final org.apache.logging.log4j.Logger LOGGER
-
-
构造器详细资料
-
AttributeUtil
public AttributeUtil()
-
-
方法详细资料
-
addAttributeTooltips
public static void addAttributeTooltips(ItemStack stack, Consumer<Component> tooltip, TooltipDisplay tooltipDisplay, AttributeTooltipContext ctx) Checks if attribute modifier tooltips should show, and if they should, adds tooltips for all attribute modifiers present on an item stack to the stack's tooltip lines.After the tooltip lines have been added, fires the
AddAttributeTooltipsEvent
to allow mods to add additional attribute-related lines.- 参数:
tooltip
- A consumer to add the tooltip lines to.ctx
- The tooltip context.
-
applyModifierTooltips
public static void applyModifierTooltips(ItemStack stack, Consumer<Component> tooltip, AttributeTooltipContext ctx) Applies the attribute modifier tooltips for all attribute modifiers present on the item stack.Before application, this method posts the
GatherSkippedAttributeTooltipsEvent
to determine which tooltips should be skipped.This method is also responsible for adding the modifier group category labels.
- 参数:
tooltip
- A consumer to add the tooltip lines to.ctx
- The tooltip context.
-
applyTextFor
public static void applyTextFor(ItemStack stack, Consumer<Component> tooltip, com.google.common.collect.Multimap<Holder<Attribute>, AttributeModifier> modifierMap, AttributeTooltipContext ctx) Applies the text for the provided attribute modifiers to the tooltip for a given item stack.This method will attempt to merge multiple modifiers for a single attribute into a single modifier if NeoForgeMod.enableMergedAttributeTooltips() was called.
- 参数:
stack
- The item stack that owns the modifiers.tooltip
- The consumer to append tooltip components to.modifierMap
- A mutable map of modifiers to convert into tooltip lines.ctx
- The tooltip context.
-
addPotionTooltip
public static void addPotionTooltip(List<com.mojang.datafixers.util.Pair<Holder<Attribute>, AttributeModifier>> list, Consumer<Component> tooltips) Adds tooltip lines for the attribute modifiers contained in aPotionContents
.- 参数:
list
- The list of attribute modifiers generated by callingMobEffect.createModifiers(int, java.util.function.BiConsumer<net.minecraft.core.Holder<net.minecraft.world.entity.ai.attributes.Attribute>, net.minecraft.world.entity.ai.attributes.AttributeModifier>)
for each mob effect instance on the potion.tooltips
- The tooltip consumer to add lines to.
-
sortedMap
Creates a sortedTreeMultimap
used to ensure a stable iteration order of item attribute modifiers. -
getSortedModifiers
public static com.google.common.collect.Multimap<Holder<Attribute>,AttributeModifier> getSortedModifiers(ItemStack stack, EquipmentSlotGroup slot) Returns a sorted, mutableMultimap
containing all the attribute modifiers on an item stack for the given group.This includes attribute modifiers from components (or default modifiers, if not present), enchantments, and the
ItemAttributeModifierEvent
.- 参数:
stack
- The stack to query modifiers for.slot
- The slot group to query modifiers for.
-
listHeader
Creates a mutable component starting with the char used to represent a drop-down list.
-