-
Bug
-
Resolution: Fixed
-
Snapshot 13w21a, Minecraft 1.6.1, Minecraft 1.6.2, Minecraft 1.7.4, Minecraft 14w02c, Minecraft 14w03a, Minecraft 14w03b, Minecraft 1.7.10, Minecraft 14w30c, Minecraft 14w31a, Minecraft 14w33c, Minecraft 14w34a, Minecraft 14w34b, Minecraft 14w34c, Minecraft 14w34d, Minecraft 1.8-pre1, Minecraft 1.8.2-pre4, Minecraft 1.8.8, Minecraft 15w37a, Minecraft 1.10.2, Minecraft 16w41a, Minecraft 16w43a, Minecraft 16w44a, Minecraft 1.11 Pre-Release 1, Minecraft 1.11, Minecraft 16w50a, Minecraft 1.11.1, Minecraft 1.11.2, Minecraft 17w06a, Minecraft 17w13b, Minecraft 17w15a, Minecraft 17w16b, Minecraft 17w17a, Minecraft 17w18b, Minecraft 1.12 Pre-Release 2, Minecraft 1.12.2, Minecraft 18w15a, Minecraft 1.13.1, Minecraft 1.14.2, 1.14.4, 19w45b, 1.15.2, 20w17a, 20w18a, 20w19a, 20w20b, 20w21a, 1.16 Pre-release 1, 1.16 Pre-release 2, 1.16 Release Candidate 1, 1.16, 1.16.1, 1.16.2 Pre-release 1, 1.16.2 Pre-release 2, 1.16.2 Release Candidate 1, 1.16.2, 1.16.4, 20w51a, 21w03a, 1.16.5, 21w05b, 21w06a, 21w07a, 21w11a, 21w14a, 21w15a, 21w16a, 21w17a, 1.17 Pre-release 1, 1.17, 1.17.1, 21w39a, 21w43a, 1.18, 1.18.1, 1.18.2, 22w18a, 1.19, 1.19.2, 1.19.3 Release Candidate 3, 1.19.3, 23w03a, 1.19.4, 23w18a, 1.20.1, 23w31a, 23w32a, 23w35a, 1.20.2 Pre-release 1, 23w44a, 24w04a, 1.20.5, 1.20.6
-
Confirmed
-
Survival
-
Data Packs
-
Important
-
Platform
The bug
When the player's base max health is reduced using /attribute, their current health (stored on the server) is not always reduced accordingly. (There have been reports in the past that this bug occurs whenever the player's total max health is reduced, including using attribute modifiers, but as of the 1.20.2 snapshots I can only reproduce this by modifying the base value using /attribute.)
Reproduction
Setup
This bug occurs inconsistently and can be hard to detect when it occurs unless you're paying close attention, so it's preferable to have a dedicated testing setup. Let's start with a few of commands:
/gamerule doImmediateRespawn true /gamerule keepInventory true /gamerule naturalRegeneration false /spawnpoint @s ~ ~ ~
Now let's make our current health value visible in the sidebar:
/scoreboard objectives add health health /scoreboard objectives setdisplay sidebar health /kill @s
And, for extra visibility, let's make particles emanate from ourselves when our current health exceeds our max health. First we run the following:
/scoreboard objectives add temp dummy
Then we put the following in a powered repeating command block:
execute as @p store result score @s temp run attribute @s minecraft:generic.max_health get 1.0
And the following in an unconditional, always-active chain command block pointing away from the repeating one:
execute as @p at @s if score @s health > @s temp run particle minecraft:glow ~ ~ ~ 0.2 0 0.2 0.2 10
Now let's set up some impulse command blocks which can cause the bug to occur. Place a button on each one, and make sure they aren't adjacent to each other.
attribute @p minecraft:generic.max_health base set 1 attribute @p minecraft:generic.max_health base set 20 attribute @p minecraft:generic.max_health base set 30
Finally, we need a command block to heal ourselves to full in case we've failed to repro and want to try again. Place a button on this one too.
effect give @p minecraft:instant_health 1 20 true
Reproducing the bug
Go into survival mode. Using the command blocks you just set up, set your base max health to 30 and heal yourself to full. Try reducing your max health, first to 20, then to 1. If you get particles and notice that the health value in the sidebar exceeds the hearts on your screen, the bug has occurred! If not, start over from the beginning of this paragraph.
Once you've repro'd successfully, set your max health to 30 again. As the particles cease, note how while you do regain some black hearts, the amount of red hearts remains unchanged. I assume this is because the client is sent an "update max health" packet but the server sees no need to send an "update current health" packet since it did not know the client was out of sync.
Being hurt or healed while the bug is occurring will fix it.
Remarks
NBT state has no effect
Due to MC-197818, the player's NBT does not accurately reflect the state of their attributes. This does not seem to affect whether or not the bug occurs at a particular point in time, but if desired, you can run /kill @s to trigger that issue and MC-179940, removing the max health attribute from your NBT and starting over again with 20 health.
Attribute modifiers have no effect (anymore)
Some past reports indicate that it was possible to get the player's current health to be higher than their max health using attribute modifiers. I tried to reproduce this by playing around with the following items during the tests mentioned above, but ultimately I did not encounter any inexplicable behavior.
/give @s stick{AttributeModifiers:[{AttributeName:"minecraft:generic.max_health",Name:"health-",Slot:"mainhand",Amount:-10,Operation:0,UUID:[I;0,1111,0,111111]}],display:{Name:'"Health Reduction"'}} /give @s blaze_rod{AttributeModifiers:[{AttributeName:"minecraft:generic.max_health",Name:"health+",Slot:"mainhand",Amount:10,Operation:0,UUID:[I;0,1111,0,111112]}],display:{Name:'"Health Boost"'}} /give @s golden_helmet{AttributeModifiers:[{AttributeName:"minecraft:generic.max_health",Name:"health++",Slot:"head",Amount:20,Operation:0,UUID:[I;0,1111,0,111113]}],display:{Name:'"Mega Health Boost"'}}
- is duplicated by
-
MC-18965 Switching from or to items that change maxhealth do not update health until damage is taken
- Resolved
-
MC-19688 Max Health Attribute Does Not Automaticly Update
- Resolved
-
MC-28127 Health doesnt update with negative maxhealth
- Resolved
-
MC-55117 Scoreboard health/ atributted skull bug
- Resolved
-
MC-67856 .maxHealth doesn't reset health
- Resolved
-
MC-81307 Health Boost from AttributeName:generic.maxHealth having wrong amount.
- Resolved
-
MC-154228 Ghost Health is created when having negative maxHealth attributes
- Resolved
-
MC-171047 Player max health float values won't decrease from generic.maxHealth on items
- Resolved
-
MC-179852 Player health doesn't sync properly with /attribute minecraft:generic.max_health
- Resolved
-
MC-179962 Health does not update when minecraft:generic.max_health is set to 1
- Resolved
-
MC-180001 Reducing max health using /attribute does not reduce current health
- Resolved
-
MC-183423 max_health attribute sets value but doesn't update health
- Resolved
-
MC-184215 generic.max_health affecting fall damage
- Resolved
-
MC-187386 Changing generic.max_health doesn't change current health
- Resolved
-
MC-188160 Setting max health to the player having half a heart would always get rounded to the next full heart
- Resolved
-
MC-190590 Attribute command can't set current health to half a heart which leads to other issues
- Resolved
-
MC-196591 Abnormal behavior related to the generic.max_health attribute
- Resolved
-
MC-199741 /attribute hearts don't visually update until relog
- Resolved
-
MC-212696 Health does not actually update when holding an item with the max health attribute.
- Resolved
-
MC-226495 Life is not well displayed when your max life is an odd number
- Resolved
-
MC-233301 Attributes and Command Block Bug
- Resolved
-
MC-233859 Attribute "generic.maxHealth" doesn't subtract health values from players properly
- Resolved
-
MC-237985 Custom Max Health Armor and /attribute
- Resolved
-
MC-237991 attribute health doesnt work unless you take damage
- Resolved
-
MC-240209 max hp remove bug
- Resolved
-
MC-258616 The "/attribute @p minecraft:generic.max_health base set x" command not working properly for lower values of x..
- Resolved
-
MC-264644 If a players generic.max_health is set to a base of 1 every game tick, the game doesn't set the players health data to 1.0 when the player respawns
- Resolved
-
MC-265367 "attribute max_health" command malfunctioning at low values
- Resolved
- relates to
-
MC-19690 Reducing maxHealth / max_health can cause fake death
- Resolved
-
MC-179940 Player's attributes reset back to default values upon respawning
- Resolved
-
MC-179946 Modified max health attribute interactions with game mechanics (20w17a)
- Resolved
-
MC-64311 Attribute (Bug?)
- Resolved