Jump to content

[SOLVED][1.7.10] - Player max health AttributeModifier


Recommended Posts

Posted

Hello.

I changed the maximum health of the player, but there was a problem:

After the death of the player or rejoining is not saved!

Help me please.

IAttributeInstance healthAttribute = player.getEntityAttribute(SharedMonsterAttributes.maxHealth);
AttributeModifier moras = new AttributeModifier(UUID.fromString("B9766C51-9566-4402-BC1F-2EE2A276D836"), "Moras Health Boost", abilities[i], 0).setSaved(true);
healthAttribute.removeModifier(moras);
healthAttribute.applyModifier(moras);

Posted

Take a look here:

https://gist.github.com/Choonster/b435956191898d34c7f8

 

I'm not very familiar with using attributes but it looks like you are applying the change wrong.

 

That code is designed to apply modifiers from an equipment

ItemStack

(held item or equipped armour). If you're applying a modifier from some other mechanic, that's not the way to do it.

 

Saved modifiers only save when the

Entity

is written to NBT (generally when saving the world). When a player respawns, a new

EntityPlayer

is created (without copying the attribute NBT) and

PlayerEvent.Clone

is fired; you should be able to use this event to reapply the modifiers.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.