LocationPredicate.java

net.minecraft.advancements.criterion.LocationPredicate

信息

  • 全限定名:net.minecraft.advancements.criterion.LocationPredicate
  • 类型:public record
  • 包:net.minecraft.advancements.criterion
  • 源码路径:src/main/java/net/minecraft/advancements/criterion/LocationPredicate.java
  • 起始行号:L18
  • 职责:

    TODO

字段/常量

  • CODEC
    • 类型: Codec<LocationPredicate>
    • 修饰符: public static final
    • 源码定位: L29
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.advancements.criterion.LocationPredicate.Builder

    • 类型: class
    • 修饰符: public static
    • 源码定位: L76
    • 说明:

      TODO

  • net.minecraft.advancements.criterion.LocationPredicate.PositionPredicate

    • 类型: record
    • 修饰符: private
    • 源码定位: L172
    • 说明:

      TODO

构造器

方法

下面的方法块按源码顺序生成。

public boolean matches(ServerLevel level, double x, double y, double z) @ L44

  • 方法名:matches
  • 源码定位:L44
  • 返回类型:boolean
  • 修饰符:public

参数:

  • level: ServerLevel
  • x: double
  • y: double
  • z: double

说明:

TODO

代码

public record LocationPredicate(
    Optional<LocationPredicate.PositionPredicate> position,
    Optional<HolderSet<Biome>> biomes,
    Optional<HolderSet<Structure>> structures,
    Optional<ResourceKey<Level>> dimension,
    Optional<Boolean> smokey,
    Optional<LightPredicate> light,
    Optional<BlockPredicate> block,
    Optional<FluidPredicate> fluid,
    Optional<Boolean> canSeeSky
) {
    public static final Codec<LocationPredicate> CODEC = RecordCodecBuilder.create(
        i -> i.group(
                LocationPredicate.PositionPredicate.CODEC.optionalFieldOf("position").forGetter(LocationPredicate::position),
                RegistryCodecs.homogeneousList(Registries.BIOME).optionalFieldOf("biomes").forGetter(LocationPredicate::biomes),
                RegistryCodecs.homogeneousList(Registries.STRUCTURE).optionalFieldOf("structures").forGetter(LocationPredicate::structures),
                ResourceKey.codec(Registries.DIMENSION).optionalFieldOf("dimension").forGetter(LocationPredicate::dimension),
                Codec.BOOL.optionalFieldOf("smokey").forGetter(LocationPredicate::smokey),
                LightPredicate.CODEC.optionalFieldOf("light").forGetter(LocationPredicate::light),
                BlockPredicate.CODEC.optionalFieldOf("block").forGetter(LocationPredicate::block),
                FluidPredicate.CODEC.optionalFieldOf("fluid").forGetter(LocationPredicate::fluid),
                Codec.BOOL.optionalFieldOf("can_see_sky").forGetter(LocationPredicate::canSeeSky)
            )
            .apply(i, LocationPredicate::new)
    );
 
    public boolean matches(ServerLevel level, double x, double y, double z) {
        if (this.position.isPresent() && !this.position.get().matches(x, y, z)) {
            return false;
        } else if (this.dimension.isPresent() && this.dimension.get() != level.dimension()) {
            return false;
        } else {
            BlockPos pos = BlockPos.containing(x, y, z);
            boolean loaded = level.isLoaded(pos);
            if (!this.biomes.isPresent() || loaded && this.biomes.get().contains(level.getBiome(pos))) {
                if (!this.structures.isPresent() || loaded && level.structureManager().getStructureWithPieceAt(pos, this.structures.get()).isValid()) {
                    if (!this.smokey.isPresent() || loaded && this.smokey.get() == CampfireBlock.isSmokeyPos(level, pos)) {
                        if (this.light.isPresent() && !this.light.get().matches(level, pos)) {
                            return false;
                        } else if (this.block.isPresent() && !this.block.get().matches(level, pos)) {
                            return false;
                        } else {
                            return this.fluid.isPresent() && !this.fluid.get().matches(level, pos)
                                ? false
                                : !this.canSeeSky.isPresent() || this.canSeeSky.get() == level.canSeeSky(pos);
                        }
                    } else {
                        return false;
                    }
                } else {
                    return false;
                }
            } else {
                return false;
            }
        }
    }
 
    public static class Builder {
        private MinMaxBounds.Doubles x = MinMaxBounds.Doubles.ANY;
        private MinMaxBounds.Doubles y = MinMaxBounds.Doubles.ANY;
        private MinMaxBounds.Doubles z = MinMaxBounds.Doubles.ANY;
        private Optional<HolderSet<Biome>> biomes = Optional.empty();
        private Optional<HolderSet<Structure>> structures = Optional.empty();
        private Optional<ResourceKey<Level>> dimension = Optional.empty();
        private Optional<Boolean> smokey = Optional.empty();
        private Optional<LightPredicate> light = Optional.empty();
        private Optional<BlockPredicate> block = Optional.empty();
        private Optional<FluidPredicate> fluid = Optional.empty();
        private Optional<Boolean> canSeeSky = Optional.empty();
 
        public static LocationPredicate.Builder location() {
            return new LocationPredicate.Builder();
        }
 
        public static LocationPredicate.Builder inBiome(Holder<Biome> biome) {
            return location().setBiomes(HolderSet.direct(biome));
        }
 
        public static LocationPredicate.Builder inDimension(ResourceKey<Level> dimension) {
            return location().setDimension(dimension);
        }
 
        public static LocationPredicate.Builder inStructure(Holder<Structure> structure) {
            return location().setStructures(HolderSet.direct(structure));
        }
 
        public static LocationPredicate.Builder atYLocation(MinMaxBounds.Doubles yLocation) {
            return location().setY(yLocation);
        }
 
        public LocationPredicate.Builder setX(MinMaxBounds.Doubles x) {
            this.x = x;
            return this;
        }
 
        public LocationPredicate.Builder setY(MinMaxBounds.Doubles y) {
            this.y = y;
            return this;
        }
 
        public LocationPredicate.Builder setZ(MinMaxBounds.Doubles z) {
            this.z = z;
            return this;
        }
 
        public LocationPredicate.Builder setBiomes(HolderSet<Biome> biomes) {
            this.biomes = Optional.of(biomes);
            return this;
        }
 
        public LocationPredicate.Builder setStructures(HolderSet<Structure> structures) {
            this.structures = Optional.of(structures);
            return this;
        }
 
        public LocationPredicate.Builder setDimension(ResourceKey<Level> dimension) {
            this.dimension = Optional.of(dimension);
            return this;
        }
 
        public LocationPredicate.Builder setLight(LightPredicate.Builder light) {
            this.light = Optional.of(light.build());
            return this;
        }
 
        public LocationPredicate.Builder setBlock(BlockPredicate.Builder block) {
            this.block = Optional.of(block.build());
            return this;
        }
 
        public LocationPredicate.Builder setFluid(FluidPredicate.Builder fluid) {
            this.fluid = Optional.of(fluid.build());
            return this;
        }
 
        public LocationPredicate.Builder setSmokey(boolean smokey) {
            this.smokey = Optional.of(smokey);
            return this;
        }
 
        public LocationPredicate.Builder setCanSeeSky(boolean canSeeSky) {
            this.canSeeSky = Optional.of(canSeeSky);
            return this;
        }
 
        public LocationPredicate build() {
            Optional<LocationPredicate.PositionPredicate> position = LocationPredicate.PositionPredicate.of(this.x, this.y, this.z);
            return new LocationPredicate(
                position, this.biomes, this.structures, this.dimension, this.smokey, this.light, this.block, this.fluid, this.canSeeSky
            );
        }
    }
 
    private record PositionPredicate(MinMaxBounds.Doubles x, MinMaxBounds.Doubles y, MinMaxBounds.Doubles z) {
        public static final Codec<LocationPredicate.PositionPredicate> CODEC = RecordCodecBuilder.create(
            i -> i.group(
                    MinMaxBounds.Doubles.CODEC.optionalFieldOf("x", MinMaxBounds.Doubles.ANY).forGetter(LocationPredicate.PositionPredicate::x),
                    MinMaxBounds.Doubles.CODEC.optionalFieldOf("y", MinMaxBounds.Doubles.ANY).forGetter(LocationPredicate.PositionPredicate::y),
                    MinMaxBounds.Doubles.CODEC.optionalFieldOf("z", MinMaxBounds.Doubles.ANY).forGetter(LocationPredicate.PositionPredicate::z)
                )
                .apply(i, LocationPredicate.PositionPredicate::new)
        );
 
        private static Optional<LocationPredicate.PositionPredicate> of(MinMaxBounds.Doubles x, MinMaxBounds.Doubles y, MinMaxBounds.Doubles z) {
            return x.isAny() && y.isAny() && z.isAny() ? Optional.empty() : Optional.of(new LocationPredicate.PositionPredicate(x, y, z));
        }
 
        public boolean matches(double x, double y, double z) {
            return this.x.matches(x) && this.y.matches(y) && this.z.matches(z);
        }
    }
}

引用的其他类

  • BlockPos

    • 引用位置: 方法调用
    • 关联成员: BlockPos.containing()
  • HolderSet

    • 引用位置: 方法调用
    • 关联成员: HolderSet.direct()
  • RegistryCodecs

    • 引用位置: 方法调用
    • 关联成员: RegistryCodecs.homogeneousList()
  • ResourceKey

    • 引用位置: 方法调用
    • 关联成员: ResourceKey.codec()
  • ServerLevel

    • 引用位置: 参数
  • CampfireBlock

    • 引用位置: 方法调用
    • 关联成员: CampfireBlock.isSmokeyPos()