Solved Entities spawned with eggs are copying custom entity properties

Discussion in 'Spigot Plugin Development' started by Mykindos, May 20, 2016.

  1. This is for spigot 1.9.2

    Alright, so to put in simple terms. I have created a bunch of custom entities using NMS, and given them pathfindergoals so they can't move, etc. However, everytime I spawn a mob using the corresponding mob egg, it will copy the pathfindergoals of my custom entity, making it undamageable, unable to move, and has no sound, etc.

    This doesn't just happen with egg spawned entities either, I've found sometimes that after chunks unload and load again (not 100% on this), that the entities also gain the same properties.

    TL;DR, I want only entities that I spawn with my command to be given these properties, no exceptions.

    Code (Text):
    public static void registerEntity(String name, int id, Class<? extends EntityInsentient> nmsClass, Class<? extends EntityInsentient> customClass){
            try {
                List<Map<?, ?>> dataMap = new ArrayList<Map<?, ?>>();
                for (Field f : EntityTypes.class.getDeclaredFields()){
                    if (f.getType().getSimpleName().equals(Map.class.getSimpleName())){
                        dataMap.add((Map<?, ?>) f.get(null));
                if (dataMap.get(2).containsKey(id)){
                Method method = EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, int.class);
                method.invoke(null, customClass, name, id);
            } catch (Exception e) {

    Spawning the entity (with a command)
    Code (Text):
    ShopZombie wz = new ShopZombie(((CraftWorld) loc.getWorld()).getHandle());
                        Zombie weapons = wz.spawn(loc);
    Any insight is appreciated, I have tried a lot of things.

    Thanks :)
    #1 Mykindos, May 20, 2016
    Last edited: May 20, 2016
  2. Common sense .-.. If you override everything that converts ids/names to your entity, of course it overrides the other entities. You need to only put the values in the maps that save the entity to, for example, a String or ID. Use a decompiler to find which maps you need
    • Like Like x 1
  3. Wouldn't it already be affecting all entities then? Even if they are spawned naturally of by a spawner?
  4. @TommyHoogstra no, because they are spawned by using an entity's constructor
    • Like Like x 1
  5. @megamichiel figured it out, it sucks that theres no documentation on this kind of stuff, it ended up getting it working with the map that was Class and ID, ill post back if any issues arise from this