Solved Custom entity invisible after spawn 1.12.2

Discussion in 'Spigot Plugin Development' started by CuongVnZ, May 14, 2019.

  1. Hi there,
    I just created a custom entity class
    I register that entity by using the code below:
    Code (Java):
        public static void registerEntities() {

            for (EntityRegistrar entity : values()) {
                a(entity.getCustomClass(), entity.getName(), entity.getID());
                /*EntityTypes.b.a(entity.id, entity.key, entity.getCustomClass());
                if (!EntityTypes.d.contains(entity.key)) {
                    EntityTypes.d.add(entity.key);
                }*/

            }

            BiomeBase[] biomes;
            try {
                biomes = (BiomeBase[]) getPrivateStatic(BiomeBase.class, "biomes");
            } catch (Exception exc) {
                // Unable to fetch.
                return;
            }
            for (BiomeBase biomeBase : biomes) {
                if (biomeBase == null)
                    break;

                for (String field : new String[] { "t", "u", "v", "w" })
                    try {
                        Field list = BiomeBase.class.getDeclaredField(field);
                        list.setAccessible(true);
                        @SuppressWarnings("unchecked")
                        List<BiomeMeta> mobList = (List<BiomeMeta>) list.get(biomeBase);

                        for (BiomeMeta meta : mobList)
                            for (EntityRegistrar entity : values())
                                if (entity.getNMSClass().equals(meta.b))
                                    meta.b = entity.getCustomClass();
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
            }
        }
        private static void a(Class<?> paramClass, String paramString, int paramInt) {
            try {
                ((Map<String, Class<?>>) getPrivateStatic(EntityTypes.class, "c")).put(paramString, paramClass);
                ((Map<Class<?>, String>) getPrivateStatic(EntityTypes.class, "d")).put(paramClass, paramString);
                ((Map<Integer, Class<?>>) getPrivateStatic(EntityTypes.class, "e")).put(Integer.valueOf(paramInt), paramClass);
                ((Map<Class<?>, Integer>) getPrivateStatic(EntityTypes.class, "f")).put(paramClass, Integer.valueOf(paramInt));
                ((Map<String, Integer>) getPrivateStatic(EntityTypes.class, "g")).put(paramString, Integer.valueOf(paramInt));
            } catch (Exception exc) {
                // Unable to register the new class.
            }
        }
    /code]

    The console run fine, no error, but entity after spawned was invisible, i just heard their sound.
    Please help me
     
  2. ho do you solved it?