Custom health for zombie

Discussion in 'Plugin Development' started by johnnyD, Aug 4, 2020.

  1. Offline

    johnnyD

    Since zombie doesnt extend attributable, how can I set the health for a custom zombie entity.

    this.setMaxHealth isnt a thing, and ofcourse .setHealth isnt what I need either.
     
  2. Online

    KarimAKL

  3. Offline

    johnnyD

  4. Offline

    Strahan

    It's just a matter of setting the attribute, but the way you are going about it is not correct as you aren't supposed to be casting to attributable. Post your code.
     
  5. Offline

    johnnyD

  6. Online

    KarimAKL

    @johnnyD Does your class implement Zombie?
     
  7. Offline

    johnnyD

    @KarimAKL extends EntityZombie, implementing zombie causes me to add a bunch of unimplemented methods & also doesnt fix the issue.
     
  8. Online

    KarimAKL

    EntityZombie doesn't implement Attributable.

    Yeah, you need to override them.

    What do you mean? The same error shouldn't persist as your class has Attributable as a super interface.
     
  9. Offline

    AddictedFader

    This is what I use for my plugin and it works just fine, I am using spigot1.16.1
    Code:
    @EventHandler
        public void creatureSpawn(CreatureSpawnEvent event) {
            if(event.getEntityType() == EntityType.ZOMBIE) {
                Zombie z = (Zombie) event.getEntity();
                z.getAttribute(Attribute.GENERIC_MAX_HEALTH).setBaseValue(5D);
                z.setHealth(5D);
         }
    }
     
  10. Offline

    Strahan

    Oh, you're doing a new class for a mob. That I've never tried. I thought you were just taking an Entity and trying to adjust its health. That would be easy; cast to Zombie and get the GENERIC_MAX_HEALTH attribute then set the value to what you want. Not sure how to do it if making your own class for the mob.
     
  11. Offline

    johnnyD

  12. Online

    KarimAKL

    @johnnyD What are you returning in those methods?
     
  13. Offline

    johnnyD

  14. Online

    KarimAKL

    @johnnyD Ah, i believe both net.minecraft.server.Entity and org.bukkit.Nameable have a getCustomName() method. The problem is probably you extending and implementing them both.
     
  15. Offline

    johnnyD

    @KarimAKL Any suggestions? I feel like it shouldnt be this complicated just to set health of a custom zombie. I guess I could not make a new class for it, but I plan on making more custom mobs. Learning this now would make it a lot easier in the future.
     

Share This Page