BlockPredicate.java
net.minecraft.advancements.criterion.BlockPredicate
信息
- 全限定名:net.minecraft.advancements.criterion.BlockPredicate
- 类型:public record
- 包:net.minecraft.advancements.criterion
- 源码路径:src/main/java/net/minecraft/advancements/criterion/BlockPredicate.java
- 起始行号:L27
- 职责:
TODO
字段/常量
-
CODEC- 类型:
Codec<BlockPredicate> - 修饰符:
public static final - 源码定位:
L30 - 说明:
TODO
- 类型:
-
STREAM_CODEC- 类型:
StreamCodec<RegistryFriendlyByteBuf,BlockPredicate> - 修饰符:
public static final - 源码定位:
L39 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.advancements.criterion.BlockPredicate.Builder- 类型:
class - 修饰符:
public static - 源码定位:
L94 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
public boolean matches(ServerLevel level, BlockPos pos) @ L51
- 方法名:matches
- 源码定位:L51
- 返回类型:boolean
- 修饰符:public
参数:
- level: ServerLevel
- pos: BlockPos
说明:
TODO
public boolean matches(BlockInWorld blockInWorld) @ L72
- 方法名:matches
- 源码定位:L72
- 返回类型:boolean
- 修饰符:public
参数:
- blockInWorld: BlockInWorld
说明:
TODO
private boolean matchesState(BlockState state) @ L78
- 方法名:matchesState
- 源码定位:L78
- 返回类型:boolean
- 修饰符:private
参数:
- state: BlockState
说明:
TODO
private static boolean matchesBlockEntity(LevelReader level, BlockEntity entity, NbtPredicate nbt) @ L82
- 方法名:matchesBlockEntity
- 源码定位:L82
- 返回类型:boolean
- 修饰符:private static
参数:
- level: LevelReader
- entity: BlockEntity
- nbt: NbtPredicate
说明:
TODO
private static boolean matchesComponents(BlockEntity entity, DataComponentMatchers components) @ L86
- 方法名:matchesComponents
- 源码定位:L86
- 返回类型:boolean
- 修饰符:private static
参数:
- entity: BlockEntity
- components: DataComponentMatchers
说明:
TODO
public boolean requiresNbt() @ L90
- 方法名:requiresNbt
- 源码定位:L90
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public record BlockPredicate(
Optional<HolderSet<Block>> blocks, Optional<StatePropertiesPredicate> properties, Optional<NbtPredicate> nbt, DataComponentMatchers components
) {
public static final Codec<BlockPredicate> CODEC = RecordCodecBuilder.create(
i -> i.group(
RegistryCodecs.homogeneousList(Registries.BLOCK).optionalFieldOf("blocks").forGetter(BlockPredicate::blocks),
StatePropertiesPredicate.CODEC.optionalFieldOf("state").forGetter(BlockPredicate::properties),
NbtPredicate.CODEC.optionalFieldOf("nbt").forGetter(BlockPredicate::nbt),
DataComponentMatchers.CODEC.forGetter(BlockPredicate::components)
)
.apply(i, BlockPredicate::new)
);
public static final StreamCodec<RegistryFriendlyByteBuf, BlockPredicate> STREAM_CODEC = StreamCodec.composite(
ByteBufCodecs.optional(ByteBufCodecs.holderSet(Registries.BLOCK)),
BlockPredicate::blocks,
ByteBufCodecs.optional(StatePropertiesPredicate.STREAM_CODEC),
BlockPredicate::properties,
ByteBufCodecs.optional(NbtPredicate.STREAM_CODEC),
BlockPredicate::nbt,
DataComponentMatchers.STREAM_CODEC,
BlockPredicate::components,
BlockPredicate::new
);
public boolean matches(ServerLevel level, BlockPos pos) {
if (!level.isLoaded(pos)) {
return false;
} else if (!this.matchesState(level.getBlockState(pos))) {
return false;
} else {
if (this.nbt.isPresent() || !this.components.isEmpty()) {
BlockEntity blockEntity = level.getBlockEntity(pos);
if (this.nbt.isPresent() && !matchesBlockEntity(level, blockEntity, this.nbt.get())) {
return false;
}
if (!this.components.isEmpty() && !matchesComponents(blockEntity, this.components)) {
return false;
}
}
return true;
}
}
public boolean matches(BlockInWorld blockInWorld) {
return !this.matchesState(blockInWorld.getState())
? false
: !this.nbt.isPresent() || matchesBlockEntity(blockInWorld.getLevel(), blockInWorld.getEntity(), this.nbt.get());
}
private boolean matchesState(BlockState state) {
return this.blocks.isPresent() && !state.is(this.blocks.get()) ? false : !this.properties.isPresent() || this.properties.get().matches(state);
}
private static boolean matchesBlockEntity(LevelReader level, @Nullable BlockEntity entity, NbtPredicate nbt) {
return entity != null && nbt.matches(entity.saveWithFullMetadata(level.registryAccess()));
}
private static boolean matchesComponents(@Nullable BlockEntity entity, DataComponentMatchers components) {
return entity != null && components.test((DataComponentGetter)entity.collectComponents());
}
public boolean requiresNbt() {
return this.nbt.isPresent();
}
public static class Builder {
private Optional<HolderSet<Block>> blocks = Optional.empty();
private Optional<StatePropertiesPredicate> properties = Optional.empty();
private Optional<NbtPredicate> nbt = Optional.empty();
private DataComponentMatchers components = DataComponentMatchers.ANY;
private Builder() {
}
public static BlockPredicate.Builder block() {
return new BlockPredicate.Builder();
}
public BlockPredicate.Builder of(HolderGetter<Block> lookup, Block... blocks) {
return this.of(lookup, Arrays.asList(blocks));
}
public BlockPredicate.Builder of(HolderGetter<Block> lookup, Collection<Block> blocks) {
this.blocks = Optional.of(HolderSet.direct(Block::builtInRegistryHolder, blocks));
return this;
}
public BlockPredicate.Builder of(HolderGetter<Block> lookup, TagKey<Block> tag) {
this.blocks = Optional.of(lookup.getOrThrow(tag));
return this;
}
public BlockPredicate.Builder hasNbt(CompoundTag nbt) {
this.nbt = Optional.of(new NbtPredicate(nbt));
return this;
}
public BlockPredicate.Builder setProperties(StatePropertiesPredicate.Builder properties) {
this.properties = properties.build();
return this;
}
public BlockPredicate.Builder components(DataComponentMatchers components) {
this.components = components;
return this;
}
public BlockPredicate build() {
return new BlockPredicate(this.blocks, this.properties, this.nbt, this.components);
}
}
}引用的其他类
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/构造调用 - 关联成员:
NbtPredicate()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
HolderSet.direct()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
RegistryCodecs.homogeneousList()
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ByteBufCodecs.holderSet(), ByteBufCodecs.optional()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
StreamCodec.composite()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数
- 引用位置: