ExtraCodecs.java
net.minecraft.util.ExtraCodecs
信息
- 全限定名:net.minecraft.util.ExtraCodecs
- 类型:public class
- 包:net.minecraft.util
- 源码路径:src/main/java/net/minecraft/util/ExtraCodecs.java
- 起始行号:L87
- 职责:
TODO
字段/常量
-
JSON- 类型:
Codec<JsonElement> - 修饰符:
public static final - 源码定位:
L88 - 说明:
TODO
- 类型:
-
JAVA- 类型:
Codec<Object> - 修饰符:
public static final - 源码定位:
L89 - 说明:
TODO
- 类型:
-
NBT- 类型:
Codec<Tag> - 修饰符:
public static final - 源码定位:
L90 - 说明:
TODO
- 类型:
-
VECTOR2F- 类型:
Codec<Vector2fc> - 修饰符:
public static final - 源码定位:
L91 - 说明:
TODO
- 类型:
-
VECTOR3F- 类型:
Codec<Vector3fc> - 修饰符:
public static final - 源码定位:
L94 - 说明:
TODO
- 类型:
-
VECTOR3I- 类型:
Codec<Vector3ic> - 修饰符:
public static final - 源码定位:
L99 - 说明:
TODO
- 类型:
-
VECTOR4F- 类型:
Codec<Vector4fc> - 修饰符:
public static final - 源码定位:
L104 - 说明:
TODO
- 类型:
-
QUATERNIONF_COMPONENTS- 类型:
Codec<Quaternionfc> - 修饰符:
public static final - 源码定位:
L110 - 说明:
TODO
- 类型:
-
AXISANGLE4F- 类型:
Codec<AxisAngle4f> - 修饰符:
public static final - 源码定位:
L116 - 说明:
TODO
- 类型:
-
QUATERNIONF- 类型:
Codec<Quaternionfc> - 修饰符:
public static final - 源码定位:
L120 - 说明:
TODO
- 类型:
-
MATRIX4F- 类型:
Codec<Matrix4fc> - 修饰符:
public static final - 源码定位:
L121 - 说明:
TODO
- 类型:
-
HEX_COLOR_PREFIX- 类型:
String - 修饰符:
private static final - 源码定位:
L138 - 说明:
TODO
- 类型:
-
RGB_COLOR_CODEC- 类型:
Codec<Integer> - 修饰符:
public static final - 源码定位:
L139 - 说明:
TODO
- 类型:
-
ARGB_COLOR_CODEC- 类型:
Codec<Integer> - 修饰符:
public static final - 源码定位:
L140 - 说明:
TODO
- 类型:
-
STRING_RGB_COLOR- 类型:
Codec<Integer> - 修饰符:
public static final - 源码定位:
L141 - 说明:
TODO
- 类型:
-
STRING_ARGB_COLOR- 类型:
Codec<Integer> - 修饰符:
public static final - 源码定位:
L142 - 说明:
TODO
- 类型:
-
UNSIGNED_BYTE- 类型:
Codec<Integer> - 修饰符:
public static final - 源码定位:
L143 - 说明:
TODO
- 类型:
-
NON_NEGATIVE_INT- 类型:
Codec<Integer> - 修饰符:
public static final - 源码定位:
L148 - 说明:
TODO
- 类型:
-
POSITIVE_INT- 类型:
Codec<Integer> - 修饰符:
public static final - 源码定位:
L149 - 说明:
TODO
- 类型:
-
NON_NEGATIVE_LONG- 类型:
Codec<Long> - 修饰符:
public static final - 源码定位:
L150 - 说明:
TODO
- 类型:
-
POSITIVE_LONG- 类型:
Codec<Long> - 修饰符:
public static final - 源码定位:
L151 - 说明:
TODO
- 类型:
-
NON_NEGATIVE_FLOAT- 类型:
Codec<Float> - 修饰符:
public static final - 源码定位:
L152 - 说明:
TODO
- 类型:
-
POSITIVE_FLOAT- 类型:
Codec<Float> - 修饰符:
public static final - 源码定位:
L153 - 说明:
TODO
- 类型:
-
PATTERN- 类型:
Codec<Pattern> - 修饰符:
public static final - 源码定位:
L154 - 说明:
TODO
- 类型:
-
INSTANT_ISO8601- 类型:
Codec<Instant> - 修饰符:
public static final - 源码定位:
L161 - 说明:
TODO
- 类型:
-
BASE64_STRING- 类型:
Codec<byte[]> - 修饰符:
public static final - 源码定位:
L162 - 说明:
TODO
- 类型:
-
ESCAPED_STRING- 类型:
Codec<String> - 修饰符:
public static final - 源码定位:
L169 - 说明:
TODO
- 类型:
-
TAG_OR_ELEMENT_ID- 类型:
Codec<ExtraCodecs.TagOrElementLocation> - 修饰符:
public static final - 源码定位:
L171 - 说明:
TODO
- 类型:
-
toOptionalLong- 类型:
Function<Optional<Long>,OptionalLong> - 修饰符:
public static final - 源码定位:
L178 - 说明:
TODO
- 类型:
-
fromOptionalLong- 类型:
Function<OptionalLong,Optional<Long>> - 修饰符:
public static final - 源码定位:
L179 - 说明:
TODO
- 类型:
-
BIT_SET- 类型:
Codec<BitSet> - 修饰符:
public static final - 源码定位:
L180 - 说明:
TODO
- 类型:
-
MAX_PROPERTY_NAME_LENGTH- 类型:
int - 修饰符:
public static final - 源码定位:
L182 - 说明:
TODO
- 类型:
-
MAX_PROPERTY_VALUE_LENGTH- 类型:
int - 修饰符:
public static final - 源码定位:
L183 - 说明:
TODO
- 类型:
-
MAX_PROPERTY_SIGNATURE_LENGTH- 类型:
int - 修饰符:
public static final - 源码定位:
L184 - 说明:
TODO
- 类型:
-
MAX_PROPERTIES- 类型:
int - 修饰符:
public static final - 源码定位:
L185 - 说明:
TODO
- 类型:
-
PROPERTY- 类型:
Codec<Property> - 修饰符:
private static final - 源码定位:
L186 - 说明:
TODO
- 类型:
-
PROPERTY_MAP- 类型:
Codec<PropertyMap> - 修饰符:
public static final - 源码定位:
L194 - 说明:
TODO
- 类型:
-
PLAYER_NAME- 类型:
Codec<String> - 修饰符:
public static final - 源码定位:
L214 - 说明:
TODO
- 类型:
-
AUTHLIB_GAME_PROFILE- 类型:
Codec<GameProfile> - 修饰符:
public static final - 源码定位:
L220 - 说明:
TODO
- 类型:
-
STORED_GAME_PROFILE- 类型:
MapCodec<GameProfile> - 修饰符:
public static final - 源码定位:
L221 - 说明:
TODO
- 类型:
-
NON_EMPTY_STRING- 类型:
Codec<String> - 修饰符:
public static final - 源码定位:
L222 - 说明:
TODO
- 类型:
-
CODEPOINT- 类型:
Codec<Integer> - 修饰符:
public static final - 源码定位:
L224 - 说明:
TODO
- 类型:
-
RESOURCE_PATH_CODEC- 类型:
Codec<String> - 修饰符:
public static final - 源码定位:
L228 - 说明:
TODO
- 类型:
-
UNTRUSTED_URI- 类型:
Codec<URI> - 修饰符:
public static final - 源码定位:
L230 - 说明:
TODO
- 类型:
-
CHAT_STRING- 类型:
Codec<String> - 修饰符:
public static final - 源码定位:
L237 - 说明:
TODO
- 类型:
内部类/嵌套类型
-
net.minecraft.util.ExtraCodecs.ContextRetrievalCodec- 类型:
class - 修饰符:
package-private - 源码定位:
L492 - 说明:
TODO
- 类型:
-
net.minecraft.util.ExtraCodecs.LateBoundIdMapper- 类型:
class - 修饰符:
public static - 源码定位:
L687 - 说明:
TODO
- 类型:
-
net.minecraft.util.ExtraCodecs.StrictUnboundedMapCodec- 类型:
record - 修饰符:
public - 源码定位:
L706 - 说明:
TODO
- 类型:
-
net.minecraft.util.ExtraCodecs.TagOrElementLocation- 类型:
record - 修饰符:
public - 源码定位:
L748 - 说明:
TODO
- 类型:
构造器
- 无
方法
下面的方法块按源码顺序生成。
public static <T> Codec<T> converter(DynamicOps<T> ops) @ L248
- 方法名:converter
- 源码定位:L248
- 返回类型:
Codec - 修饰符:public static
参数:
- ops: DynamicOps
说明:
TODO
private static Codec<Integer> hexColor(int expectedDigits) @ L252
- 方法名:hexColor
- 源码定位:L252
- 返回类型:Codec
- 修饰符:private static
参数:
- expectedDigits: int
说明:
TODO
public static <P,I> Codec<I> intervalCodec(Codec<P> pointCodec, String lowerBoundName, String upperBoundName, BiFunction<P,P,DataResult<I>> makeInterval, Function<I,P> getMin, Function<I,P> getMax) @ L279
- 方法名:intervalCodec
- 源码定位:L279
- 返回类型:<P,I> Codec
- 修饰符:public static
参数:
- pointCodec: Codec
- lowerBoundName: String
- upperBoundName: String
- makeInterval: BiFunction<P,P,DataResult>
- getMin: Function<I,P>
- getMax: Function<I,P>
说明:
TODO
public static <A> ResultFunction<A> orElsePartial(A value) @ L306
- 方法名:orElsePartial
- 源码定位:L306
- 返回类型: ResultFunction
- 修饰符:public static
参数:
- value: A
说明:
TODO
public static <E> Codec<E> idResolverCodec(ToIntFunction<E> toInt, IntFunction<E> fromInt, int unknownId) @ L327
- 方法名:idResolverCodec
- 源码定位:L327
- 返回类型:
Codec - 修饰符:public static
参数:
- toInt: ToIntFunction
- fromInt: IntFunction
- unknownId: int
说明:
TODO
public static <I,E> Codec<E> idResolverCodec(Codec<I> value, Function<I,E> fromId, Function<E,I> toId) @ L338
- 方法名:idResolverCodec
- 源码定位:L338
- 返回类型:<I,E> Codec
- 修饰符:public static
参数:
- value: Codec
- fromId: Function<I,E>
- toId: Function<E,I>
说明:
TODO
public static <E> Codec<E> orCompressed(Codec<E> normal, Codec<E> compressed) @ L348
- 方法名:orCompressed
- 源码定位:L348
- 返回类型:
Codec - 修饰符:public static
参数:
- normal: Codec
- compressed: Codec
说明:
TODO
public static <E> MapCodec<E> orCompressed(MapCodec<E> normal, MapCodec<E> compressed) @ L367
- 方法名:orCompressed
- 源码定位:L367
- 返回类型:
MapCodec - 修饰符:public static
参数:
- normal: MapCodec
- compressed: MapCodec
说明:
TODO
public static <E> Codec<E> overrideLifecycle(Codec<E> codec, Function<E,Lifecycle> decodeLifecycle, Function<E,Lifecycle> encodeLifecycle) @ L391
- 方法名:overrideLifecycle
- 源码定位:L391
- 返回类型:
Codec - 修饰符:public static
参数:
- codec: Codec
- decodeLifecycle: Function<E,Lifecycle>
- encodeLifecycle: Function<E,Lifecycle>
说明:
TODO
public static <E> Codec<E> overrideLifecycle(Codec<E> codec, Function<E,Lifecycle> lifecycleGetter) @ L410
- 方法名:overrideLifecycle
- 源码定位:L410
- 返回类型:
Codec - 修饰符:public static
参数:
- codec: Codec
- lifecycleGetter: Function<E,Lifecycle>
说明:
TODO
public static <K,V> ExtraCodecs.StrictUnboundedMapCodec<K,V> strictUnboundedMap(Codec<K> keyCodec, Codec<V> elementCodec) @ L414
- 方法名:strictUnboundedMap
- 源码定位:L414
- 返回类型:<K,V> ExtraCodecs.StrictUnboundedMapCodec<K,V>
- 修饰符:public static
参数:
- keyCodec: Codec
- elementCodec: Codec
说明:
TODO
public static <E> Codec<List<E>> compactListCodec(Codec<E> elementCodec) @ L418
- 方法名:compactListCodec
- 源码定位:L418
- 返回类型:
Codec<List > - 修饰符:public static
参数:
- elementCodec: Codec
说明:
TODO
public static <E> Codec<List<E>> compactListCodec(Codec<E> elementCodec, Codec<List<E>> listCodec) @ L422
- 方法名:compactListCodec
- 源码定位:L422
- 返回类型:
Codec<List > - 修饰符:public static
参数:
- elementCodec: Codec
- listCodec: Codec<List
>
说明:
TODO
private static Codec<Integer> intRangeWithMessage(int minInclusive, int maxInclusive, Function<Integer,String> error) @ L427
- 方法名:intRangeWithMessage
- 源码定位:L427
- 返回类型:Codec
- 修饰符:private static
参数:
- minInclusive: int
- maxInclusive: int
- error: Function<Integer,String>
说明:
TODO
public static Codec<Integer> intRange(int minInclusive, int maxInclusive) @ L436
- 方法名:intRange
- 源码定位:L436
- 返回类型:Codec
- 修饰符:public static
参数:
- minInclusive: int
- maxInclusive: int
说明:
TODO
private static Codec<Long> longRangeWithMessage(long minInclusive, long maxInclusive, Function<Long,String> error) @ L440
- 方法名:longRangeWithMessage
- 源码定位:L440
- 返回类型:Codec
- 修饰符:private static
参数:
- minInclusive: long
- maxInclusive: long
- error: Function<Long,String>
说明:
TODO
public static Codec<Long> longRange(int minInclusive, int maxInclusive) @ L449
- 方法名:longRange
- 源码定位:L449
- 返回类型:Codec
- 修饰符:public static
参数:
- minInclusive: int
- maxInclusive: int
说明:
TODO
private static Codec<Float> floatRangeMinInclusiveWithMessage(float minInclusive, float maxInclusive, Function<Float,String> error) @ L453
- 方法名:floatRangeMinInclusiveWithMessage
- 源码定位:L453
- 返回类型:Codec
- 修饰符:private static
参数:
- minInclusive: float
- maxInclusive: float
- error: Function<Float,String>
说明:
TODO
private static Codec<Float> floatRangeMinExclusiveWithMessage(float minExclusive, float maxInclusive, Function<Float,String> error) @ L462
- 方法名:floatRangeMinExclusiveWithMessage
- 源码定位:L462
- 返回类型:Codec
- 修饰符:private static
参数:
- minExclusive: float
- maxInclusive: float
- error: Function<Float,String>
说明:
TODO
public static Codec<Float> floatRange(float minInclusive, float maxInclusive) @ L471
- 方法名:floatRange
- 源码定位:L471
- 返回类型:Codec
- 修饰符:public static
参数:
- minInclusive: float
- maxInclusive: float
说明:
TODO
public static <T> Codec<List<T>> nonEmptyList(Codec<List<T>> listCodec) @ L477
- 方法名:nonEmptyList
- 源码定位:L477
- 返回类型:
Codec<List > - 修饰符:public static
参数:
- listCodec: Codec<List
>
说明:
TODO
public static <T> Codec<HolderSet<T>> nonEmptyHolderSet(Codec<HolderSet<T>> listCodec) @ L481
- 方法名:nonEmptyHolderSet
- 源码定位:L481
- 返回类型:
Codec<HolderSet > - 修饰符:public static
参数:
- listCodec: Codec<HolderSet
>
说明:
TODO
public static <M extends Map<?,?>> Codec<M> nonEmptyMap(Codec<M> mapCodec) @ L487
- 方法名:nonEmptyMap
- 源码定位:L487
- 返回类型:<M extends Map> Codec
- 修饰符:public static
参数:
- mapCodec: Codec
说明:
TODO
public static <E> MapCodec<E> retrieveContext(Function<DynamicOps<?>,DataResult<E>> getter) @ L491
- 方法名:retrieveContext
- 源码定位:L491
- 返回类型:
MapCodec - 修饰符:public static
参数:
- getter: Function<DynamicOps<?>,DataResult
>
说明:
TODO
public static <E,L extends Collection<E>,T> Function<L,DataResult<L>> ensureHomogenous(Function<E,T> typeGetter) @ L517
- 方法名:ensureHomogenous
- 源码定位:L517
- 返回类型:<E,L extends Collection
,T> Function<L,DataResult > - 修饰符:public static
参数:
- typeGetter: Function<E,T>
说明:
TODO
public static <A> Codec<A> catchDecoderException(Codec<A> codec) @ L536
参数:
说明:
TODO
public static Codec<TemporalAccessor> temporalCodec(DateTimeFormatter formatter) @ L549
- 方法名:temporalCodec
- 源码定位:L549
- 返回类型:Codec
- 修饰符:public static
参数:
- formatter: DateTimeFormatter
说明:
TODO
public static MapCodec<OptionalLong> asOptionalLong(MapCodec<Optional<Long>> fieldCodec) @ L559
- 方法名:asOptionalLong
- 源码定位:L559
- 返回类型:MapCodec
- 修饰符:public static
参数:
- fieldCodec: MapCodec<Optional
>
说明:
TODO
private static MapCodec<GameProfile> gameProfileCodec(Codec<UUID> uuidCodec) @ L563
- 方法名:gameProfileCodec
- 源码定位:L563
- 返回类型:MapCodec
- 修饰符:private static
参数:
- uuidCodec: Codec
说明:
TODO
public static <K,V> Codec<Map<K,V>> sizeLimitedMap(Codec<Map<K,V>> codec, int maxSizeInclusive) @ L574
- 方法名:sizeLimitedMap
- 源码定位:L574
- 返回类型:<K,V> Codec<Map<K,V>>
- 修饰符:public static
参数:
- codec: Codec<Map<K,V>>
- maxSizeInclusive: int
说明:
TODO
public static <T> Codec<Object2BooleanMap<T>> object2BooleanMap(Codec<T> keyCodec) @ L582
- 方法名:object2BooleanMap
- 源码定位:L582
- 返回类型:
Codec<Object2BooleanMap > - 修饰符:public static
参数:
- keyCodec: Codec
说明:
TODO
public static <K,V> MapCodec<V> dispatchOptionalValue(String typeKey, String valueKey, Codec<K> typeCodec, Function<?super V,?extends K> typeGetter, Function<?super K,?extends Codec<?extends V>> valueCodec) @ L586
- 方法名:dispatchOptionalValue
- 源码定位:L586
- 返回类型:<K,V> MapCodec
- 修饰符:public static
参数:
- typeKey: String
- valueKey: String
- typeCodec: Codec
- typeGetter: Function<?super V,?extends K>
- valueCodec: Function<?super K,?extends Codec<?extends V>>
说明:
TODO
public static <A> Codec<Optional<A>> optionalEmptyMap(Codec<A> codec) @ L629
参数:
说明:
TODO
public static <E extends Enum<E>> Codec<E> legacyEnum(Function<String,E> valueOf) @ L649
- 方法名:legacyEnum
- 源码定位:L649
- 返回类型:<E extends Enum
> Codec - 修饰符:public static
参数:
- valueOf: Function<String,E>
说明:
TODO
public static Codec<Path> pathCodec(Function<String,Path> pathFactory) @ L660
- 方法名:pathCodec
- 源码定位:L660
- 返回类型:Codec
- 修饰符:public static
参数:
- pathFactory: Function<String,Path>
说明:
TODO
public static Codec<Path> relaiveNormalizedSubPathCodec(Function<String,Path> pathFactory) @ L664
- 方法名:relaiveNormalizedSubPathCodec
- 源码定位:L664
- 返回类型:Codec
- 修饰符:public static
参数:
- pathFactory: Function<String,Path>
说明:
TODO
public static Codec<Path> guardedPathCodec(Path baseFolder) @ L680
- 方法名:guardedPathCodec
- 源码定位:L680
- 返回类型:Codec
- 修饰符:public static
参数:
- baseFolder: Path
说明:
TODO
代码
public class ExtraCodecs {
public static final Codec<JsonElement> JSON = converter(JsonOps.INSTANCE);
public static final Codec<Object> JAVA = converter(JavaOps.INSTANCE);
public static final Codec<Tag> NBT = converter(NbtOps.INSTANCE);
public static final Codec<Vector2fc> VECTOR2F = Codec.FLOAT
.listOf()
.comapFlatMap(input -> Util.fixedSize((List<Float>)input, 2).map(d -> new Vector2f(d.get(0), d.get(1))), vec -> List.of(vec.x(), vec.y()));
public static final Codec<Vector3fc> VECTOR3F = Codec.FLOAT
.listOf()
.comapFlatMap(
input -> Util.fixedSize((List<Float>)input, 3).map(d -> new Vector3f(d.get(0), d.get(1), d.get(2))), vec -> List.of(vec.x(), vec.y(), vec.z())
);
public static final Codec<Vector3ic> VECTOR3I = Codec.INT
.listOf()
.comapFlatMap(
input -> Util.fixedSize((List<Integer>)input, 3).map(d -> new Vector3i(d.get(0), d.get(1), d.get(2))), vec -> List.of(vec.x(), vec.y(), vec.z())
);
public static final Codec<Vector4fc> VECTOR4F = Codec.FLOAT
.listOf()
.comapFlatMap(
input -> Util.fixedSize((List<Float>)input, 4).map(d -> new Vector4f(d.get(0), d.get(1), d.get(2), d.get(3))),
vec -> List.of(vec.x(), vec.y(), vec.z(), vec.w())
);
public static final Codec<Quaternionfc> QUATERNIONF_COMPONENTS = Codec.FLOAT
.listOf()
.comapFlatMap(
input -> Util.fixedSize((List<Float>)input, 4).map(d -> new Quaternionf(d.get(0), d.get(1), d.get(2), d.get(3)).normalize()),
q -> List.of(q.x(), q.y(), q.z(), q.w())
);
public static final Codec<AxisAngle4f> AXISANGLE4F = RecordCodecBuilder.create(
i -> i.group(Codec.FLOAT.fieldOf("angle").forGetter(o -> o.angle), VECTOR3F.fieldOf("axis").forGetter(o -> new Vector3f(o.x, o.y, o.z)))
.apply(i, AxisAngle4f::new)
);
public static final Codec<Quaternionfc> QUATERNIONF = Codec.withAlternative(QUATERNIONF_COMPONENTS, AXISANGLE4F.xmap(Quaternionf::new, AxisAngle4f::new));
public static final Codec<Matrix4fc> MATRIX4F = Codec.FLOAT.listOf().comapFlatMap(input -> Util.fixedSize((List<Float>)input, 16).map(l -> {
Matrix4f result = new Matrix4f();
for (int i = 0; i < l.size(); i++) {
result.setRowColumn(i >> 2, i & 3, l.get(i));
}
return result.determineProperties();
}), m -> {
FloatList output = new FloatArrayList(16);
for (int i = 0; i < 16; i++) {
output.add(m.getRowColumn(i >> 2, i & 3));
}
return output;
});
private static final String HEX_COLOR_PREFIX = "#";
public static final Codec<Integer> RGB_COLOR_CODEC = Codec.withAlternative(Codec.INT, VECTOR3F, v -> ARGB.colorFromFloat(1.0F, v.x(), v.y(), v.z()));
public static final Codec<Integer> ARGB_COLOR_CODEC = Codec.withAlternative(Codec.INT, VECTOR4F, v -> ARGB.colorFromFloat(v.w(), v.x(), v.y(), v.z()));
public static final Codec<Integer> STRING_RGB_COLOR = Codec.withAlternative(hexColor(6).xmap(ARGB::opaque, ARGB::transparent), RGB_COLOR_CODEC);
public static final Codec<Integer> STRING_ARGB_COLOR = Codec.withAlternative(hexColor(8), ARGB_COLOR_CODEC);
public static final Codec<Integer> UNSIGNED_BYTE = Codec.BYTE
.flatComapMap(
UnsignedBytes::toInt,
integer -> integer > 255 ? DataResult.error(() -> "Unsigned byte was too large: " + integer + " > 255") : DataResult.success(integer.byteValue())
);
public static final Codec<Integer> NON_NEGATIVE_INT = intRangeWithMessage(0, Integer.MAX_VALUE, n -> "Value must be non-negative: " + n);
public static final Codec<Integer> POSITIVE_INT = intRangeWithMessage(1, Integer.MAX_VALUE, n -> "Value must be positive: " + n);
public static final Codec<Long> NON_NEGATIVE_LONG = longRangeWithMessage(0L, Long.MAX_VALUE, n -> "Value must be non-negative: " + n);
public static final Codec<Long> POSITIVE_LONG = longRangeWithMessage(1L, Long.MAX_VALUE, n -> "Value must be positive: " + n);
public static final Codec<Float> NON_NEGATIVE_FLOAT = floatRangeMinInclusiveWithMessage(0.0F, Float.MAX_VALUE, n -> "Value must be non-negative: " + n);
public static final Codec<Float> POSITIVE_FLOAT = floatRangeMinExclusiveWithMessage(0.0F, Float.MAX_VALUE, n -> "Value must be positive: " + n);
public static final Codec<Pattern> PATTERN = Codec.STRING.comapFlatMap(pattern -> {
try {
return DataResult.success(Pattern.compile(pattern));
} catch (PatternSyntaxException var2) {
return DataResult.error(() -> "Invalid regex pattern '" + pattern + "': " + var2.getMessage());
}
}, Pattern::pattern);
public static final Codec<Instant> INSTANT_ISO8601 = temporalCodec(DateTimeFormatter.ISO_INSTANT).xmap(Instant::from, Function.identity());
public static final Codec<byte[]> BASE64_STRING = Codec.STRING.comapFlatMap(string -> {
try {
return DataResult.success(Base64.getDecoder().decode(string));
} catch (IllegalArgumentException var2) {
return DataResult.error(() -> "Malformed base64 string");
}
}, bytes -> Base64.getEncoder().encodeToString(bytes));
public static final Codec<String> ESCAPED_STRING = Codec.STRING
.comapFlatMap(str -> DataResult.success(StringEscapeUtils.unescapeJava(str)), StringEscapeUtils::escapeJava);
public static final Codec<ExtraCodecs.TagOrElementLocation> TAG_OR_ELEMENT_ID = Codec.STRING
.comapFlatMap(
name -> name.startsWith("#")
? Identifier.read(name.substring(1)).map(id -> new ExtraCodecs.TagOrElementLocation(id, true))
: Identifier.read(name).map(id -> new ExtraCodecs.TagOrElementLocation(id, false)),
ExtraCodecs.TagOrElementLocation::decoratedId
);
public static final Function<Optional<Long>, OptionalLong> toOptionalLong = o -> o.map(OptionalLong::of).orElseGet(OptionalLong::empty);
public static final Function<OptionalLong, Optional<Long>> fromOptionalLong = l -> l.isPresent() ? Optional.of(l.getAsLong()) : Optional.empty();
public static final Codec<BitSet> BIT_SET = Codec.LONG_STREAM
.xmap(longStream -> BitSet.valueOf(longStream.toArray()), bitSet -> Arrays.stream(bitSet.toLongArray()));
public static final int MAX_PROPERTY_NAME_LENGTH = 64;
public static final int MAX_PROPERTY_VALUE_LENGTH = 32767;
public static final int MAX_PROPERTY_SIGNATURE_LENGTH = 1024;
public static final int MAX_PROPERTIES = 16;
private static final Codec<Property> PROPERTY = RecordCodecBuilder.create(
i -> i.group(
Codec.sizeLimitedString(64).fieldOf("name").forGetter(Property::name),
Codec.sizeLimitedString(32767).fieldOf("value").forGetter(Property::value),
Codec.sizeLimitedString(1024).optionalFieldOf("signature").forGetter(property -> Optional.ofNullable(property.signature()))
)
.apply(i, (name, value, signature) -> new Property(name, value, signature.orElse(null)))
);
public static final Codec<PropertyMap> PROPERTY_MAP = Codec.either(
Codec.unboundedMap(Codec.STRING, Codec.STRING.listOf())
.validate(
map -> map.size() > 16 ? DataResult.error(() -> "Cannot have more than 16 properties, but was " + map.size()) : DataResult.success(map)
),
PROPERTY.sizeLimitedListOf(16)
)
.xmap(mapListEither -> {
Builder<String, Property> result = ImmutableMultimap.builder();
mapListEither.ifLeft(s -> s.forEach((name, properties) -> {
for (String property : properties) {
result.put(name, new Property(name, property));
}
})).ifRight(properties -> {
for (Property property : properties) {
result.put(property.name(), property);
}
});
return new PropertyMap(result.build());
}, propertyMap -> Either.right(propertyMap.values().stream().toList()));
public static final Codec<String> PLAYER_NAME = Codec.string(0, 16)
.validate(
name -> StringUtil.isValidPlayerName(name)
? DataResult.success(name)
: DataResult.error(() -> "Player name contained disallowed characters: '" + name + "'")
);
public static final Codec<GameProfile> AUTHLIB_GAME_PROFILE = gameProfileCodec(UUIDUtil.AUTHLIB_CODEC).codec();
public static final MapCodec<GameProfile> STORED_GAME_PROFILE = gameProfileCodec(UUIDUtil.CODEC);
public static final Codec<String> NON_EMPTY_STRING = Codec.STRING
.validate(value -> value.isEmpty() ? DataResult.error(() -> "Expected non-empty string") : DataResult.success(value));
public static final Codec<Integer> CODEPOINT = Codec.STRING.comapFlatMap(s -> {
int[] codepoint = s.codePoints().toArray();
return codepoint.length != 1 ? DataResult.error(() -> "Expected one codepoint, got: " + s) : DataResult.success(codepoint[0]);
}, Character::toString);
public static final Codec<String> RESOURCE_PATH_CODEC = Codec.STRING
.validate(s -> !Identifier.isValidPath(s) ? DataResult.error(() -> "Invalid string to use as a resource path element: " + s) : DataResult.success(s));
public static final Codec<URI> UNTRUSTED_URI = Codec.STRING.comapFlatMap(string -> {
try {
return DataResult.success(Util.parseAndValidateUntrustedUri(string));
} catch (URISyntaxException var2) {
return DataResult.error(var2::getMessage);
}
}, URI::toString);
public static final Codec<String> CHAT_STRING = Codec.STRING.validate(string -> {
for (int i = 0; i < string.length(); i++) {
char c = string.charAt(i);
if (!StringUtil.isAllowedChatCharacter(c)) {
return DataResult.error(() -> "Disallowed chat character: '" + c + "'");
}
}
return DataResult.success(string);
});
public static <T> Codec<T> converter(DynamicOps<T> ops) {
return Codec.PASSTHROUGH.xmap(t -> t.convert(ops).getValue(), t -> new Dynamic<>(ops, (T)t));
}
private static Codec<Integer> hexColor(int expectedDigits) {
long maxValue = (1L << expectedDigits * 4) - 1L;
return Codec.STRING
.comapFlatMap(
string -> {
if (!string.startsWith("#")) {
return DataResult.error(() -> "Hex color must begin with #");
} else {
int digits = string.length() - "#".length();
if (digits != expectedDigits) {
return DataResult.error(() -> "Hex color is wrong size, expected " + expectedDigits + " digits but got " + digits);
} else {
try {
long value = HexFormat.fromHexDigitsToLong(string, "#".length(), string.length());
return value >= 0L && value <= maxValue
? DataResult.success((int)value)
: DataResult.error(() -> "Color value out of range: " + string);
} catch (NumberFormatException var7) {
return DataResult.error(() -> "Invalid color value: " + string);
}
}
}
},
value -> "#" + HexFormat.of().toHexDigits(value.intValue(), expectedDigits)
);
}
public static <P, I> Codec<I> intervalCodec(
Codec<P> pointCodec,
String lowerBoundName,
String upperBoundName,
BiFunction<P, P, DataResult<I>> makeInterval,
Function<I, P> getMin,
Function<I, P> getMax
) {
Codec<I> arrayCodec = Codec.list(pointCodec).comapFlatMap(list -> Util.fixedSize((List<P>)list, 2).flatMap(l -> {
P min = l.get(0);
P max = l.get(1);
return makeInterval.apply(min, max);
}), p -> ImmutableList.of(getMin.apply((I)p), getMax.apply((I)p)));
Codec<I> objectCodec = RecordCodecBuilder.<Pair<P, P>>create(
i -> i.group(pointCodec.fieldOf(lowerBoundName).forGetter(Pair::getFirst), pointCodec.fieldOf(upperBoundName).forGetter(Pair::getSecond))
.apply(i, Pair::of)
)
.comapFlatMap(p -> makeInterval.apply((P)p.getFirst(), (P)p.getSecond()), i -> Pair.of(getMin.apply((I)i), getMax.apply((I)i)));
Codec<I> arrayOrObjectCodec = Codec.withAlternative(arrayCodec, objectCodec);
return Codec.either(pointCodec, arrayOrObjectCodec)
.comapFlatMap(either -> either.map(min -> makeInterval.apply((P)min, (P)min), DataResult::success), p -> {
P min = getMin.apply((I)p);
P max = getMax.apply((I)p);
return Objects.equals(min, max) ? Either.left(min) : Either.right((I)p);
});
}
public static <A> ResultFunction<A> orElsePartial(A value) {
return new ResultFunction<A>() {
@Override
public <T> DataResult<Pair<A, T>> apply(DynamicOps<T> ops, T input, DataResult<Pair<A, T>> a) {
MutableObject<String> message = new MutableObject<>();
Optional<Pair<A, T>> result = a.resultOrPartial(message::setValue);
return result.isPresent() ? a : DataResult.error(() -> "(" + message.get() + " -> using default)", Pair.of(value, input));
}
@Override
public <T> DataResult<T> coApply(DynamicOps<T> ops, A input, DataResult<T> t) {
return t;
}
@Override
public String toString() {
return "OrElsePartial[" + value + "]";
}
};
}
public static <E> Codec<E> idResolverCodec(ToIntFunction<E> toInt, IntFunction<@Nullable E> fromInt, int unknownId) {
return Codec.INT
.flatXmap(
id -> Optional.ofNullable(fromInt.apply(id)).map(DataResult::success).orElseGet(() -> DataResult.error(() -> "Unknown element id: " + id)),
e -> {
int id = toInt.applyAsInt((E)e);
return id == unknownId ? DataResult.error(() -> "Element with unknown id: " + e) : DataResult.success(id);
}
);
}
public static <I, E> Codec<E> idResolverCodec(Codec<I> value, Function<I, @Nullable E> fromId, Function<E, @Nullable I> toId) {
return value.flatXmap(id -> {
E element = fromId.apply((I)id);
return element == null ? DataResult.error(() -> "Unknown element id: " + id) : DataResult.success(element);
}, e -> {
I id = toId.apply((E)e);
return id == null ? DataResult.error(() -> "Element with unknown id: " + e) : DataResult.success(id);
});
}
public static <E> Codec<E> orCompressed(Codec<E> normal, Codec<E> compressed) {
return new Codec<E>() {
@Override
public <T> DataResult<T> encode(E input, DynamicOps<T> ops, T prefix) {
return ops.compressMaps() ? compressed.encode(input, ops, prefix) : normal.encode(input, ops, prefix);
}
@Override
public <T> DataResult<Pair<E, T>> decode(DynamicOps<T> ops, T input) {
return ops.compressMaps() ? compressed.decode(ops, input) : normal.decode(ops, input);
}
@Override
public String toString() {
return normal + " orCompressed " + compressed;
}
};
}
public static <E> MapCodec<E> orCompressed(MapCodec<E> normal, MapCodec<E> compressed) {
return new MapCodec<E>() {
@Override
public <T> RecordBuilder<T> encode(E input, DynamicOps<T> ops, RecordBuilder<T> prefix) {
return ops.compressMaps() ? compressed.encode(input, ops, prefix) : normal.encode(input, ops, prefix);
}
@Override
public <T> DataResult<E> decode(DynamicOps<T> ops, MapLike<T> input) {
return ops.compressMaps() ? compressed.decode(ops, input) : normal.decode(ops, input);
}
@Override
public <T> Stream<T> keys(DynamicOps<T> ops) {
return compressed.keys(ops);
}
@Override
public String toString() {
return normal + " orCompressed " + compressed;
}
};
}
public static <E> Codec<E> overrideLifecycle(Codec<E> codec, Function<E, Lifecycle> decodeLifecycle, Function<E, Lifecycle> encodeLifecycle) {
return codec.mapResult(new ResultFunction<E>() {
@Override
public <T> DataResult<Pair<E, T>> apply(DynamicOps<T> ops, T input, DataResult<Pair<E, T>> a) {
return a.result().map(r -> a.setLifecycle(decodeLifecycle.apply(r.getFirst()))).orElse(a);
}
@Override
public <T> DataResult<T> coApply(DynamicOps<T> ops, E input, DataResult<T> t) {
return t.setLifecycle(encodeLifecycle.apply(input));
}
@Override
public String toString() {
return "WithLifecycle[" + decodeLifecycle + " " + encodeLifecycle + "]";
}
});
}
public static <E> Codec<E> overrideLifecycle(Codec<E> codec, Function<E, Lifecycle> lifecycleGetter) {
return overrideLifecycle(codec, lifecycleGetter, lifecycleGetter);
}
public static <K, V> ExtraCodecs.StrictUnboundedMapCodec<K, V> strictUnboundedMap(Codec<K> keyCodec, Codec<V> elementCodec) {
return new ExtraCodecs.StrictUnboundedMapCodec<>(keyCodec, elementCodec);
}
public static <E> Codec<List<E>> compactListCodec(Codec<E> elementCodec) {
return compactListCodec(elementCodec, elementCodec.listOf());
}
public static <E> Codec<List<E>> compactListCodec(Codec<E> elementCodec, Codec<List<E>> listCodec) {
return Codec.either(listCodec, elementCodec)
.xmap(e -> e.map(l -> l, List::of), v -> v.size() == 1 ? Either.right(v.getFirst()) : Either.left((List<E>)v));
}
private static Codec<Integer> intRangeWithMessage(int minInclusive, int maxInclusive, Function<Integer, String> error) {
return Codec.INT
.validate(
value -> value.compareTo(minInclusive) >= 0 && value.compareTo(maxInclusive) <= 0
? DataResult.success(value)
: DataResult.error(() -> error.apply(value))
);
}
public static Codec<Integer> intRange(int minInclusive, int maxInclusive) {
return intRangeWithMessage(minInclusive, maxInclusive, n -> "Value must be within range [" + minInclusive + ";" + maxInclusive + "]: " + n);
}
private static Codec<Long> longRangeWithMessage(long minInclusive, long maxInclusive, Function<Long, String> error) {
return Codec.LONG
.validate(
value -> value.compareTo(minInclusive) >= 0L && value.compareTo(maxInclusive) <= 0L
? DataResult.success(value)
: DataResult.error(() -> error.apply(value))
);
}
public static Codec<Long> longRange(int minInclusive, int maxInclusive) {
return longRangeWithMessage(minInclusive, maxInclusive, n -> "Value must be within range [" + minInclusive + ";" + maxInclusive + "]: " + n);
}
private static Codec<Float> floatRangeMinInclusiveWithMessage(float minInclusive, float maxInclusive, Function<Float, String> error) {
return Codec.FLOAT
.validate(
value -> value.compareTo(minInclusive) >= 0 && value.compareTo(maxInclusive) <= 0
? DataResult.success(value)
: DataResult.error(() -> error.apply(value))
);
}
private static Codec<Float> floatRangeMinExclusiveWithMessage(float minExclusive, float maxInclusive, Function<Float, String> error) {
return Codec.FLOAT
.validate(
value -> value.compareTo(minExclusive) > 0 && value.compareTo(maxInclusive) <= 0
? DataResult.success(value)
: DataResult.error(() -> error.apply(value))
);
}
public static Codec<Float> floatRange(float minInclusive, float maxInclusive) {
return floatRangeMinInclusiveWithMessage(
minInclusive, maxInclusive, n -> "Value must be within range [" + minInclusive + ";" + maxInclusive + "]: " + n
);
}
public static <T> Codec<List<T>> nonEmptyList(Codec<List<T>> listCodec) {
return listCodec.validate(list -> list.isEmpty() ? DataResult.error(() -> "List must have contents") : DataResult.success(list));
}
public static <T> Codec<HolderSet<T>> nonEmptyHolderSet(Codec<HolderSet<T>> listCodec) {
return listCodec.validate(
list -> list.unwrap().right().filter(List::isEmpty).isPresent() ? DataResult.error(() -> "List must have contents") : DataResult.success(list)
);
}
public static <M extends Map<?, ?>> Codec<M> nonEmptyMap(Codec<M> mapCodec) {
return mapCodec.validate(map -> map.isEmpty() ? DataResult.error(() -> "Map must have contents") : DataResult.success(map));
}
public static <E> MapCodec<E> retrieveContext(Function<DynamicOps<?>, DataResult<E>> getter) {
class ContextRetrievalCodec extends MapCodec<E> {
@Override
public <T> RecordBuilder<T> encode(E input, DynamicOps<T> ops, RecordBuilder<T> prefix) {
return prefix;
}
@Override
public <T> DataResult<E> decode(DynamicOps<T> ops, MapLike<T> input) {
return getter.apply(ops);
}
@Override
public String toString() {
return "ContextRetrievalCodec[" + getter + "]";
}
@Override
public <T> Stream<T> keys(DynamicOps<T> ops) {
return Stream.empty();
}
}
return new ContextRetrievalCodec();
}
public static <E, L extends Collection<E>, T> Function<L, DataResult<L>> ensureHomogenous(Function<E, T> typeGetter) {
return container -> {
Iterator<E> it = container.iterator();
if (it.hasNext()) {
T firstType = typeGetter.apply(it.next());
while (it.hasNext()) {
E next = it.next();
T nextType = typeGetter.apply(next);
if (nextType != firstType) {
return DataResult.error(() -> "Mixed type list: element " + next + " had type " + nextType + ", but list is of type " + firstType);
}
}
}
return DataResult.success(container, Lifecycle.stable());
};
}
public static <A> Codec<A> catchDecoderException(Codec<A> codec) {
return Codec.of(codec, new Decoder<A>() {
@Override
public <T> DataResult<Pair<A, T>> decode(DynamicOps<T> ops, T input) {
try {
return codec.decode(ops, input);
} catch (Exception var4) {
return DataResult.error(() -> "Caught exception decoding " + input + ": " + var4.getMessage());
}
}
});
}
public static Codec<TemporalAccessor> temporalCodec(DateTimeFormatter formatter) {
return Codec.STRING.comapFlatMap(s -> {
try {
return DataResult.success(formatter.parse(s));
} catch (Exception var3) {
return DataResult.error(var3::getMessage);
}
}, formatter::format);
}
public static MapCodec<OptionalLong> asOptionalLong(MapCodec<Optional<Long>> fieldCodec) {
return fieldCodec.xmap(toOptionalLong, fromOptionalLong);
}
private static MapCodec<GameProfile> gameProfileCodec(Codec<UUID> uuidCodec) {
return RecordCodecBuilder.mapCodec(
i -> i.group(
uuidCodec.fieldOf("id").forGetter(GameProfile::id),
PLAYER_NAME.fieldOf("name").forGetter(GameProfile::name),
PROPERTY_MAP.optionalFieldOf("properties", PropertyMap.EMPTY).forGetter(GameProfile::properties)
)
.apply(i, GameProfile::new)
);
}
public static <K, V> Codec<Map<K, V>> sizeLimitedMap(Codec<Map<K, V>> codec, int maxSizeInclusive) {
return codec.validate(
map -> map.size() > maxSizeInclusive
? DataResult.error(() -> "Map is too long: " + map.size() + ", expected range [0-" + maxSizeInclusive + "]")
: DataResult.success(map)
);
}
public static <T> Codec<Object2BooleanMap<T>> object2BooleanMap(Codec<T> keyCodec) {
return Codec.unboundedMap(keyCodec, Codec.BOOL).xmap(Object2BooleanOpenHashMap::new, Object2ObjectOpenHashMap::new);
}
@Deprecated
public static <K, V> MapCodec<V> dispatchOptionalValue(
String typeKey,
String valueKey,
Codec<K> typeCodec,
Function<? super V, ? extends K> typeGetter,
Function<? super K, ? extends Codec<? extends V>> valueCodec
) {
return new MapCodec<V>() {
@Override
public <T> Stream<T> keys(DynamicOps<T> ops) {
return Stream.of(ops.createString(typeKey), ops.createString(valueKey));
}
@Override
public <T> DataResult<V> decode(DynamicOps<T> ops, MapLike<T> input) {
T typeName = input.get(typeKey);
return typeName == null
? DataResult.error(() -> "Missing \"" + typeKey + "\" in: " + input)
: typeCodec.decode(ops, typeName).flatMap(type -> {
T value = Objects.requireNonNullElseGet(input.get(valueKey), ops::emptyMap);
return valueCodec.apply(type.getFirst()).decode(ops, value).map(Pair::getFirst);
});
}
@Override
public <T> RecordBuilder<T> encode(V input, DynamicOps<T> ops, RecordBuilder<T> builder) {
K type = (K)typeGetter.apply(input);
builder.add(typeKey, typeCodec.encodeStart(ops, type));
DataResult<T> parameters = this.encode((Codec<? extends V>)valueCodec.apply(type), input, ops);
if (parameters.result().isEmpty() || !Objects.equals(parameters.result().get(), ops.emptyMap())) {
builder.add(valueKey, parameters);
}
return builder;
}
private <T, V2 extends V> DataResult<T> encode(Codec<V2> codec, V input, DynamicOps<T> ops) {
return codec.encodeStart(ops, (V2)input);
}
};
}
public static <A> Codec<Optional<A>> optionalEmptyMap(Codec<A> codec) {
return new Codec<Optional<A>>() {
@Override
public <T> DataResult<Pair<Optional<A>, T>> decode(DynamicOps<T> ops, T input) {
return isEmptyMap(ops, input)
? DataResult.success(Pair.of(Optional.empty(), input))
: codec.decode(ops, input).map(pair -> pair.mapFirst(Optional::of));
}
private static <T> boolean isEmptyMap(DynamicOps<T> ops, T input) {
Optional<MapLike<T>> map = ops.getMap(input).result();
return map.isPresent() && map.get().entries().findAny().isEmpty();
}
public <T> DataResult<T> encode(Optional<A> input, DynamicOps<T> ops, T prefix) {
return input.isEmpty() ? DataResult.success(ops.emptyMap()) : codec.encode(input.get(), ops, prefix);
}
};
}
@Deprecated
public static <E extends Enum<E>> Codec<E> legacyEnum(Function<String, E> valueOf) {
return Codec.STRING.comapFlatMap(key -> {
try {
return DataResult.success(valueOf.apply(key));
} catch (IllegalArgumentException var3) {
return DataResult.error(() -> "No value with id: " + key);
}
}, Enum::toString);
}
public static Codec<Path> pathCodec(Function<String, Path> pathFactory) {
return Codec.STRING.xmap(pathFactory, path -> FilenameUtils.separatorsToUnix(path.toString()));
}
public static Codec<Path> relaiveNormalizedSubPathCodec(Function<String, Path> pathFactory) {
return pathCodec(pathFactory)
.xmap(Path::normalize, Path::normalize)
.validate(
path -> {
if (path.isAbsolute()) {
return DataResult.error(() -> "Illegal absolute path: " + path);
} else {
return !path.startsWith("..") && !path.startsWith(".") && !FileUtil.isEmptyPath(path)
? DataResult.success(path)
: DataResult.error(() -> "Illegal path traversal: " + path);
}
}
);
}
public static Codec<Path> guardedPathCodec(Path baseFolder) {
FileSystem var10000 = baseFolder.getFileSystem();
Objects.requireNonNull(var10000);
FileSystem var1 = var10000;
return relaiveNormalizedSubPathCodec(x$0 -> var1.getPath(x$0)).xmap(baseFolder::resolve, baseFolder::relativize);
}
public static class LateBoundIdMapper<I, V> {
private final BiMap<I, V> idToValue = HashBiMap.create();
public Codec<V> codec(Codec<I> idCodec) {
BiMap<V, I> valueToId = this.idToValue.inverse();
return ExtraCodecs.idResolverCodec(idCodec, this.idToValue::get, valueToId::get);
}
public ExtraCodecs.LateBoundIdMapper<I, V> put(I id, V value) {
Objects.requireNonNull(value, () -> "Value for " + id + " is null");
this.idToValue.put(id, value);
return this;
}
public Set<V> values() {
return Collections.unmodifiableSet(this.idToValue.values());
}
}
public record StrictUnboundedMapCodec<K, V>(Codec<K> keyCodec, Codec<V> elementCodec) implements BaseMapCodec<K, V>, Codec<Map<K, V>> {
@Override
public <T> DataResult<Map<K, V>> decode(DynamicOps<T> ops, MapLike<T> input) {
com.google.common.collect.ImmutableMap.Builder<K, V> read = ImmutableMap.builder();
for (Pair<T, T> pair : input.entries().toList()) {
DataResult<K> k = this.keyCodec().parse(ops, pair.getFirst());
DataResult<V> v = this.elementCodec().parse(ops, pair.getSecond());
DataResult<Pair<K, V>> entry = k.apply2stable(Pair::of, v);
Optional<Error<Pair<K, V>>> error = entry.error();
if (error.isPresent()) {
String errorMessage = error.get().message();
return DataResult.error(() -> k.result().isPresent() ? "Map entry '" + k.result().get() + "' : " + errorMessage : errorMessage);
}
if (!entry.result().isPresent()) {
return DataResult.error(() -> "Empty or invalid map contents are not allowed");
}
Pair<K, V> kvPair = entry.result().get();
read.put(kvPair.getFirst(), kvPair.getSecond());
}
Map<K, V> elements = read.build();
return DataResult.success(elements);
}
@Override
public <T> DataResult<Pair<Map<K, V>, T>> decode(DynamicOps<T> ops, T input) {
return ops.getMap(input).setLifecycle(Lifecycle.stable()).flatMap(map -> this.decode(ops, (MapLike<T>)map)).map(r -> Pair.of((Map<K, V>)r, input));
}
public <T> DataResult<T> encode(Map<K, V> input, DynamicOps<T> ops, T prefix) {
return this.encode(input, ops, ops.mapBuilder()).build(prefix);
}
@Override
public String toString() {
return "StrictUnboundedMapCodec[" + this.keyCodec + " -> " + this.elementCodec + "]";
}
}
public record TagOrElementLocation(Identifier id, boolean tag) {
@Override
public String toString() {
return this.decoratedId();
}
private String decoratedId() {
return this.tag ? "#" + this.id : this.id.toString();
}
}
}引用的其他类
-
- 引用位置:
返回值
- 引用位置:
-
- 引用位置:
参数/返回值
- 引用位置:
-
- 引用位置:
字段
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Identifier.isValidPath(), Identifier.read()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
ARGB.colorFromFloat()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
FileUtil.isEmptyPath()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
StringUtil.isAllowedChatCharacter(), StringUtil.isValidPlayerName()
- 引用位置:
-
- 引用位置:
方法调用 - 关联成员:
Util.fixedSize(), Util.parseAndValidateUntrustedUri()
- 引用位置:
-
- 引用位置:
字段/方法调用 - 关联成员:
Pattern.compile()
- 引用位置:
-
- 引用位置:
字段/构造调用 - 关联成员:
Property()
- 引用位置: