Posted January 12, 20214 yr 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); }
January 12, 20214 yr Author I spawned the mod with this code. Is this count as spawn eggs? entityType.spawn(spawnWorld,null,null,pos, SpawnReason.SPAWN_EGG,true,true);
January 12, 20214 yr Author 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);
January 12, 20214 yr Author 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, 20214 yr by Klarks
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.