Jump to content

[1.10] Set Max Health of Player


Darki

Recommended Posts

You need to apply an attribute modifier to the player.

 

When I did this in my mod, I created a capability to manage the modifier. You can see the API here and the implementation here.

 

Is there a more simple way of doing it?

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

You need to apply an attribute modifier to the player.

 

When I did this in my mod, I created a capability to manage the modifier. You can see the API here and the implementation here.

 

Is there a more simple way of doing it?

 

It depends on what your needs are.

 

When does the player's maximum health need to change? How often does it need to change? Are there existing systems (e.g. potions, equipment) that will apply the modifier when you need it?

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.

Link to comment
Share on other sites

It depends on what your needs are.

 

When does the player's maximum health need to change? How often does it need to change? Are there existing systems (e.g. potions, equipment) that will apply the modifier when you need it?

Can you explain that a bit more? If you would want for the players health to not exceed 5 hearts for example I thought you only need to change it once when the player enters the world.

I still haven't published a mod because I can never get that in-dev version just right to warrant a public release. And yes, after two years of mod development I am still learning to speak Java.

 

Follow me on GitHub: https://github.com/yooksi

Contact me on Twitter: https://twitter.com/yooksi

Read my Minecraft blog: https://yooksidoesminecraft.blogspot.de/

Link to comment
Share on other sites

It depends on what your needs are.

 

When does the player's maximum health need to change? How often does it need to change? Are there existing systems (e.g. potions, equipment) that will apply the modifier when you need it?

Can you explain that a bit more? If you would want for the players health to not exceed 5 hearts for example I thought you only need to change it once when the player enters the world.

 

You could apply the modifier once when the player enters the world, but that will be a static reduction and won't account for other modifiers being added or removed.

 

If you want to change the modifier's amount, you need to handle removing it, re-calculating the reduction, making sure the max health doesn't reach 0 and re-applying it.

 

I chose to do this with a capability.

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.

Link to comment
Share on other sites

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.