Tough As Nails

Tough As Nails

21M Downloads

Dying when player's max health is changed to lower value than default

mchorse opened this issue ยท 4 comments

commented

Hello there!

I'm developer of Metamorph mod (basically Morph's clone), and my users reported an issue with Tough as Nails mod when player's max health changed programmatically to something lower than 10 points or so points, I believe, the player begins to repeatedly dying. Is there any way to solve this issue? Maybe adding an option to disable scaled health damage, or adapting the algorithm for lower values?

See this issue: mchorse/metamorph#28, and this comment on CurseForge.

Thank you for attention and have a good day! ๐Ÿ˜„

commented

I ran into this exact same issue, actually. It's solved rather easily by setting a minimum bound on the max health attribute, or less easily using Choonster's method in TestMod3.

I tried submitting a Forge PR for the former solution (sighs deeply) but it would make a rather trivial coremod patch.

A bit off-topic, but I believe the minimum bound on max health combined with negative health modifiers makes it possible to heal health by morphing into a chicken and back. :P

commented

Hey @asanetargoss, thanks for reply, and sorry for my late response!

It's solved rather easily by setting a minimum bound on the max

I haven't really dealt with entity attributes, so I don't really know what is minimum bound in context of entity attributes. Could you show me an example?

commented

See net.minecraft.entity.SharedMonsterAttributes. The MAX_HEALTH attribute has a default value of 20 and is allowed to range between 0 and 1024. By setting the lower bound of this range to a positive non-zero value, you can prevent max health from ever being zero.

Whenever you update an entity's health, Minecraft checks to make sure that the health value is between 0 and the entity's max health. If the health value is too high, Minecraft reduces the health value to equal the max health. Zero max health causes zero current health, which causes death.

The fix I have used is to change the minimum bound on the MAX_HEALTH attribute from 0 to 1E-45. That's the lowest order of magnitude I could get the number to be without the number being interpreted as 0 for unknown internal reasons. The low number ensures a player with that amount of hp is killed in one hit in any sane scenario.

Here's a forum post with an explanation of Entity Attributes, if you're interested:
http://www.minecraftforge.net/forum/topic/29927-the-entity-attribute-system-how-to-manipulate-it-in-code/

commented

Good news! The latest Forge commits for 1.10-1.12 now have a lower bound on max health, so max health updates can no longer kill you. :D (As soon as new Forge versions are released)