Register Custom Entity

Discussion in 'Spigot Plugin Development' started by xIceApple, Feb 12, 2019 at 2:04 PM.

  1. Hello Guys,

    i created a Custom-Entity-Class which i spawn with the following code:

    Summon:
    World w = ((CraftWorld) Bukkit.getWorld("world")).getHandle();
    CustomMob z = new CustomMob(w, p.getLocation());
    w.addEntity(z);

    After a restart the Entity is a normal Zombie (the Mob extends from a EntityZombie) which attacks Player(this is disabled in my CustomMob.class).
    Then i started to search and found this code:

    Register
    registerEntity("customzombie","zombie",CustomMob.class,CustomMob::new);

    Function-Code:

    Map<Object, Type<?>> types = (Map<Object, Type<?>>) DataConverterRegistry.a().getSchema(15190).findChoiceType(DataConverterTypes.n).types();
    types.put("minecraft:" + key, types.get("minecraft:" + extend));
    EntityTypes.a(key, EntityTypes.a.a(entityclass, function));

    Now, after a Restart the Zombie is despawned.

    CustomMob.class - Class::new functions
    public CustomMob(World world, Location loc) {
    super(world);
    setLocation(loc.getX(),loc.getY(),loc.getZ(),loc.getYaw(),loc.getPitch());
    }
    public CustomMob(World world) {
    super(world);
    }



    Please Help,
    ~ Apple
     
    #1 xIceApple, Feb 12, 2019 at 2:04 PM
    Last edited: Feb 12, 2019 at 6:53 PM
  2. Problem isnt solved yet.
    How can i fix that Problem?
     
  3. I don't see a question here. What are you seeking help with? Are you trying to keep the custom Zombies from despawning? If so, there are plenty of reasons they might disappear. You could try assigning names to the Zombies to give them priority, call setRemoveWhenFarAway(false) from the EntitySpawnEvent, and/or simply save your entities to a file onDisable and check whether they're present onEnable (and if not, respawn them).

    Also, please use code brackets for the sake of readability.
     
  4. Does your custom mob have a constructor with one parameter the world?
     
  5. @ysl3000

    public CustomMob(World world) {
    super(world);
    }


    Yeah, because the registerEntity() funtion needs it.

    @HappyPikachu i'll try the setRemoveWhenFarAway() funtion.
     
  6. You just need to register the entity in the mc registry material/EntityTypes in the onEnable method. setRemoveWhenFarAway will not solve the problem.

    Tip: use the code statement (+ button > code) to insert code
     
  7. @Il_totore
    Where i register that? I used this Method but after that and a restart the Entity is removed.

     
  8. Are you in 1.13 or + ?
     
  9. @Il_totore I'm using Spigot 1.13.2 (lastest) Build.
     
    #9 xIceApple, Feb 13, 2019 at 12:13 PM
    Last edited: Feb 13, 2019 at 12:27 PM
  10. @Il_totore Did you find something or know how i register that Entity?
     
  11. No. 1.13 remaked the EntityType registrring
     
    • Agree Agree x 1
    • Agree Agree x 1

Share This Page