Skipping entity with id [id]

Discussion in 'Spigot Plugin Development' started by AdamAdam, Aug 2, 2018.

  1. Basiaclly. I'm working with custom entities and i've stumbled upon a problem where everytime a player connects he can't see the custom entities (in this case a silverfish) until another one gets summoned.
    When they connect I see this error "Skipping entity with id customsilverfish" (custom silverfish is my name for it) even thought it's registred.

    I'm on 1.8.8 spigot.
     
  2. Mycode for entity types:
    public enum EntityTypes
    {
    //NAME("Entity name", Entity ID, yourcustomclass.class);
    CUSTOMm_SILVERFISH("customsilverfish", 60, CustomSilverfish.class); //You can add as many as you want.

    private EntityTypes(String name, int id, Class<? extends Entity> custom)
    {
    addToMaps(custom, name, id);
    }

    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);
    }

    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;
    }


    private static void addToMaps(Class clazz, String name, int id)
    {
    //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_8_R3.EntityTypes.class, null)).put(name, clazz);
    ((Map)getPrivateField("d", net.minecraft.server.v1_8_R3.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_8_R3.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));
    }
    }
     
  3. You need to register the entity using the same registry name
     
  4. What do you mean?
     
  5. Do you mean Silverfish instead of "customsilverfish"?
     
  6. Yes. When you're overriding entities, you need all the same IDs for the client to see it.
     
  7. Oh, ok. Thanks!