DataComponentExactPredicate.java
net.minecraft.core.component.DataComponentExactPredicate
信息
- 全限定名:net.minecraft.core.component.DataComponentExactPredicate
- 类型:public final class
- 包:net.minecraft.core.component
- 源码路径:src/main/java/net/minecraft/core/component/DataComponentExactPredicate.java
- 起始行号:L14
- 实现:Predicate
- 职责:
TODO
字段/常量
-
CODEC- 类型:
Codec<DataComponentExactPredicate> - 修饰符:
public static final - 源码定位:
L15 - 说明:
TODO
- 类型:
-
STREAM_CODEC- 类型:
StreamCodec<RegistryFriendlyByteBuf,DataComponentExactPredicate> - 修饰符:
public static final - 源码定位:
L23 - 说明:
TODO
- 类型:
-
EMPTY- 类型:
DataComponentExactPredicate - 修饰符:
public static final - 源码定位:
L26 - 说明:
TODO
- 类型:
-
expectedComponents- 类型:
List<TypedDataComponent<?>> - 修饰符:
private final - 源码定位:
L27 - 说明:
TODO
- 类型:
内部类/嵌套类型
net.minecraft.core.component.DataComponentExactPredicate.Builder- 类型:
class - 修饰符:
public static - 源码定位:
L96 - 说明:
TODO
- 类型:
构造器
private DataComponentExactPredicate(List<TypedDataComponent<?>> expectedComponents) @ L29
- 构造器名:DataComponentExactPredicate
- 源码定位:L29
- 修饰符:private
参数:
- expectedComponents: List<TypedDataComponent<?>>
说明:
TODO
方法
下面的方法块按源码顺序生成。
public static DataComponentExactPredicate.Builder builder() @ L33
- 方法名:builder
- 源码定位:L33
- 返回类型:DataComponentExactPredicate.Builder
- 修饰符:public static
参数:
- 无
说明:
TODO
public static <T> DataComponentExactPredicate expect(DataComponentType<T> type, T value) @ L37
- 方法名:expect
- 源码定位:L37
- 返回类型:
DataComponentExactPredicate - 修饰符:public static
参数:
- type: DataComponentType
- value: T
说明:
TODO
public static DataComponentExactPredicate allOf(DataComponentMap components) @ L41
- 方法名:allOf
- 源码定位:L41
- 返回类型:DataComponentExactPredicate
- 修饰符:public static
参数:
- components: DataComponentMap
说明:
TODO
public static DataComponentExactPredicate someOf(DataComponentMap components, DataComponentType<?>... types) @ L45
- 方法名:someOf
- 源码定位:L45
- 返回类型:DataComponentExactPredicate
- 修饰符:public static
参数:
- components: DataComponentMap
- types: DataComponentType<?>…
说明:
TODO
public boolean isEmpty() @ L58
- 方法名:isEmpty
- 源码定位:L58
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean equals(Object obj) @ L62
- 方法名:equals
- 源码定位:L62
- 返回类型:boolean
- 修饰符:public
参数:
- obj: Object
说明:
TODO
public int hashCode() @ L67
- 方法名:hashCode
- 源码定位:L67
- 返回类型:int
- 修饰符:public
参数:
- 无
说明:
TODO
public String toString() @ L72
- 方法名:toString
- 源码定位:L72
- 返回类型:String
- 修饰符:public
参数:
- 无
说明:
TODO
public boolean test(DataComponentGetter actualComponents) @ L77
- 方法名:test
- 源码定位:L77
- 返回类型:boolean
- 修饰符:public
参数:
- actualComponents: DataComponentGetter
说明:
TODO
public boolean alwaysMatches() @ L88
- 方法名:alwaysMatches
- 源码定位:L88
- 返回类型:boolean
- 修饰符:public
参数:
- 无
说明:
TODO
public DataComponentPatch asPatch() @ L92
- 方法名:asPatch
- 源码定位:L92
- 返回类型:DataComponentPatch
- 修饰符:public
参数:
- 无
说明:
TODO
代码
public final class DataComponentExactPredicate implements Predicate<DataComponentGetter> {
public static final Codec<DataComponentExactPredicate> CODEC = DataComponentType.VALUE_MAP_CODEC
.xmap(
map -> new DataComponentExactPredicate(map.entrySet().stream().map(TypedDataComponent::fromEntryUnchecked).collect(Collectors.toList())),
predicate -> predicate.expectedComponents
.stream()
.filter(e -> !e.type().isTransient())
.collect(Collectors.toMap(TypedDataComponent::type, TypedDataComponent::value))
);
public static final StreamCodec<RegistryFriendlyByteBuf, DataComponentExactPredicate> STREAM_CODEC = TypedDataComponent.STREAM_CODEC
.apply(ByteBufCodecs.list())
.map(DataComponentExactPredicate::new, predicate -> predicate.expectedComponents);
public static final DataComponentExactPredicate EMPTY = new DataComponentExactPredicate(List.of());
private final List<TypedDataComponent<?>> expectedComponents;
private DataComponentExactPredicate(List<TypedDataComponent<?>> expectedComponents) {
this.expectedComponents = expectedComponents;
}
public static DataComponentExactPredicate.Builder builder() {
return new DataComponentExactPredicate.Builder();
}
public static <T> DataComponentExactPredicate expect(DataComponentType<T> type, T value) {
return new DataComponentExactPredicate(List.of(new TypedDataComponent<>(type, value)));
}
public static DataComponentExactPredicate allOf(DataComponentMap components) {
return new DataComponentExactPredicate(ImmutableList.copyOf(components));
}
public static DataComponentExactPredicate someOf(DataComponentMap components, DataComponentType<?>... types) {
DataComponentExactPredicate.Builder result = new DataComponentExactPredicate.Builder();
for (DataComponentType<?> type : types) {
TypedDataComponent<?> value = components.getTyped(type);
if (value != null) {
result.expect(value);
}
}
return result.build();
}
public boolean isEmpty() {
return this.expectedComponents.isEmpty();
}
@Override
public boolean equals(Object obj) {
return obj instanceof DataComponentExactPredicate predicate && this.expectedComponents.equals(predicate.expectedComponents);
}
@Override
public int hashCode() {
return this.expectedComponents.hashCode();
}
@Override
public String toString() {
return this.expectedComponents.toString();
}
public boolean test(DataComponentGetter actualComponents) {
for (TypedDataComponent<?> expected : this.expectedComponents) {
Object actual = actualComponents.get(expected.type());
if (!Objects.equals(expected.value(), actual)) {
return false;
}
}
return true;
}
public boolean alwaysMatches() {
return this.expectedComponents.isEmpty();
}
public DataComponentPatch asPatch() {
return DataComponentPatch.builder().set(this.expectedComponents).build();
}
public static class Builder {
private final List<TypedDataComponent<?>> expectedComponents = new ArrayList<>();
private Builder() {
}
public <T> DataComponentExactPredicate.Builder expect(TypedDataComponent<T> value) {
return this.expect(value.type(), value.value());
}
public <T> DataComponentExactPredicate.Builder expect(DataComponentType<? super T> type, T value) {
for (TypedDataComponent<?> component : this.expectedComponents) {
if (component.type() == type) {
throw new IllegalArgumentException("Predicate already has component of type: '" + type + "'");
}
}
this.expectedComponents.add(new TypedDataComponent<>(type, value));
return this;
}
public DataComponentExactPredicate build() {
return new DataComponentExactPredicate(List.copyOf(this.expectedComponents));
}
}
}引用的其他类
-
- 引用位置:
参数/实现
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
方法调用/返回值 - 关联成员:
DataComponentPatch.builder()
- 引用位置:
-
- 引用位置:
参数
- 引用位置:
-
- 引用位置:
参数/字段
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ByteBufCodecs.list()
- 引用位置:
-
- 引用位置:
字段
- 引用位置: