ServerEntityGetter.java
net.minecraft.server.level.ServerEntityGetter
信息
- 全限定名:net.minecraft.server.level.ServerEntityGetter
- 类型:public interface
- 包:net.minecraft.server.level
- 源码路径:src/main/java/net/minecraft/server/level/ServerEntityGetter.java
- 起始行号:L14
- 继承:EntityGetter
- 职责:
TODO
字段/常量
- 无
内部类/嵌套类型
- 无
构造器
- 无
方法
下面的方法块按源码顺序生成。
ServerLevel getLevel() @ L15
- 方法名:getLevel
- 源码定位:L15
- 返回类型:ServerLevel
- 修饰符:package-private
参数:
- 无
说明:
TODO
default Player getNearestPlayer(TargetingConditions targetConditions, LivingEntity source) @ L17
- 方法名:getNearestPlayer
- 源码定位:L17
- 返回类型:Player
- 修饰符:default
参数:
- targetConditions: TargetingConditions
- source: LivingEntity
说明:
TODO
default Player getNearestPlayer(TargetingConditions targetConditions, LivingEntity source, double x, double y, double z) @ L21
- 方法名:getNearestPlayer
- 源码定位:L21
- 返回类型:Player
- 修饰符:default
参数:
- targetConditions: TargetingConditions
- source: LivingEntity
- x: double
- y: double
- z: double
说明:
TODO
default Player getNearestPlayer(TargetingConditions targetConditions, double x, double y, double z) @ L25
- 方法名:getNearestPlayer
- 源码定位:L25
- 返回类型:Player
- 修饰符:default
参数:
- targetConditions: TargetingConditions
- x: double
- y: double
- z: double
说明:
TODO
default <T extends LivingEntity> T getNearestEntity(Class<?extends T> type, TargetingConditions targetConditions, LivingEntity source, double x, double y, double z, AABB bb) @ L29
- 方法名:getNearestEntity
- 源码定位:L29
- 返回类型:
T - 修饰符:default
参数:
- type: Class<?extends T>
- targetConditions: TargetingConditions
- source: LivingEntity
- x: double
- y: double
- z: double
- bb: AABB
说明:
TODO
default LivingEntity getNearestEntity(TagKey<EntityType<?>> tag, TargetingConditions targetConditions, LivingEntity source, double x, double y, double z, AABB bb) @ L35
- 方法名:getNearestEntity
- 源码定位:L35
- 返回类型:LivingEntity
- 修饰符:default
参数:
- tag: TagKey<EntityType<?>>
- targetConditions: TargetingConditions
- source: LivingEntity
- x: double
- y: double
- z: double
- bb: AABB
说明:
TODO
default <T extends LivingEntity> T getNearestEntity(List<?extends T> entities, TargetingConditions targetConditions, LivingEntity source, double x, double y, double z) @ L54
- 方法名:getNearestEntity
- 源码定位:L54
- 返回类型:
T - 修饰符:default
参数:
- entities: List<?extends T>
- targetConditions: TargetingConditions
- source: LivingEntity
- x: double
- y: double
- z: double
说明:
TODO
default List<Player> getNearbyPlayers(TargetingConditions targetConditions, LivingEntity source, AABB bb) @ L73
- 方法名:getNearbyPlayers
- 源码定位:L73
- 返回类型:List
- 修饰符:default
参数:
- targetConditions: TargetingConditions
- source: LivingEntity
- bb: AABB
说明:
TODO
default <T extends LivingEntity> List<T> getNearbyEntities(Class<T> type, TargetingConditions targetConditions, LivingEntity source, AABB bb) @ L85
- 方法名:getNearbyEntities
- 源码定位:L85
- 返回类型:
List - 修饰符:default
参数:
- type: Class
- targetConditions: TargetingConditions
- source: LivingEntity
- bb: AABB
说明:
TODO
代码
public interface ServerEntityGetter extends EntityGetter {
ServerLevel getLevel();
default @Nullable Player getNearestPlayer(TargetingConditions targetConditions, LivingEntity source) {
return this.getNearestEntity(this.players(), targetConditions, source, source.getX(), source.getY(), source.getZ());
}
default @Nullable Player getNearestPlayer(TargetingConditions targetConditions, LivingEntity source, double x, double y, double z) {
return this.getNearestEntity(this.players(), targetConditions, source, x, y, z);
}
default @Nullable Player getNearestPlayer(TargetingConditions targetConditions, double x, double y, double z) {
return this.getNearestEntity(this.players(), targetConditions, null, x, y, z);
}
default <T extends LivingEntity> @Nullable T getNearestEntity(
Class<? extends T> type, TargetingConditions targetConditions, @Nullable LivingEntity source, double x, double y, double z, AABB bb
) {
return this.getNearestEntity(this.getEntitiesOfClass(type, bb, entity -> true), targetConditions, source, x, y, z);
}
default @Nullable LivingEntity getNearestEntity(
TagKey<EntityType<?>> tag, TargetingConditions targetConditions, @Nullable LivingEntity source, double x, double y, double z, AABB bb
) {
double bestDistance = Double.MAX_VALUE;
LivingEntity nearestEntity = null;
for (LivingEntity entity : this.getEntitiesOfClass(LivingEntity.class, bb, e -> e.is(tag))) {
if (targetConditions.test(this.getLevel(), source, entity)) {
double distance = entity.distanceToSqr(x, y, z);
if (distance < bestDistance) {
bestDistance = distance;
nearestEntity = entity;
}
}
}
return nearestEntity;
}
default <T extends LivingEntity> @Nullable T getNearestEntity(
List<? extends T> entities, TargetingConditions targetConditions, @Nullable LivingEntity source, double x, double y, double z
) {
double best = -1.0;
T result = null;
for (T entity : entities) {
if (targetConditions.test(this.getLevel(), source, entity)) {
double dist = entity.distanceToSqr(x, y, z);
if (best == -1.0 || dist < best) {
best = dist;
result = entity;
}
}
}
return result;
}
default List<Player> getNearbyPlayers(TargetingConditions targetConditions, LivingEntity source, AABB bb) {
List<Player> foundPlayers = new ArrayList<>();
for (Player player : this.players()) {
if (bb.contains(player.getX(), player.getY(), player.getZ()) && targetConditions.test(this.getLevel(), source, player)) {
foundPlayers.add(player);
}
}
return foundPlayers;
}
default <T extends LivingEntity> List<T> getNearbyEntities(Class<T> type, TargetingConditions targetConditions, LivingEntity source, AABB bb) {
List<T> nearby = this.getEntitiesOfClass(type, bb, entityx -> true);
List<T> entities = new ArrayList<>();
for (T entity : nearby) {
if (targetConditions.test(this.getLevel(), source, entity)) {
entities.add(entity);
}
}
return entities;
}
}引用的其他类
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
继承
- 引用位置:
-
- 引用位置:
参数
- 引用位置: