Uploaded image for project: 'Minecraft: Java Edition'
  1. Minecraft: Java Edition
  2. MC-16345

Reducing the player's base max health using /attribute does not always reduce their current health

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • 24w19a
    • 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"'}}

        1. health.png
          health.png
          88 kB
        2. MC-16345.mp4
          9.80 MB
        3. MC-16345.png
          MC-16345.png
          1.37 MB

            panda4994 [Mojang] Panda
            clamlol clam lol
            Votes:
            48 Vote for this issue
            Watchers:
            18 Start watching this issue

              Created:
              Updated:
              Resolved:
              CHK: