98 lines
3.8 KiB
Java
98 lines
3.8 KiB
Java
package net.minecraft.world.entity;
|
|
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.item.ItemStack;
|
|
import net.minecraft.world.Container;
|
|
import net.minecraft.world.entity.player.Player;
|
|
import com.google.common.base.Predicates;
|
|
import net.minecraft.world.scores.Team;
|
|
import java.util.function.Predicate;
|
|
|
|
public final class EntitySelector {
|
|
public static final Predicate<Entity> ENTITY_STILL_ALIVE;
|
|
public static final Predicate<LivingEntity> LIVING_ENTITY_STILL_ALIVE;
|
|
public static final Predicate<Entity> ENTITY_NOT_BEING_RIDDEN;
|
|
public static final Predicate<Entity> CONTAINER_ENTITY_SELECTOR;
|
|
public static final Predicate<Entity> NO_CREATIVE_OR_SPECTATOR;
|
|
public static final Predicate<Entity> NO_SPECTATORS;
|
|
|
|
public static Predicate<Entity> withinDistance(final double double1, final double double2, final double double3, final double double4) {
|
|
final double double5 = double4 * double4;
|
|
final double n;
|
|
return akn -> akn != null && akn.distanceToSqr(double1, double2, double3) <= n;
|
|
}
|
|
|
|
public static Predicate<Entity> pushableBy(final Entity akn) {
|
|
final Team cwk2 = akn.getTeam();
|
|
final Team.CollisionRule a3 = (cwk2 == null) ? Team.CollisionRule.ALWAYS : cwk2.getCollisionRule();
|
|
if (a3 == Team.CollisionRule.NEVER) {
|
|
return Predicates.alwaysFalse();
|
|
}
|
|
Team cwk3;
|
|
Team.CollisionRule a4;
|
|
final Team team;
|
|
boolean boolean7;
|
|
final Team.CollisionRule collisionRule;
|
|
return EntitySelector.NO_SPECTATORS.and(akn4 -> {
|
|
if (!akn4.isPushable()) {
|
|
return false;
|
|
}
|
|
else if (akn.level.isClientSide && (!(akn4 instanceof Player) || !akn4.isLocalPlayer())) {
|
|
return false;
|
|
}
|
|
else {
|
|
cwk3 = akn4.getTeam();
|
|
a4 = ((cwk3 == null) ? Team.CollisionRule.ALWAYS : cwk3.getCollisionRule());
|
|
if (a4 == Team.CollisionRule.NEVER) {
|
|
return false;
|
|
}
|
|
else {
|
|
boolean7 = (team != null && team.isAlliedTo(cwk3));
|
|
return ((collisionRule != Team.CollisionRule.PUSH_OWN_TEAM && a4 != Team.CollisionRule.PUSH_OWN_TEAM) || !boolean7) && ((collisionRule != Team.CollisionRule.PUSH_OTHER_TEAMS && a4 != Team.CollisionRule.PUSH_OTHER_TEAMS) || boolean7);
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
public static Predicate<Entity> notRiding(final Entity akn) {
|
|
return akn2 -> {
|
|
while (akn2.isPassenger()) {
|
|
akn2 = akn2.getVehicle();
|
|
if (akn2 == akn) {
|
|
return false;
|
|
}
|
|
}
|
|
return true;
|
|
};
|
|
}
|
|
|
|
static {
|
|
ENTITY_STILL_ALIVE = Entity::isAlive;
|
|
LIVING_ENTITY_STILL_ALIVE = LivingEntity::isAlive;
|
|
ENTITY_NOT_BEING_RIDDEN = (akn -> akn.isAlive() && !akn.isVehicle() && !akn.isPassenger());
|
|
CONTAINER_ENTITY_SELECTOR = (akn -> akn instanceof Container && akn.isAlive());
|
|
NO_CREATIVE_OR_SPECTATOR = (akn -> !(akn instanceof Player) || (!akn.isSpectator() && !akn.isCreative()));
|
|
NO_SPECTATORS = (akn -> !akn.isSpectator());
|
|
}
|
|
|
|
public static class MobCanWearArmourEntitySelector implements Predicate<Entity> {
|
|
private final ItemStack itemStack;
|
|
|
|
public MobCanWearArmourEntitySelector(final ItemStack bek) {
|
|
this.itemStack = bek;
|
|
}
|
|
|
|
@Override
|
|
public boolean test(@Nullable final Entity akn) {
|
|
if (!akn.isAlive()) {
|
|
return false;
|
|
}
|
|
if (!(akn instanceof LivingEntity)) {
|
|
return false;
|
|
}
|
|
final LivingEntity akw3 = (LivingEntity)akn;
|
|
return akw3.canTakeItem(this.itemStack);
|
|
}
|
|
}
|
|
}
|