[SOLVED]Custom mob health

Discussion in 'Plugin Development' started by mollekake, Aug 23, 2012.

Thread Status:
Not open for further replies.
  1. I'm trying to make my Ghasts have more life than normal, but it doesn't seem to work.
    So i tried it on a zombie, gave it 300 health, but it still went down on 5 sword hits or something.
    What am i doing wrong?
    Ghast class code below:
    Code:
    import net.minecraft.server.World;
     
    public class Ghasts extends net.minecraft.server.EntityGhast{
     
        public Ghasts(World world) {
            super(world);
        }
     
        @Override
        public int getMaxHealth() {
            return 20;    //Double life points
        }
    }
     
  2. Offline

    sd5

    Check out this:
    Code:
    @EventHandler
    public void onCreatureSpawn(CreatureSpawnEvent event) {
        if(event.getEntityType() == EntityType.GHAST) {
            event.getEntity().setHealth(5000);
        }
    }
     
  3. Offline

    Fl1pzta

    sd5 I seriously thought you added your signature into that :eek:
     
  4. Offline

    sd5

    Lool ^^
     
  5. hmm, don't seem to work.
     
  6. anyone else know how? can't seem to get it to work.
     
  7. Offline

    Barinade

    What he wrote should work, you sure you got your listener set up right?
     
  8. Offline

    sd5

    Try to get the event entity and check wherher it is an instance of your class. I dont know whether this works becuause evebt.getEntity returns a bukkit entity but your class extends a net.minecraft.server entity...
     
  9. if i get the entity it returns CraftGhast. if i get the entitytype it returns GHAST.
    bu i can't set the health of the entitytype.
     
  10. Offline

    travja

    Not the entity type, but if you know the entity type is a GHAST. You can then set the event.getEntity().setHealth(int); knowing that it will only change the health of the ghast.
     
  11. i'm trying that but it gives me an severe error when i spawn a ghast on the server. don't get why. everything else is working fine in the listener.
     
  12. Offline

    travja

    Can you post the error?
     
  13. figured it out. could not do it that way, so i just created a custom mob class. easier.
     
  14. Offline

    Icyene

    Perhaps easier, but it won't play nice with other plugins doing the same thing... Try:

    Code:
    ((CraftGhast)yourGhast).getHandle().health = 1000;
    
    I wrote that from my head, but there is a health integer in nms.Entity, and since CraftGhast.getHandle returns an EntityGhast (which extends nms.Entity) you should have access to health.
     
Thread Status:
Not open for further replies.

Share This Page