Solved 1.15.2 Spawn Entity(NMS) Error

Discussion in 'Spigot Plugin Development' started by inrh, Feb 20, 2020.

  1. If use world.addEntity it will have an error.
    I was troubled by this for about two hours.

    Code (error (Unknown Language)):

    [21:42:44 ERROR]: Attempted Double World add on FollowPet['Wolf'/62, uuid='70f0da2e-6551-4db4-a3d7-787fa07a82a9', l='world', x=-278.50, y=63.00, z=226.50, cx=-18, cz=14, tl=0, v=true, d=false]
    java.lang.Throwable: null
            at net.minecraft.server.v1_15_R1.WorldServer.addEntity0( ~[Paper-1.15.2-b90.jar:git-Paper-89]
            at net.minecraft.server.v1_15_R1.WorldServer.addEntity( ~[Paper-1.15.2-b90.jar:git-Paper-89]
    Code (Java):

    public static void registerEntity() {
        String customName = "custom_wolf";
        Map<String, Type<?>> types = (Map<String, Type<?>>) DataConverterRegistry.a()
        types.put("minecraft:" + customName, types.get("minecraft:wolf"));
        EntityTypes.a<Entity> a = EntityTypes.a.a(FollowPet::new, EnumCreatureType.MONSTER);
        entityTypes = IRegistry.a(IRegistry.ENTITY_TYPE, customName, a.a(customName));

    public static Wolf getWolf(Player player, Location location) {
        WorldServer world = ((CraftWorld) player.getWorld()).getHandle();
        Entity entity = entityTypes.spawnCreature(world,
                new BlockPosition(location.getX(), location.getY(), location.getZ()), EnumMobSpawn.EVENT,
        world.addEntity(entity, CreatureSpawnEvent.SpawnReason.CUSTOM);
        return  (Wolf) entity.getBukkitEntity();
    #1 inrh, Feb 20, 2020
    Last edited: Feb 20, 2020
  2. It's quite clear what the problem is
    Code (Text):
    [21:42:44 ERROR]: Attempted Double World add on FollowPet
    The entity is already added to the world. In other words, remove the line where you call World#addEntity
    • Agree Agree x 2
  3. I'm sorry, I'm not proficient in English, I don't understand it through machine translation. If this line is deleted, the entity will not be spawn.
    • Informative Informative x 1
  4. entityTypes.spawnEntity should spawn the entity just fine (pretty sure World#addEntity is used somewhere in there). Have you tested the plugin without that line?
    • Agree Agree x 2