Changing maximum entity health

Discussion in 'Plugin Development' started by matejdro, Dec 2, 2011.

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

    matejdro

    Before 1.0, you could simply use entity.setHealth() to set higher health. But now this command is capped at entity's max health.

    Is there a way to change maximum health of the specific entity?
     
  2. Offline

    Nitnelave

    I don't know, but I guess if there is you'll have to get the craft Entity and figure out what variable that is, and change it...
     
  3. Offline

    DrBowe

    @matejdro

    I ran into this exact same issue with DeadMines, and the answer is yes. However, you need to dig deep into the dark magic of NMS code and Reflection. Here's a link to how I accomplished it (with @fullwall 's help)
    http://pastie.org/2957209

    Also, make sure you place this piece of code in your plugin and run it once (as a sort of initializer), otherwise the server won't recognize your custom entity:
    Code:java
    1.  
    2. Class<?>[] parameterTypes = {Class.class, String.class, int.class}; // reflection uses the parameter classes during the lookup process.
    3. Method method = EntityTypes.class.getDeclaredMethod("a", parameterTypes); // look up the method object using the class of EntityTypes.
    4. method.setAccessible(true); // since the method is private, we make sure we can access it.
    5. method.invoke(null, DeadMinesZombie.class, "Zombie", 54); //keep 1st parameter null, 2nd one should be your new entity class,
    6. // 3rd should be the name of whatever Entity you extended, and 4th should be the ID of said entity (you can find that on the MC wiki)
    7. }
    8.  
     
  4. Offline

    matejdro

    :O

    Will try it out. Thanks!

    Will that replace all other entities? For example in your case, normal zombies will still have normal health, right?

    Also, is this how you spawn entities?

    Code:java
    1. CBworld.addEntity(guard);
    2. guard.getBukkitEntity().teleport(guard.getLocation());


    (CBworld is net.minecraft.server.WorldServer, guard is cusotm mob class)

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

    Uniclaw

    A question.. How i spawn my new mob?
     
  6. Offline

    Nitnelave

    Create a new topic instead of reviving one that is a year old!
     
Thread Status:
Not open for further replies.

Share This Page