Hostile custom mob wont spawn since 1.9

Discussion in 'Plugin Development' started by Lordloss, Mar 8, 2016.

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

    Lordloss

    Hey guys,

    i have trouble spawning my Custom Skeleton, which made no problems in Minecraft 1.8.
    The strange thing about this is, passive mobs work properly.

    On spawning there happens nothing, no errors.

    working CustomChicken: (removed unessessary code for debugging)
    Code:
    public class CustomChicken extends EntityChicken{
        public CustomChicken(org.bukkit.World world)
        {       
            super(((CraftWorld)world).getHandle());
        }
      
        public CustomChicken(World w)
        {
            super(w);
        }
    }
    not working CustomSkeleton:
    Code:
    public class CustomSkeleton extends EntitySkeleton{
         public CustomSkeleton(org.bukkit.World world)
        {       
          super(((CraftWorld)world).getHandle());
        }
      
        public CustomSkeleton(World w)
        {
            super(w);
        }
    the EntityTypes enum:
    Code:
    public enum EntityTypes {
    
        CUSTOM_CHICKEN("Chicken", 93, CustomChicken.class),
        CUSTOM_SKELETON("Skeleton", 51, CustomSkeleton.class);
    
        EntityTypes(String name, int id, Class<? extends Entity> custom) {
            addToMaps(custom, name, id);
        }
    
        public static CustomChicken spawnEntity(Entity entity, Location loc) {
            entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
            ((CraftWorld) loc.getWorld()).getHandle().addEntity(entity);
            return (CustomChicken) entity;
        }
       
    //made it just like the Chicken one for debugging, normally its a bit different
        public static CustomSkeleton spawnEntitySkel(Entity entity, Location loc) {
            entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
            ((CraftWorld) loc.getWorld()).getHandle().addEntity(entity);
            return (CustomSkeleton) entity;
        }
    (... get fields etc...)
    Every suggestion is greatly appreciated!

    Edit: btw, i tried multiple EntityTypes: Chicken, Pig, Sheep, Villager are working, Skeleton, Creeper, Spider etc. dont. Thats why i think hostile mobs make problems.
     
  2. Offline

    Zombie_Striker

    @Lordloss
    1. It looks like you're replacing all Skeletons with your custom entity. Is this what you want, are do you just want to be able to spawn your custom entities?
    2. 93 (id for your chicken) is not taken for any other base minecraft entity. 51 Is already taken by EntitySkeleton. You may want to change "51" to "94".
     
  3. Offline

    Lordloss

  4. Offline

    Zombie_Striker

    @Lordloss
    Then most likely this is either a bug or that they modified/added a new way to spawn in hostile mobs. Since the packets for spawning almost all entities require the same packet, the problem is with the API.
     
  5. Offline

    Lordloss

    @Zombie_Striker thats what i thought, i just hope that somebody can tell me whats wrong with it, im not the only one with custom mobs ;) i also tried EntityMonster instead of Entity, without success.
    But thanks for your help
     
  6. Offline

    Konato_K

    @Lordloss When registering custom entities like that you need to replace them in the NMS maps for the entities, are you sure the maps are still the same? Maybe there is now something new there or something changed and that's why they don't work properly.

    I don't have a 1.9 build so I can't see it for myself.
     
  7. Offline

    Lordloss

    This is the rest of the class:

    Klick (open)

    Code:
        private static void addToMaps(Class clazz, String name, int id)
        {
    
            ((Map)getPrivateField("c", net.minecraft.server.v1_9_R1.EntityTypes.class, null)).put(name, clazz);
            ((Map)getPrivateField("d", net.minecraft.server.v1_9_R1.EntityTypes.class, null)).put(clazz, name);
            ((Map)getPrivateField("e", net.minecraft.server.v1_9_R1.EntityTypes.class, null)).put(Integer.valueOf(id), clazz);
            ((Map)getPrivateField("f", net.minecraft.server.v1_9_R1.EntityTypes.class, null)).put(clazz, Integer.valueOf(id));
            ((Map)getPrivateField("g", net.minecraft.server.v1_9_R1.EntityTypes.class, null)).put(name, Integer.valueOf(id));
        }
      
        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 they made something different here, hopefully i would get an exception somewhere what is not the case. Again, please note that passive mobs are working. [pig] :confused:
     
  8. Offline

    Lordloss

    Anybody who knows whats going on?
     
Thread Status:
Not open for further replies.

Share This Page