Solved Custom Entity Not Summoning

Discussion in 'Plugin Development' started by mine2012craft, Sep 10, 2017.

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

    mine2012craft

    Hello,

    So, currently I'm trying to make a custom Zombie following this tutorial: https://www.spigotmc.org/threads/tu...m-entities-with-pathfindergoals.18519/page-11

    Currently, I'm getting a null pointer whenever I try to summon it at this line:

    Code:
            ((Map)getPrivateField("c", net.minecraft.server.v1_12_R1.EntityTypes.class, null)).put(name, clazz);
    The code is in this class:

    Code:
    public enum EntityTypes
    {
        //NAME("Entity name", Entity ID, yourcustomclass.class);
        CUSTOM_ZOMBIE("Zombie", 54, CustomZombie.class); //You can add as many as you want.
    
        private EntityTypes(String name, int id, Class<? extends Entity> custom)
        {
            addToMaps(name, id,custom);
        }
    
      public static void spawnEntity(Entity entity, Location loc)
       {
          entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
         ((CraftWorld)loc.getWorld()).getHandle().addEntity(entity);
       }
    
        @SuppressWarnings({ "unchecked", "rawtypes" })
        private static void addToMaps(String name, int id, Class clazz)
        {
            Bukkit.broadcastMessage("" + ((Map)getPrivateField("c", net.minecraft.server.v1_12_R1.EntityTypes.class, null)));
            //getPrivateField is the method from above.
            //Remove the lines with // in front of them if you want to override default entities (You'd have to remove the default entity from the map first though).
            ((Map)getPrivateField("c", net.minecraft.server.v1_12_R1.EntityTypes.class, null)).put(name, clazz);
            ((Map)getPrivateField("d", net.minecraft.server.v1_12_R1.EntityTypes.class, null)).put(clazz, name);
            //((Map)getPrivateField("e", net.minecraft.server.v1_7_R4.EntityTypes.class, null)).put(Integer.valueOf(id), clazz);
            ((Map)getPrivateField("f", net.minecraft.server.v1_12_R1.EntityTypes.class, null)).put(clazz, Integer.valueOf(id));
            //((Map)getPrivateField("g", net.minecraft.server.v1_7_R4.EntityTypes.class, null)).put(name, Integer.valueOf(id));
        }
       
        @SuppressWarnings("rawtypes")
        public static Object getPrivateField(String fieldName, Class clazz, Object object)
        {
            Field field;
            Object o = null;
    
            try
            {
                field = clazz.getDeclaredField(fieldName);
    
                field.setAccessible(true);
    
                o = field.get(object);
            }
            catch(NoSuchFieldException e)
            {
                e.printStackTrace();
            }
            catch(IllegalAccessException e)
            {
                e.printStackTrace();
            }
    
            return o;
        }
       
    }
    If someone could tell help me out with this, it would be greatly appreciated.

    Thank you,
    WarlordWeaponry
     
  2. Offline

    travja

    It looks like you have imports for both 1.12.1 and 1.7.10. Which version is your server running in?
     
  3. Offline

    mine2012craft

    They are unused versions from the tutorial. Take a quick look at it also and you'll notice they're commented out.

    Also, I got it now, thank you.
     
Thread Status:
Not open for further replies.

Share This Page