Solved NMS Custom mob

Discussion in 'Plugin Development' started by Wantsome909, Jan 30, 2017.

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

    Wantsome909

    Here is my Util:

    Code:
        public void registerEntity(String name, int id, Class<? extends EntityInsentient> nmsClass, Class<? extends EntityInsentient> customClass){
            try{
                List<Map<?, ?>> dataMap = new ArrayList<Map<?, ?>>();
                for(Field f: net.minecraft.server.v1_11_R1.EntityTypes.class.getDeclaredFields()){
                    if(f.getType().getSimpleName().equals(Map.class.getSimpleName())){
                        f.setAccessible(true);
                        dataMap.add((Map<?, ?>) f.get(null));
                    }
                }
                if(dataMap.get(2).containsKey(id)){
                    dataMap.get(0).remove(name);
                    dataMap.get(2).remove(id);
                }
                Method method = net.minecraft.server.v1_11_R1.EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, int.class);
                method.setAccessible(true);
                method.invoke(null, customClass, name, id);
            }catch(Exception e){
                e.printStackTrace();
            }
        }

    Heres my Custom Zombie class:

    Code:
    package Monster;
    
    import net.minecraft.server.v1_11_R1.EntityZombie;
    import net.minecraft.server.v1_11_R1.GenericAttributes;
    import net.minecraft.server.v1_11_R1.World;
    
    /**
    * Created by christian on 1/30/2017.
    */
    public class CustomZombie extends EntityZombie {
    
        public CustomZombie(World world){
            super(world);
        }
    
        protected void initAttributes(){
            super.initAttributes();
            this.getAttributeInstance(GenericAttributes.ATTACK_DAMAGE).setValue(10.0D);
            this.getAttributeInstance(GenericAttributes.maxHealth).setValue(100.0D);
            this.getAttributeInstance(GenericAttributes.MOVEMENT_SPEED).setValue(1.0D);
        }
    
    }
    This is how i spawn it:

    Code:
    public class EntityTypes {
    
        public static CustomZombie spawnCustomZombie(CustomZombie entity, Location loc) {
            entity.setLocation(loc.getX(), loc.getY(), loc.getZ(), loc.getYaw(), loc.getPitch());
            ((CraftWorld)loc.getWorld()).getHandle().addEntity(entity, CreatureSpawnEvent.SpawnReason.NATURAL);
            return entity;
        }
    
    }
    My question is?: when i spawn the zombie its invisible. i can hear it and damage it but i cant see it.
     
  2. Offline

    Wantsome909

    Times close enough. bump...

    Anyone please help.

    EDIT by Moderator: merged posts, please use the edit button instead of double posting.
     
    Last edited by a moderator: Feb 1, 2017
  3. Offline

    Drkmaster83

    I could be wrong, but the first class is never used to register the Entity with the world. Perhaps using it would help, but I think there also might be something wrong it with it.
    Code:
    Method method = net.minecraft.server.v1_11_R1.EntityTypes.class.getDeclaredMethod("a", Class.class, String.class, int.class);
                method.setAccessible(true);
                method.invoke(null, customClass, name, id);
    
    You create a reflected method and invoke it, but I believe you'd need to invoke that on the zombie object... additionally, the way you're getting the declared method, instead of Class.class, it should be customClass.class.
    I could be wrong, just my input on the portion.
    I assumed, also, that the first portion of code is in a separate class than the CustomZombie.
     
  4. Offline

    Wantsome909

    @Drkmaster83 still the zombie is invisible. I'm so confused why he is invisible. i tried so many different methods and nothing has worked
     
  5. Offline

    Wantsome909

    Thanks for the help @Drkmaster83. i got it to work. Thanks.
     
  6. Offline

    Drkmaster83

    What was the solution? I'm asking because I couldn't figure it out myself, and the problem was reproducible
     
Thread Status:
Not open for further replies.

Share This Page