Klarks Posted January 12, 2021 Share Posted January 12, 2021 How can i get the player who spawned the mob. Is it would be correct to find a player by distance like this. it is wotking but is it correct? @Override public ILivingEntityData onInitialSpawn(IServerWorld worldIn, DifficultyInstance difficultyIn, SpawnReason reason, @Nullable ILivingEntityData spawnDataIn, @Nullable CompoundNBT dataTag) { float dist = 999999999; int pl = 0; if (reason == SpawnReason.COMMAND || reason == SpawnReason.SPAWN_EGG || reason == SpawnReason.SPAWNER || reason == SpawnReason.DISPENSER) { List<ServerPlayerEntity> players = worldIn.getWorld().getPlayers(); for(int i = 0;i < players.size();i++) { if ( dist > this.getDistance(players.get(i))) { dist = this.getDistance(players.get(i)); pl = i; } } this.setCustomName(new TranslationTextComponent(players.get(pl).getScoreboardName())); } return super.onInitialSpawn(worldIn, difficultyIn, reason, spawnDataIn, dataTag); } Quote Link to comment Share on other sites More sharing options...
Klarks Posted January 12, 2021 Author Share Posted January 12, 2021 I spawned the mod with this code. Is this count as spawn eggs? entityType.spawn(spawnWorld,null,null,pos, SpawnReason.SPAWN_EGG,true,true); Quote Link to comment Share on other sites More sharing options...
Klarks Posted January 12, 2021 Author Share Posted January 12, 2021 Like this ? ItemStack is = new ItemStack(null); is.setDisplayName(new TranslationTextComponent(ctx.get().getSender().getScoreboardName())); entityType.spawn(spawnWorld,is,null,pos, SpawnReason.SPAWN_EGG,true,true); Quote Link to comment Share on other sites More sharing options...
Klarks Posted January 12, 2021 Author Share Posted January 12, 2021 (edited) like this? Entity e = entityType.spawn(spawnWorld,null,null,pos, SpawnReason.SPAWN_EGG,true,true); e.setCustomName(new TranslationTextComponent(ctx.get().getSender().getScoreboardName())); Edited January 12, 2021 by Klarks Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.