Custom NMS Entity Issue

Discussion in 'Plugin Development' started by Joshuaknight1998, Jul 5, 2015.

Thread Status:
Not open for further replies.
  1. I've been learning & messing around with making a NMS Skeleton to spawn when I type my command. My issue is that the Skeleton's(my custom one) "custom aspect" are applied to any spawned Skeleton, whether it be my command-spawned Skeleton or one straight from a spawn egg. I feel as if when registering my entities, it's somehow overriding the default Minecraft Skeleton, but I'm not really sure how to fix it.

    If I wasn't really clear, I want my "PetSkeleton" to be spawned with commands, and regular Skeletons to be spawned as they normally would. At the moment, "PetSkeleton" overrides all vanilla aspects of the Skeleton's behavior. Anyone know how to fix this or could give some pointers? Thanks!

    Registering Entities:
    Code:
            try {
    
                List<Map<?, ?>> dataMaps = new ArrayList<Map<?, ?>>();
                for (Field f : EntityTypes.class.getDeclaredFields()) {
                    if (f.getType().getSimpleName().equals(Map.class.getSimpleName())) {
                        f.setAccessible(true);
                        dataMaps.add((Map<?, ?>) f.get(null));
                    }
                }
    
                if (dataMaps.get(2).containsKey(id)) {
                    dataMaps.get(0).remove(name);
                    dataMaps.get(2).remove(id);
                }
    
                Method method = EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, int.class);
                method.setAccessible(true);
                method.invoke(null, customClass, name, id);
    
            } catch (Exception e) {
                e.printStackTrace();
            }
    
    And I register my entity in onEnable() as follows:
    Code:
            nms.registerEntity("Skeleton", 51, EntitySkeleton.class, PetSkeleton.class);
    
     
  2. Offline

    mine-care

    @Joshuaknight1998 i tink its because you register it as an entity overriding the previus one.
    I dont really think you need the the onEnable registration but i am not the NMS entities specialist so i may be talking butterflies xD
     
  3. Offline

    WesJD

    @Joshuaknight1998 Use reflection and call a in EntityTypes to register your entity.
     
  4. @WesJD I am =[ . That's the three "Method" lines in my code :/
     
  5. Offline

    WesJD

    @Joshuaknight1998 Try changing the name to something other than Skeleton(i.e. My Skeleton).

    Remove this:
    Code:
                List<Map<?, ?>> dataMaps = new ArrayList<Map<?, ?>>();
                for (Field f : EntityTypes.class.getDeclaredFields()) {
                    if (f.getType().getSimpleName().equals(Map.class.getSimpleName())) {
                        f.setAccessible(true);
                        dataMaps.add((Map<?, ?>) f.get(null));
                    }
                }
    
                if (dataMaps.get(2).containsKey(id)) {
                    dataMaps.get(0).remove(name);
                    dataMaps.get(2).remove(id);
                }
    
     
  6. @WesJD Hey, sorry but that didn't fix it :/. I continuously get the stacktrace in console stating that the ID has already been registered, whether it be 51, 200, or even 991. I have no clue what I could be doing wrong, but I believe I have to register this entity if I ever plan on it spawning via commands :[ . Thanks for your help so far, though.
     
  7. Any insight? I still haven't been able to find a fix.
     
  8. @Joshuaknight1998
    Maybe you need to register the entity with a name besides "Skeleton", I wouldn't really now though.

    On a side note, what are the question marks in "List<Map<?, ?>> dataMaps = new ArrayList<Map<?, ?>>();" for?
     
Thread Status:
Not open for further replies.

Share This Page