Monster returning to normal

Discussion in 'Plugin Development' started by Jalau, Dec 29, 2013.

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

    Jalau

    So i have a few Custom NMS Classe where i actually create Monsters with Custom AIs (Zombies)...
    When i spawn them everything works fine but after a action that i haven't found out yet (probably server restart or chunk unloading) the mobs lose their custom ai and return to normal zombies but they still have their custom equipment and name? Does someone has an idea how to fix this glitch / bug?
     
  2. Offline

    Jogy34

    This probably occurs on on a server restart or reload. You have to declare your custom entity to the server in the onLoad() method of your main class.
     
  3. Offline

    Jalau

    That does mean? You mean register? Already is in onEnable(); Or am i wrong?
    Code:java
    1. registerMob(CustomZombie.class, "Zombie", 54);
    2. registerMob(CustomBowZombie.class, "Zombie", 54);
    3. registerMob(CustomIronGolem.class, "VillagerGolem", 99);
     
  4. Offline

    Jogy34

    Yes that. But again, that needs to be in the onLoad() method of your main class not in the onEnable() method.
     
  5. Offline

    Jalau

    there is a onLoad method? ;) :D Jogy34
     
  6. Offline

    Jogy34

    Yeah, It's like the onEnable() and onDisable() methods but it's called before any worlds are loaded and before the server completely starts up so that you can do things like that. What's happening is that you are registering your custom entities after the world loads so when the world loads it find them with a strange id and doesn't know what to make them so it turns them into normal entities.
     
  7. Offline

    Jalau

    Jogy34 Tested it, still happens? Tried to do that onEnable:
    for(Entity e : Bukkit.getWorld(main_world_name).getEntities()) {
    if(!e.hasMetadata("NPC"))
    e.remove();
    x++;
    }

    But that doesn't seem to kill all Entities? Any idea why? Because if this would work then i can simply respawn them onEnable ;)

    Here my Load code:
    Code:java
    1. @Override
    2. public void onLoad() {
    3. //Register Mobs
    4. registerMob(CustomZombie.class, "Zombie", 54);
    5. registerMob(CustomBowZombie.class, "Zombie", 54);
    6. registerMob(CustomIronGolem.class, "VillagerGolem", 99);
    7. }
    8.  
     
  8. Offline

    Jogy34

    What? You have to put the registerMob(//stuff...) calls in the onLoad() method of your main class.
     
  9. Offline

    Jalau

    @Jogy34 Yeah i did that, look at the post i edited it :D And i just tested it, it also happens when i switch servers (reconnect) so probably also chunk unload? Any idea?
     
  10. Offline

    Jogy34

    Change the string id to a custom one when registering them. So instead of using "Zombie" use "Zombie_Bow" or "Zombie_[PLUGIN_NAME]". I believe that's what the server reads to decide what type of entity to spawn so it would see that and think it should spawn a normal zombie. The number is what's sent to the clients to tell them what it looks like.
     
  11. Offline

    Jalau

    @Jorgy34
    Seems to work but they don't drop loot after a relog anymore... Do i need to change anything in my nms classes?
     
Thread Status:
Not open for further replies.

Share This Page