use of org.spongepowered.common.bridge.world.entity.player.PlayerBridge in project SpongeCommon by SpongePowered.
the class MobMixin method impl$getClosestPlayerForSpawning.
@Nullable
@Redirect(method = "checkDespawn()V", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/level/Level;getNearestPlayer(Lnet/minecraft/world/entity/Entity;D)Lnet/minecraft/world/entity/player/Player;"))
private Player impl$getClosestPlayerForSpawning(final Level world, final net.minecraft.world.entity.Entity entityIn, final double distance) {
double bestDistance = -1.0D;
Player result = null;
for (final Player player : world.players()) {
if (player == null || player.removed || !((PlayerBridge) player).bridge$affectsSpawning()) {
continue;
}
final double playerDistance = player.distanceToSqr(entityIn);
if ((distance < 0.0D || playerDistance < distance * distance) && (bestDistance == -1.0D || playerDistance < bestDistance)) {
bestDistance = playerDistance;
result = player;
}
}
return result;
}
Aggregations