mojira.dev
MC-177264

Entities die when you modify their health using /execute store

I think you need to know the circumstances in order to understand this report; I am currently working on a project, in which i use commands to set the Health of an entity to the "generic.max_health" attribute of the same entity using /execute store.

This was working fine, until 20w14a, where it just kills the entity, instead of setting its health to the appropriate amount.

The command i used is as follows:

/execute as <target> store result entity @s Health double 1 run data get entity @s Attributes[{Name:"generic.max_health"}].Base

 

Comments 5

First of all, you need to be using minecraft:generic.max_health. That's a very dangerous command, since, as you've observed, it will return 0 and kill the mob if the attribute you're looking for is not found.

However, I have noticed in this snapshot that certain attributes aren't showing up for various mobs, presumably when it's the default for their entity type. I'm not sure whether that's intended, so I'll keep this report open.

Oh, should probably have included that i tried getting it to work multiple times, i even tried the old attribute names like "maxHealth" (Which obviously didn't work, didn't really expect it to either). I also tried doing "minecraft:generic.max_health", but that didn't work either. /summon zombie ~ ~ ~ {Health:30f,Attributes:[{Name:"generic.max_health",Base:30}]} also seems to be working without the "minecraft:", so i don't know. Might be intended, or just some of trouble that would inevitably come with changing the attribute names.

Sorry for my incompetence.

It would actually seem as though this only part of a larger issue... Extracting attribute values from entities with /execute store just gets a zero

As of 23w31a this is not an issue. During my testing, if the entity died it was either because:

  • The attribute I was searching for didn't exist in NBT (which may be a separate bug; MC-197818 seems like a partial description and was created relatively shortly after 20w14a)

  • The value I was trying to store was less than 1.0, in which case it was rounded down to 0.0 by the store subcommand (this is longstanding behavior and I believe it is intended)

The example command here is an example of the former case. If the goal is simply to heal the entity to max health, the following command should work just fine, since the Health value seems to be instantaneously (or very nearly so) clamped to the entity's max health:

/data modify entity <target> Health set value 694201337f

nottellingyou

(Unassigned)

Confirmed

Commands, Entities

20w14a, 1.16.2 Pre-release 2, 1.16.2 Release Candidate 1, 1.16.2

Retrieved