#Event for naturally spawned villagers?

1 messages · Page 1 of 1 (latest)

inner pewter
#

Trying to add a custom name to both natural and egg-spawned villagers. CreatureSpawnEvent and EntitySpawnEvent seem to work for eggs, but not in new villages. Advice?

#
@EventHandler
    public void onCreatureSpawn(CreatureSpawnEvent event) {
        LivingEntity entity = event.getEntity();
        if (entity instanceof AbstractVillager) {
            entity.setCustomName("George");
            System.out.println("Named a villager creature George");
        }
    }

    @EventHandler
    public void onEntitySpawn(EntitySpawnEvent event) {
        Entity entity = event.getEntity();
        if (entity instanceof AbstractVillager) {
            entity.setCustomName("Carol");
            System.out.println("Named a villager entity Carol");
        }
    }
patent helm
#

just check the spawn reason and see if that fixes the issue?

#

Also try not to use System.out.println, just use your plugins logger

#

Little something like

@EventHandler
    public void onCreatureSpawn(CreatureSpawnEvent event) {
        if(event.getSpawnReason() == CreatureSpawnEvent.SpawnReason.NATURAL && event.getEntity() instanceof AbstractVillager) {
            event.getEntity().setCustomName("George");
            MAINCLASS.getPlugin(MAINCLASS.class).getLogger().info("Renamed a villager to George");
        }
    }```
inner pewter
#

Shouldn't the entity get named regardless of spawn reason? I'll try it, though.

#

And thanks, I'm aware about logger. Just not passing the plugin class atm.

inner pewter