Changing of mob display name

Hey guys, so I’ve spent the last like 4 days trying to figure out how to change the names of mobs when they spawn.

So currently in default Minecraft, mobs do not spawn with a Display Name for players to see, but in my plug I am trying to create custom mob names, but have yet to figure out the way of doing it with Sponge. I’m not sure if I am missing something or not, but does anyone know how to do it, if it is possible? Or is it not implemented yet?

I’m using the ConstructEntityEvent to decide when a mob spawns, and then I am using
getTargetType.getId.equals, to decide the kind of mob spawned, to customize the name from there.
I know I need to use getTargetEntity, but there isn’t a spawning event that I have found *unless I haven’t looked enough) that uses that, that is implemented yet.

Does anyone know how to help me resolve my issue? haha

hope can help you

@Listener
public void onSpawnEntity(SpawnEntityEvent e){
    for (Entity entity:e.getEntities()){
        if (entity instanceof Living){
            Living lv = (Living) entity;
            lv.offer(Keys.DISPLAY_NAME,Text.of("Buzz Lightyear"));
            if (lv.getType().equals(EntityTypes.ZOMBIE)){
               lv.offer(Keys.DISPLAY_NAME,Text.of("Zombie Buzz Lightyear"));
             }
            if (e.getCause().first(MobSpawner.class).isPresent()){
                lv.offer(Keys.DISPLAY_NAME,Text.of("Spawner Buzz Lightyear"));
                }
            }
        }
    }
1 Like