MC Toolkit

Guides / Commands & Data

/attribute: base value versus modifiers, and why yours keeps resetting

Setting a base value is permanent and setting a modifier is not — unless you pick the wrong operation. The three operations, the stacking order, and the slot trap.

/attribute looks like one command with three subcommands. It is really two different systems that happen to share a name, and mixing them up is why values keep snapping back.

base versus modifier

/attribute @s minecraft:max_health base set 40
/attribute @s minecraft:max_health modifier add my_buff 20 add_value
  • base set rewrites the entity's own value. It persists through reloads and is not removed by anything except another base set.
  • modifier add layers a named adjustment on top. It is saved with the entity just like the base, it has an id, and it can be removed by that id.

If your change will not go away, you either used base set and need base reset, or added a modifier that needs modifier remove <id>.

The three operations, and the order they apply

OperationDoesApplied
add_valuevalue + nfirst
add_multiplied_basevalue + (base × n)second
add_multiplied_totalrunning total × (1 + n)last

The order is fixed and it matters. Starting from base 20, then add_value 10 and add_multiplied_total 0.5:

20 → 30 → 45          not  20 → 30 → 30 + 10 = 40

add_multiplied_base multiplies the base after the add_value modifiers are added in — not the running total — which is why two of them stack additively rather than compounding.

Modifier ids are namespaced now

Older versions used a UUID. Modern versions use a namespaced id:

/attribute @s minecraft:attack_damage modifier add my_pack:rage 5 add_value

Adding a second modifier with the same id fails with "Modifier … is already present" rather than stacking or replacing it. To refresh a buff, modifier remove it first.

Equipment modifiers live on the item, not the entity

A sword's damage bonus is an attribute_modifiers item component, and it only applies while the item is in the right slot:

/give @s diamond_sword[attribute_modifiers=[{type:"attack_damage",amount:5,
  operation:"add_value",slot:"mainhand",id:"my:bonus"}]]

Leaving out slot is the usual mistake. It defaults to any, so the modifier applies in every equipment slot — a sword buffs you from your offhand, or from an armour slot, not just from your main hand.

Valid slots: mainhand, offhand, hand, head, chest, legs, feet, armor, body, saddle, any.

Reading a value back

/attribute @s minecraft:max_health get

returns the effective total, modifiers included. /attribute @s minecraft:max_health base get returns just the base.

Build any of these — including the item-component form with the slot set — in the Entity & Combat Command Builder.

Entity & Combat Command Builder →

More guides

Browse all →