Guides
ReferenceAttributes

Attribute modifiers: max health, speed, and knockback resistance

7 min read

Attributes are the underlying stats of every living entity: max health, movement speed, attack damage, knockback resistance, and more. You can change them two ways — the /attribute command edits an entity directly, and the attribute_modifiers item component attaches a stat boost to gear that applies while it is worn or held.

Guide result

A working pattern for setting entity attributes directly, or attaching attribute modifiers to items.

Open related workflowAttributesChanging entity attributes with commands

Recommended path

  1. Decide whether to edit an entity directly (/attribute) or attach a bonus to an item (attribute_modifiers).
  2. For an entity, run /attribute with the target, attribute id, and base value.
  3. For an item, add an attribute_modifiers component with an amount, operation, and slot.
  4. Set the version, since attribute ids dropped the generic. prefix in 1.21.2.
  5. Test in game and confirm the health bar, speed, or damage changed as expected.

The /attribute command

To set an attribute on an entity, use /attribute <target> <attribute> base set <value>. For example /attribute @s minecraft:max_health base set 40 gives the player 20 hearts (base health is 20). Speed is a small number: /attribute @s minecraft:movement_speed base set 0.15 is noticeably faster than the default 0.1.

In Java 1.21.2 the attribute ids dropped the generic. prefix, so generic.max_health became minecraft:max_health (or just max_health). Set the version so the generator writes an id your world accepts, otherwise the command silently targets nothing.

  • Format: /attribute <target> <attribute> base set <value>.
  • max_health of 40 equals 20 hearts; base is 20.
  • 1.21.2+ uses max_health; older versions use generic.max_health.

Attribute modifiers on items

The attribute_modifiers component (Java 1.20.5+) attaches a stat change to an item that applies while it is in a given slot. For example [attribute_modifiers=[{type:"max_health",amount:10,operation:"add_value",slot:"any"}]] adds 5 hearts while the item is present.

The operation is add_value (flat), add_multiplied_base, or add_multiplied_total (percentage-style). The slot can be mainhand, offhand, head, chest, legs, feet, armor, or any. This is how custom weapons grant bonus damage or armor grants extra health.

  • operation: add_value, add_multiplied_base, or add_multiplied_total.
  • slot: mainhand, offhand, the armor slots, armor, or any.
  • Modifiers apply only while the item sits in the chosen slot.

Useful attributes to know

The stats people change most are max_health, movement_speed, attack_damage, attack_speed, knockback_resistance (0 to 1, where 1 is immune to knockback), and max_absorption. Scale, step_height, and jump_strength were added to the attribute system in later versions.

Direct base edits are permanent for that entity until changed, while item modifiers come and go with the gear. Use base set for a boss with fixed high health, and item modifiers for equipment a player can swap.

Ship the copied artifact

Use this guide to produce the artifact a player or map maker will actually run: a copied command, ordered Project pack, or datapack resource. The final review should happen on that copied output, not only on the editable builder state.

When the workflow is version-sensitive, label the target version beside the command. When it uses selectors, scoreboards, bossbars, tags, loot tables, or project order, test those dependencies in a clean world before publishing the setup.

  • Copy from Output for one command and from Project for ordered packs.
  • Keep Java, Bedrock, and snapshot variants separate.
  • Test destructive selectors with harmless output first.
  • Update related presets when the guide becomes the canonical workflow.

Related guides and presets

FAQ

How do I set a player max health above 20?

Use /attribute @s minecraft:max_health base set 40 for 20 hearts. On versions before 1.21.2 the id is generic.max_health. The change stays until reset.

How do I make a mob immune to knockback?

Set knockback_resistance to 1.0, for example /attribute @e[type=zombie,limit=1] minecraft:knockback_resistance base set 1. Values run from 0 (normal) to 1 (immune).

What is the difference between /attribute and attribute_modifiers?

/attribute changes an entity directly and persists. attribute_modifiers is an item component whose bonus only applies while the item is worn or held in the specified slot.

Why does my attribute command do nothing?

Most often the attribute id is wrong for the version. 1.21.2+ uses ids like max_health, while older versions require generic.max_health. Set the version and use the matching id.

What number is normal movement speed?

The default player movement_speed is about 0.1. Small increases feel large, so 0.15 is clearly faster and 0.2 is very fast.

When should this guide become a Project pack?

Use Project when the workflow needs more than one command, has setup and cleanup order, or must be edited again after testing. One-off commands can stay in Output.