EntityPredicate.java
net.minecraft.advancements.criterion.EntityPredicate
信息
- 全限定名:net.minecraft.advancements.criterion.EntityPredicate
- 类型:public record
- 包:net.minecraft.advancements.criterion
- 源码路径:src/main/java/net/minecraft/advancements/criterion/EntityPredicate.java
- 起始行号:L28
- 职责:
TODO
字段/常量
-
CODEC- 类型:
Codec<EntityPredicate> - 修饰符:
public static final - 源码定位:
L46 - 说明:
TODO
- 类型:
-
ADVANCEMENT_CODEC- 类型:
Codec<ContextAwarePredicate> - 修饰符:
public static final - 源码定位:
L70 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.advancements.criterion.EntityPredicate.Builder- 类型:
class - 修饰符:
public static - 源码定位:
L176 - 说明:
TODO
- 类型:
-
net.minecraft.advancements.criterion.EntityPredicate.LocationWrapper- 类型:
record - 修饰符:
public - 源码定位:
L327 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static ContextAwarePredicate wrap(EntityPredicate.Builder singlePredicate) @ L72
- 方法名:wrap
- 源码定位:L72
- 返回类型:ContextAwarePredicate
- 修饰符:public static
参数:
- singlePredicate: EntityPredicate.Builder
说明:
TODO
public static Optional<ContextAwarePredicate> wrap(Optional<EntityPredicate> singlePredicate) @ L76
- 方法名:wrap
- 源码定位:L76
- 返回类型:Optional
- 修饰符:public static
参数:
- singlePredicate: Optional
说明:
TODO
public static List<ContextAwarePredicate> wrap(EntityPredicate.Builder... predicates) @ L80
- 方法名:wrap
- 源码定位:L80
- 返回类型:List
- 修饰符:public static
参数:
- predicates: EntityPredicate.Builder…
说明:
TODO
public static ContextAwarePredicate wrap(EntityPredicate singlePredicate) @ L84
- 方法名:wrap
- 源码定位:L84
- 返回类型:ContextAwarePredicate
- 修饰符:public static
参数:
- singlePredicate: EntityPredicate
说明:
TODO
public boolean matches(ServerPlayer player, Entity entity) @ L89
- 方法名:matches
- 源码定位:L89
- 返回类型:boolean
- 修饰符:public
参数:
- player: ServerPlayer
- entity: Entity
说明:
TODO
public boolean matches(ServerLevel level, Vec3 position, Entity entity) @ L93
- 方法名:matches
- 源码定位:L93
- 返回类型:boolean
- 修饰符:public
参数:
- level: ServerLevel
- position: Vec3
- entity: Entity
说明:
TODO
public static LootContext createContext(ServerPlayer player, Entity entity) @ L168
- 方法名:createContext
- 源码定位:L168
- 返回类型:LootContext
- 修饰符:public static
参数:
- player: ServerPlayer
- entity: Entity
说明:
TODO
代码
public record EntityPredicate(
Optional<EntityTypePredicate> entityType,
Optional<DistancePredicate> distanceToPlayer,
Optional<MovementPredicate> movement,
EntityPredicate.LocationWrapper location,
Optional<MobEffectsPredicate> effects,
Optional<NbtPredicate> nbt,
Optional<EntityFlagsPredicate> flags,
Optional<EntityEquipmentPredicate> equipment,
Optional<EntitySubPredicate> subPredicate,
Optional<Integer> periodicTick,
Optional<EntityPredicate> vehicle,
Optional<EntityPredicate> passenger,
Optional<EntityPredicate> targetedEntity,
Optional<String> team,
Optional<SlotsPredicate> slots,
DataComponentMatchers components
) {
public static final Codec<EntityPredicate> CODEC = Codec.recursive(
"EntityPredicate",
subCodec -> RecordCodecBuilder.create(
i -> i.group(
EntityTypePredicate.CODEC.optionalFieldOf("type").forGetter(EntityPredicate::entityType),
DistancePredicate.CODEC.optionalFieldOf("distance").forGetter(EntityPredicate::distanceToPlayer),
MovementPredicate.CODEC.optionalFieldOf("movement").forGetter(EntityPredicate::movement),
EntityPredicate.LocationWrapper.CODEC.forGetter(EntityPredicate::location),
MobEffectsPredicate.CODEC.optionalFieldOf("effects").forGetter(EntityPredicate::effects),
NbtPredicate.CODEC.optionalFieldOf("nbt").forGetter(EntityPredicate::nbt),
EntityFlagsPredicate.CODEC.optionalFieldOf("flags").forGetter(EntityPredicate::flags),
EntityEquipmentPredicate.CODEC.optionalFieldOf("equipment").forGetter(EntityPredicate::equipment),
EntitySubPredicate.CODEC.optionalFieldOf("type_specific").forGetter(EntityPredicate::subPredicate),
ExtraCodecs.POSITIVE_INT.optionalFieldOf("periodic_tick").forGetter(EntityPredicate::periodicTick),
subCodec.optionalFieldOf("vehicle").forGetter(EntityPredicate::vehicle),
subCodec.optionalFieldOf("passenger").forGetter(EntityPredicate::passenger),
subCodec.optionalFieldOf("targeted_entity").forGetter(EntityPredicate::targetedEntity),
Codec.STRING.optionalFieldOf("team").forGetter(EntityPredicate::team),
SlotsPredicate.CODEC.optionalFieldOf("slots").forGetter(EntityPredicate::slots),
DataComponentMatchers.CODEC.forGetter(EntityPredicate::components)
)
.apply(i, EntityPredicate::new)
)
);
public static final Codec<ContextAwarePredicate> ADVANCEMENT_CODEC = Codec.withAlternative(ContextAwarePredicate.CODEC, CODEC, EntityPredicate::wrap);
public static ContextAwarePredicate wrap(EntityPredicate.Builder singlePredicate) {
return wrap(singlePredicate.build());
}
public static Optional<ContextAwarePredicate> wrap(Optional<EntityPredicate> singlePredicate) {
return singlePredicate.map(EntityPredicate::wrap);
}
public static List<ContextAwarePredicate> wrap(EntityPredicate.Builder... predicates) {
return Stream.of(predicates).map(EntityPredicate::wrap).toList();
}
public static ContextAwarePredicate wrap(EntityPredicate singlePredicate) {
LootItemCondition asCondition = LootItemEntityPropertyCondition.hasProperties(LootContext.EntityTarget.THIS, singlePredicate).build();
return new ContextAwarePredicate(List.of(asCondition));
}
public boolean matches(ServerPlayer player, @Nullable Entity entity) {
return this.matches(player.level(), player.position(), entity);
}
public boolean matches(ServerLevel level, @Nullable Vec3 position, @Nullable Entity entity) {
if (entity == null) {
return false;
} else if (this.entityType.isPresent() && !this.entityType.get().matches(entity.typeHolder())) {
return false;
} else {
if (position == null) {
if (this.distanceToPlayer.isPresent()) {
return false;
}
} else if (this.distanceToPlayer.isPresent()
&& !this.distanceToPlayer.get().matches(position.x, position.y, position.z, entity.getX(), entity.getY(), entity.getZ())) {
return false;
}
if (this.movement.isPresent()) {
Vec3 knownMovement = entity.getKnownMovement();
Vec3 velocity = knownMovement.scale(20.0);
if (!this.movement.get().matches(velocity.x, velocity.y, velocity.z, entity.fallDistance)) {
return false;
}
}
if (this.location.located.isPresent() && !this.location.located.get().matches(level, entity.getX(), entity.getY(), entity.getZ())) {
return false;
} else {
if (this.location.steppingOn.isPresent()) {
Vec3 onPos = Vec3.atCenterOf(entity.getOnPos());
if (!entity.onGround() || !this.location.steppingOn.get().matches(level, onPos.x(), onPos.y(), onPos.z())) {
return false;
}
}
if (this.location.affectsMovement.isPresent()) {
Vec3 onPos = Vec3.atCenterOf(entity.getBlockPosBelowThatAffectsMyMovement());
if (!this.location.affectsMovement.get().matches(level, onPos.x(), onPos.y(), onPos.z())) {
return false;
}
}
if (this.effects.isPresent() && !this.effects.get().matches(entity)) {
return false;
} else if (this.flags.isPresent() && !this.flags.get().matches(entity)) {
return false;
} else if (this.equipment.isPresent() && !this.equipment.get().matches(entity)) {
return false;
} else if (this.subPredicate.isPresent() && !this.subPredicate.get().matches(entity, level, position)) {
return false;
} else if (this.vehicle.isPresent() && !this.vehicle.get().matches(level, position, entity.getVehicle())) {
return false;
} else if (this.passenger.isPresent() && entity.getPassengers().stream().noneMatch(p -> this.passenger.get().matches(level, position, p))) {
return false;
} else if (this.targetedEntity.isPresent()
&& !this.targetedEntity.get().matches(level, position, entity instanceof Mob ? ((Mob)entity).getTarget() : null)) {
return false;
} else if (this.periodicTick.isPresent() && entity.tickCount % this.periodicTick.get() != 0) {
return false;
} else {
if (this.team.isPresent()) {
Team team = entity.getTeam();
if (team == null || !this.team.get().equals(team.getName())) {
return false;
}
}
if (this.slots.isPresent() && !this.slots.get().matches(entity)) {
return false;
} else {
return !this.components.test((DataComponentGetter)entity) ? false : this.nbt.isEmpty() || this.nbt.get().matches(entity);
}
}
}
}
}
public static LootContext createContext(ServerPlayer player, Entity entity) {
LootParams lootParams = new LootParams.Builder(player.level())
.withParameter(LootContextParams.THIS_ENTITY, entity)
.withParameter(LootContextParams.ORIGIN, player.position())
.create(LootContextParamSets.ADVANCEMENT_ENTITY);
return new LootContext.Builder(lootParams).create(Optional.empty());
}
public static class Builder {
private Optional<EntityTypePredicate> entityType = Optional.empty();
private Optional<DistancePredicate> distanceToPlayer = Optional.empty();
private Optional<MovementPredicate> movement = Optional.empty();
private Optional<LocationPredicate> located = Optional.empty();
private Optional<LocationPredicate> steppingOnLocation = Optional.empty();
private Optional<LocationPredicate> movementAffectedBy = Optional.empty();
private Optional<MobEffectsPredicate> effects = Optional.empty();
private Optional<NbtPredicate> nbt = Optional.empty();
private Optional<EntityFlagsPredicate> flags = Optional.empty();
private Optional<EntityEquipmentPredicate> equipment = Optional.empty();
private Optional<EntitySubPredicate> subPredicate = Optional.empty();
private Optional<Integer> periodicTick = Optional.empty();
private Optional<EntityPredicate> vehicle = Optional.empty();
private Optional<EntityPredicate> passenger = Optional.empty();
private Optional<EntityPredicate> targetedEntity = Optional.empty();
private Optional<String> team = Optional.empty();
private Optional<SlotsPredicate> slots = Optional.empty();
private DataComponentMatchers components = DataComponentMatchers.ANY;
public static EntityPredicate.Builder entity() {
return new EntityPredicate.Builder();
}
public EntityPredicate.Builder of(HolderGetter<EntityType<?>> lookup, EntityType<?> entityType) {
this.entityType = Optional.of(EntityTypePredicate.of(lookup, entityType));
return this;
}
public EntityPredicate.Builder of(HolderGetter<EntityType<?>> lookup, TagKey<EntityType<?>> entityTypeTag) {
this.entityType = Optional.of(EntityTypePredicate.of(lookup, entityTypeTag));
return this;
}
public EntityPredicate.Builder entityType(EntityTypePredicate entityType) {
this.entityType = Optional.of(entityType);
return this;
}
public EntityPredicate.Builder distance(DistancePredicate distanceToPlayer) {
this.distanceToPlayer = Optional.of(distanceToPlayer);
return this;
}
public EntityPredicate.Builder moving(MovementPredicate movement) {
this.movement = Optional.of(movement);
return this;
}
public EntityPredicate.Builder located(LocationPredicate.Builder location) {
this.located = Optional.of(location.build());
return this;
}
public EntityPredicate.Builder steppingOn(LocationPredicate.Builder location) {
this.steppingOnLocation = Optional.of(location.build());
return this;
}
public EntityPredicate.Builder movementAffectedBy(LocationPredicate.Builder location) {
this.movementAffectedBy = Optional.of(location.build());
return this;
}
public EntityPredicate.Builder effects(MobEffectsPredicate.Builder effects) {
this.effects = effects.build();
return this;
}
public EntityPredicate.Builder nbt(NbtPredicate nbt) {
this.nbt = Optional.of(nbt);
return this;
}
public EntityPredicate.Builder flags(EntityFlagsPredicate.Builder flags) {
this.flags = Optional.of(flags.build());
return this;
}
public EntityPredicate.Builder equipment(EntityEquipmentPredicate.Builder equipment) {
this.equipment = Optional.of(equipment.build());
return this;
}
public EntityPredicate.Builder equipment(EntityEquipmentPredicate equipment) {
this.equipment = Optional.of(equipment);
return this;
}
public EntityPredicate.Builder subPredicate(EntitySubPredicate subPredicate) {
this.subPredicate = Optional.of(subPredicate);
return this;
}
public EntityPredicate.Builder periodicTick(int period) {
this.periodicTick = Optional.of(period);
return this;
}
public EntityPredicate.Builder vehicle(EntityPredicate.Builder vehicle) {
this.vehicle = Optional.of(vehicle.build());
return this;
}
public EntityPredicate.Builder passenger(EntityPredicate.Builder passenger) {
this.passenger = Optional.of(passenger.build());
return this;
}
public EntityPredicate.Builder targetedEntity(EntityPredicate.Builder targetedEntity) {
this.targetedEntity = Optional.of(targetedEntity.build());
return this;
}
public EntityPredicate.Builder team(String team) {
this.team = Optional.of(team);
return this;
}
public EntityPredicate.Builder slots(SlotsPredicate slots) {
this.slots = Optional.of(slots);
return this;
}
public EntityPredicate.Builder components(DataComponentMatchers components) {
this.components = components;
return this;
}
public EntityPredicate build() {
return new EntityPredicate(
this.entityType,
this.distanceToPlayer,
this.movement,
new EntityPredicate.LocationWrapper(this.located, this.steppingOnLocation, this.movementAffectedBy),
this.effects,
this.nbt,
this.flags,
this.equipment,
this.subPredicate,
this.periodicTick,
this.vehicle,
this.passenger,
this.targetedEntity,
this.team,
this.slots,
this.components
);
}
}
public record LocationWrapper(Optional<LocationPredicate> located, Optional<LocationPredicate> steppingOn, Optional<LocationPredicate> affectsMovement) {
public static final MapCodec<EntityPredicate.LocationWrapper> CODEC = RecordCodecBuilder.mapCodec(
i -> i.group(
LocationPredicate.CODEC.optionalFieldOf("location").forGetter(EntityPredicate.LocationWrapper::located),
LocationPredicate.CODEC.optionalFieldOf("stepping_on").forGetter(EntityPredicate.LocationWrapper::steppingOn),
LocationPredicate.CODEC.optionalFieldOf("movement_affected_by").forGetter(EntityPredicate.LocationWrapper::affectsMovement)
)
.apply(i, EntityPredicate.LocationWrapper::new)
);
}
}引用的其他类
-
- 引用位置:
字段/构造调用/返回值 - 关联成员:
ContextAwarePredicate()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
EntityTypePredicate.of()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用/构造调用/返回值 - 关联成员:
Builder(), LootContext.Builder()
- 引用位置:
-
- 引用位置:
方法调用/构造调用 - 关联成员:
Builder(), LootParams.Builder()
- 引用位置:
-
LootItemEntityPropertyCondition
- 引用位置:
方法调用 - 关联成员:
LootItemEntityPropertyCondition.hasProperties()
- 引用位置:
-
- 引用位置:
参数/方法调用 - 关联成员:
Vec3.atCenterOf()
- 引用位置: