Custom mob health

Discussion in 'Plugin Development' started by chris8787878787, Aug 26, 2015.

Thread Status:
Not open for further replies.
  1. Offline


    i was wondering if it's possible to give a mob custom health? Meaning instead of the average amount of health they have I could set it to something else. .setHealth() doesn't work in this way it seems, after a few attempts. So is it possible or will I have to do some kind of illusion
  2. Try something like increasing the damage done to it, if the ways you tried since now didn't work.
    For example:
    Pig has 20 hearts and you hit it with a sword giving 5 damage to it.
    If you want the pig to only have 10 hearts instead, multiply the damage done to it with 20/10 (=2).
  3. Offline


    @Ahmet094 Would this be in EntityDamageEntity event? And instead of multiplying the damage would dividing it to lower the damage work? I would really appreciate an example.
  4. Offline

    timtower Administrator Administrator Moderator

    Moved to plugin development
  5. Code:
        int pig_original_health = 30;
        int pig_new_health = 20;
        public void modifiedDamage(EntityDamageByEntityEvent e){ 
            if(e.getEntityType() == EntityType.PIG){
    Just an example. Neither effective nor perfect.
  6. Offline


    @Ahmet094 The original health would have to be 10 for pigs though.

    @chris8787878787 And why would .setHealth not work? Did you use .setMaxHealth too?
  8. Offline


    @au2001 Yes. I think .setHealth just confuses the code into thinking I want to set its health to a number within its normal max health, nothing more.
  9. Offline


    @chris8787878787 Use:
    Damageable.setMaxHealth(Math.min(health, Damageable.getMaxHealth()));
    and then:
  10. Offline


    @au2001 Still doesn't work :/ Does that normally work for you? It still gives me that same error: "Health must be between 0 and 20.0"

    @au2001 Ah, nevermind, solved it. Thanks though.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
    Last edited by a moderator: Jun 11, 2016
  11. Offline


Thread Status:
Not open for further replies.

Share This Page