Jump to content

[1.7.10] Best way to handle health changes (customHP)


Recommended Posts

Posted

Currently everything I have is handled by PlayerExtended which is wrapped EntityPlayer and contains player stats, levelHistory, quests, everything.

Most is synced by packets on-request (e.g if you want to see stats you send request to server when opening GUI, but in combat, client itself never have values like dodge %, it's all on server). Only stuff send onTick are basic values (used by ClientGuis, like mana).

Now I've been thinking - why not adding health value to this (like mana) and just intercept HURT event like:

PSEUDO
LivingHurtEvent event; if (player)
PlayerExtended.wrap(player).hurtPlayer(event.amount, event.source)

And rest of it handle on my own (ofc. when CustomHealth <= 0 player.setDead)

 

Question is: How un-/safe is this? Is there ANY way that player can get damage without calling this event? What about knockback?

 

What would be a better way - I guess SharedMonsterAttributes, but I have no idea how they are synced, how saved and how to edit/add them?

 

 

1.7.10 is no longer supported by forge, you are on your own.

Posted

Let's just put it this way: How the hell can I set players max HP based on my "I want", but in a way that it won't be a const value. (MaxHP = Str*5 + premiumHP + something + whatever)

1.7.10 is no longer supported by forge, you are on your own.

Posted

Aww... it's probably me being stupid, sry.

 

So normally player HP is defined by:

public final float getMaxHealth()
    {
        return (float)this.getEntityAttribute(SharedMonsterAttributes.maxHealth).getAttributeValue();
    }

 

And from what I know "maxHealth" is a const.

 

I don't want it to be const. I want maxHP to be value dependent on my player stats. And "I want" means "I want it to be x on this tick, but on next tick it will be y"

 

So since I alredy have huge player handler I though why not making customHealth just some next value like mana, but just track hurt event to instead hurt normal HP, make it hurt customHP and if it's == 0 set player dead.

1.7.10 is no longer supported by forge, you are on your own.

Posted

I'll just end my overthinking and ask:

 

How they are synced, how saved and how to edit them? Also same question for custom-made IAttributes. (Till now i didn't think they are entity-specified, but SHARED)

1.7.10 is no longer supported by forge, you are on your own.

Posted

Okay so I gotten around with that system and it all would be nice and tidy, but still (also thanks for your help so far):

 

My EntityPlayer's maxHP is influenced by:

Level (50 levels), PlayerStats (2 stats), Inventory (12 items), Generics (1-3 extra values, something like race/class), EffectsMap (effects that are currently on player).

 

Now from what I see - I could leave base health to be 20 and do rest by adding Modifiers, but that would leave me with UP TO DOZEN of those (counting situations like all my 12 items give some health buff and player has few health buffs on him).

1. Is having so many Modifiers good? (note: All of them would be marked isSaved = false, because everything from Level to EffectsMap is alredy saved and only loaded on startup)

 

2. So Attributes are static (not synced) on both client and server, how about Modifiers? Does client know about Modifiers or it just receives final value?

1.7.10 is no longer supported by forge, you are on your own.

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.