Search in sources :

Example 1 with PlayerBridge

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;
}
Also used : Player(net.minecraft.world.entity.player.Player) PlayerBridge(org.spongepowered.common.bridge.world.entity.player.PlayerBridge) Redirect(org.spongepowered.asm.mixin.injection.Redirect) Nullable(javax.annotation.Nullable)

Aggregations

Nullable (javax.annotation.Nullable)1 Player (net.minecraft.world.entity.player.Player)1 Redirect (org.spongepowered.asm.mixin.injection.Redirect)1 PlayerBridge (org.spongepowered.common.bridge.world.entity.player.PlayerBridge)1