minecraft-source/src/net/minecraft/world/level/EntityGetter.java

196 lines
8.9 KiB
Java

package net.minecraft.world.level;
import java.util.UUID;
import com.google.common.collect.Lists;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.ai.targeting.TargetingConditions;
import java.util.Iterator;
import java.util.function.Function;
import java.util.Objects;
import java.util.stream.Stream;
import java.util.Set;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.Shapes;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.entity.EntitySelector;
import net.minecraft.world.entity.player.Player;
import java.util.List;
import java.util.function.Predicate;
import net.minecraft.world.phys.AABB;
import javax.annotation.Nullable;
import net.minecraft.world.entity.Entity;
public interface EntityGetter {
List<Entity> getEntities(@Nullable final Entity akn, final AABB cvc, @Nullable final Predicate<? super Entity> predicate);
<T extends Entity> List<T> getEntitiesOfClass(final Class<? extends T> class1, final AABB cvc, @Nullable final Predicate<? super T> predicate);
default <T extends Entity> List<T> getLoadedEntitiesOfClass(final Class<? extends T> class1, final AABB cvc, @Nullable final Predicate<? super T> predicate) {
return this.getEntitiesOfClass(class1, cvc, predicate);
}
List<? extends Player> players();
default List<Entity> getEntities(@Nullable final Entity akn, final AABB cvc) {
return this.getEntities(akn, cvc, EntitySelector.NO_SPECTATORS);
}
default boolean isUnobstructed(@Nullable final Entity akn, final VoxelShape cwc) {
return cwc.isEmpty() || this.getEntities(akn, cwc.bounds()).stream().filter(akn2 -> !akn2.removed && akn2.blocksBuilding && (akn == null || !akn2.isPassengerOfSameVehicle(akn))).noneMatch(akn -> Shapes.joinIsNotEmpty(cwc, Shapes.create(akn.getBoundingBox()), BooleanOp.AND));
}
default <T extends Entity> List<T> getEntitiesOfClass(final Class<? extends T> class1, final AABB cvc) {
return this.<T>getEntitiesOfClass(class1, cvc, EntitySelector.NO_SPECTATORS);
}
default <T extends Entity> List<T> getLoadedEntitiesOfClass(final Class<? extends T> class1, final AABB cvc) {
return this.<T>getLoadedEntitiesOfClass(class1, cvc, EntitySelector.NO_SPECTATORS);
}
default Stream<VoxelShape> getEntityCollisions(@Nullable final Entity akn, final AABB cvc, final Set<Entity> set) {
if (cvc.getSize() < 1.0E-7) {
return Stream.<VoxelShape>empty();
}
final AABB cvc2 = cvc.inflate(1.0E-7);
return this.getEntities(akn, cvc2).stream().filter(akn -> !set.contains(akn)).filter(akn2 -> akn == null || !akn.isPassengerOfSameVehicle(akn2)).flatMap(akn2 -> Stream.<AABB>of(new AABB[] { akn2.getCollideBox(), (akn == null) ? null : akn.getCollideAgainstBox(akn2) })).filter(Objects::nonNull).filter(cvc2::intersects).<VoxelShape>map(Shapes::create);
}
@Nullable
default Player getNearestPlayer(final double double1, final double double2, final double double3, final double double4, @Nullable final Predicate<Entity> predicate) {
double double5 = -1.0;
Player ayg13 = null;
for (final Player ayg14 : this.players()) {
if (predicate != null && !predicate.test(ayg14)) {
continue;
}
final double double6 = ayg14.distanceToSqr(double1, double2, double3);
if ((double4 >= 0.0 && double6 >= double4 * double4) || (double5 != -1.0 && double6 >= double5)) {
continue;
}
double5 = double6;
ayg13 = ayg14;
}
return ayg13;
}
@Nullable
default Player getNearestPlayer(final Entity akn, final double double2) {
return this.getNearestPlayer(akn.getX(), akn.getY(), akn.getZ(), double2, false);
}
@Nullable
default Player getNearestPlayer(final double double1, final double double2, final double double3, final double double4, final boolean boolean5) {
final Predicate<Entity> predicate11 = boolean5 ? EntitySelector.NO_CREATIVE_OR_SPECTATOR : EntitySelector.NO_SPECTATORS;
return this.getNearestPlayer(double1, double2, double3, double4, predicate11);
}
@Nullable
default Player getNearestPlayerIgnoreY(final double double1, final double double2, final double double3) {
double double4 = -1.0;
Player ayg10 = null;
for (final Player ayg11 : this.players()) {
if (!EntitySelector.NO_SPECTATORS.test(ayg11)) {
continue;
}
final double double5 = ayg11.distanceToSqr(double1, ayg11.getY(), double2);
if ((double3 >= 0.0 && double5 >= double3 * double3) || (double4 != -1.0 && double5 >= double4)) {
continue;
}
double4 = double5;
ayg10 = ayg11;
}
return ayg10;
}
default boolean hasNearbyAlivePlayer(final double double1, final double double2, final double double3, final double double4) {
for (final Player ayg11 : this.players()) {
if (EntitySelector.NO_SPECTATORS.test(ayg11)) {
if (!EntitySelector.LIVING_ENTITY_STILL_ALIVE.test(ayg11)) {
continue;
}
final double double5 = ayg11.distanceToSqr(double1, double2, double3);
if (double4 < 0.0 || double5 < double4 * double4) {
return true;
}
continue;
}
}
return false;
}
@Nullable
default Player getNearestPlayer(final TargetingConditions ash, final LivingEntity akw) {
return this.<Player>getNearestEntity(this.players(), ash, akw, akw.getX(), akw.getY(), akw.getZ());
}
@Nullable
default Player getNearestPlayer(final TargetingConditions ash, final LivingEntity akw, final double double3, final double double4, final double double5) {
return this.<Player>getNearestEntity(this.players(), ash, akw, double3, double4, double5);
}
@Nullable
default Player getNearestPlayer(final TargetingConditions ash, final double double2, final double double3, final double double4) {
return this.<Player>getNearestEntity(this.players(), ash, (LivingEntity)null, double2, double3, double4);
}
@Nullable
default <T extends LivingEntity> T getNearestEntity(final Class<? extends T> class1, final TargetingConditions ash, @Nullable final LivingEntity akw, final double double4, final double double5, final double double6, final AABB cvc) {
return this.<T>getNearestEntity(this.getEntitiesOfClass(class1, cvc, null), ash, akw, double4, double5, double6);
}
@Nullable
default <T extends LivingEntity> T getNearestLoadedEntity(final Class<? extends T> class1, final TargetingConditions ash, @Nullable final LivingEntity akw, final double double4, final double double5, final double double6, final AABB cvc) {
return this.<T>getNearestEntity(this.getLoadedEntitiesOfClass(class1, cvc, null), ash, akw, double4, double5, double6);
}
@Nullable
default <T extends LivingEntity> T getNearestEntity(final List<? extends T> list, final TargetingConditions ash, @Nullable final LivingEntity akw, final double double4, final double double5, final double double6) {
double double7 = -1.0;
T akw2 = null;
for (final T akw3 : list) {
if (!ash.test(akw, akw3)) {
continue;
}
final double double8 = akw3.distanceToSqr(double4, double5, double6);
if (double7 != -1.0 && double8 >= double7) {
continue;
}
double7 = double8;
akw2 = akw3;
}
return akw2;
}
default List<Player> getNearbyPlayers(final TargetingConditions ash, final LivingEntity akw, final AABB cvc) {
final List<Player> list5 = Lists.newArrayList();
for (final Player ayg7 : this.players()) {
if (cvc.contains(ayg7.getX(), ayg7.getY(), ayg7.getZ()) && ash.test(akw, ayg7)) {
list5.add(ayg7);
}
}
return list5;
}
default <T extends LivingEntity> List<T> getNearbyEntities(final Class<? extends T> class1, final TargetingConditions ash, final LivingEntity akw, final AABB cvc) {
final List<T> list6 = this.<T>getEntitiesOfClass(class1, cvc, null);
final List<T> list7 = Lists.newArrayList();
for (final T akw2 : list6) {
if (ash.test(akw, akw2)) {
list7.add(akw2);
}
}
return list7;
}
@Nullable
default Player getPlayerByUUID(final UUID uUID) {
for (int integer3 = 0; integer3 < this.players().size(); ++integer3) {
final Player ayg4 = (Player)this.players().get(integer3);
if (uUID.equals(ayg4.getUUID())) {
return ayg4;
}
}
return null;
}
}