Solved Custom non-insentient entities

Discussion in 'Spigot Plugin Development' started by MartinStone, Apr 22, 2017.

  1. Hey, I am trying to make custom projectiles and non-insentient entities so I can use the NMS classes of them to handle collisions, particle trails and such. I choose this because I figured that making a scheduler to track every normal entity created under certain conditions and apply said custom conditions might be more costly than to use it's default methods.

    The problem I run into is when registering the class to the server. I've tried using the default enity register, accessing the list register directly and adding the entity, using a custom register, etc. In all the attempts I get the same error with the stack trace beign from when I spawn the entity.

    The entity I am using (ProjectileBeam) extends the EntityEnderpearl, class because I hear it needs to extend the class which looks it mimics, also tried with EntitySnowball and EntityProjectile and Entity aswell with the same results.

    Code (Text):
    Caused by: java.lang.AssertionError: Unknown entity class <class_path>.ProjectileBeam.class
    The methods I used for registering are the following:

    Accessing the store of EntityTypes.class directly:
    Code (Text):
    public static void patch() {
            EntityTypes.b.a(11, new MinecraftKey("projectile_beam"), ProjectileBeam.class);
    Using the default register method:
    Code (Text):
    EntityTypes.class.getDeclaredMethod("a", int.class, String.class, Class.class, String.class)
                    .invoke(null, 11, "projectile_beam", ProjectileBeam.class, "ProjectileBeam");
    Accessing the store of EntityTypes.class and doing the same as the default register:
    Code (Text):
        public static void registerEntity(String name, int id, Class<? extends Entity> customClass) {
            MinecraftKey key = new MinecraftKey(name);
            try {
                ((RegistryMaterials) getPrivateStatic(EntityTypes.class, "b")).a(id, key, customClass);
                ((Set) getPrivateStatic(EntityTypes.class, "d")).add(key);
                ((List) getPrivateStatic(EntityTypes.class, "g")).set(id, name);
            } catch (Exception e) {

    Any help as if this can be done would be great. Or maybe advice on how to add behavior to entities that are going to be spawned constantly without having to use multiple tracking threads. Thanks
  2. Bumping, I haven't found anything on the web so far.
  3. sothatsit


    Don't bump your thread within less than 24 hours.

    Have you tried without trying to register your custom projectile? Non-insentient entities shouldn't have to be registered. Also, the error is fairly useless without its stack trace.

    Additionally, in your spawning code:
    Code (Text):
    CraftWorld handle = (CraftWorld) p.getWorld();
    ProjectileBeam beam = new ProjectileBeam(handle.getHandle(),((CraftLivingEntity) p).getHandle());
    handle.getHandle().addEntity(beam, CreatureSpawnEvent.SpawnReason.CUSTOM);
    beam.setPosition(p.getEyeLocation().getBlockX(), p.getEyeLocation().getBlockY(), p.getEyeLocation().getBlockZ());
    The position should be set before you add the entity, or it will likely not work.
    • Like Like x 1
  4. That's it I didn't need to register the entity. Thank you I didn't even try that.

    If you wouldn't mind do you know how an Entity is asigned it's look?. Is it based on class name?. Because I have discovered all projectiles and fireballs have this method that calls a super from Entity containing a name identifier, however in Entity and EntityProjectile it's an empty method.

    Code (Text):
        public static void a(DataConverterManager dataconvertermanager) {
            EntityProjectile.a(dataconvertermanager, "Snowball");
    Or is the texture of the entity related to something else. Thanks alot
  5. sothatsit


    If you just extend the one you want to look like it will take care of it for you, however it is done.