ExtraDataFixUtils.java

net.minecraft.util.datafix.ExtraDataFixUtils

信息

  • 全限定名:net.minecraft.util.datafix.ExtraDataFixUtils
  • 类型:public class
  • 包:net.minecraft.util.datafix
  • 源码路径:src/main/java/net/minecraft/util/datafix/ExtraDataFixUtils.java
  • 起始行号:L25
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

构造器

方法

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

public static Dynamic<?> fixBlockPos(Dynamic<?> pos) @ L26

  • 方法名:fixBlockPos
  • 源码定位:L26
  • 返回类型:Dynamic<?>
  • 修饰符:public static

参数:

  • pos: Dynamic<?>

说明:

TODO

public static Dynamic<?> fixInlineBlockPos(Dynamic<?> input, String fieldX, String fieldY, String fieldZ, String newField) @ L33

  • 方法名:fixInlineBlockPos
  • 源码定位:L33
  • 返回类型:Dynamic<?>
  • 修饰符:public static

参数:

  • input: Dynamic<?>
  • fieldX: String
  • fieldY: String
  • fieldZ: String
  • newField: String

说明:

TODO

public static Dynamic<?> createBlockPos(Dynamic<?> dynamic, int x, int y, int z) @ L45

  • 方法名:createBlockPos
  • 源码定位:L45
  • 返回类型:Dynamic<?>
  • 修饰符:public static

参数:

  • dynamic: Dynamic<?>
  • x: int
  • y: int
  • z: int

说明:

TODO

public static <T,R> Typed<R> cast(Type<R> type, Typed<T> typed) @ L49

  • 方法名:cast
  • 源码定位:L49
  • 返回类型:<T,R> Typed
  • 修饰符:public static

参数:

  • type: Type
  • typed: Typed

说明:

TODO

public static <T> Typed<T> cast(Type<T> type, Object value, DynamicOps<?> ops) @ L53

  • 方法名:cast
  • 源码定位:L53
  • 返回类型: Typed
  • 修饰符:public static

参数:

  • type: Type
  • value: Object
  • ops: DynamicOps<?>

说明:

TODO

public static Type<?> patchSubType(Type<?> type, Type<?> find, Type<?> replace) @ L57

  • 方法名:patchSubType
  • 源码定位:L57
  • 返回类型:Type<?>
  • 修饰符:public static

参数:

  • type: Type<?>
  • find: Type<?>
  • replace: Type<?>

说明:

TODO

private static <A,B> TypeRewriteRule typePatcher(Type<A> inputEntityType, Type<B> outputEntityType) @ L61

  • 方法名:typePatcher
  • 源码定位:L61
  • 返回类型:<A,B> TypeRewriteRule
  • 修饰符:private static

参数:

说明:

TODO

public static <T> Function<Typed<?>,Typed<?>> chainAllFilters(Function<Typed<?>,Typed<?>>... fixers) @ L68

  • 方法名:chainAllFilters
  • 源码定位:L68
  • 返回类型: Function<Typed,Typed>
  • 修饰符:public static

参数:

  • fixers: Function<Typed,Typed>…

说明:

TODO

public static Dynamic<?> blockState(String id, Map<String,String> properties) @ L79

  • 方法名:blockState
  • 源码定位:L79
  • 返回类型:Dynamic<?>
  • 修饰符:public static

参数:

  • id: String
  • properties: Map<String,String>

说明:

TODO

public static Dynamic<?> blockState(String id) @ L96

  • 方法名:blockState
  • 源码定位:L96
  • 返回类型:Dynamic<?>
  • 修饰符:public static

参数:

  • id: String

说明:

TODO

public static Dynamic<?> fixStringField(Dynamic<?> dynamic, String fieldName, UnaryOperator<String> fix) @ L100

  • 方法名:fixStringField
  • 源码定位:L100
  • 返回类型:Dynamic<?>
  • 修饰符:public static

参数:

  • dynamic: Dynamic<?>
  • fieldName: String
  • fix: UnaryOperator

说明:

TODO

public static String dyeColorIdToName(int id) @ L104

  • 方法名:dyeColorIdToName
  • 源码定位:L104
  • 返回类型:String
  • 修饰符:public static

参数:

  • id: int

说明:

TODO

public static <T> Typed<?> readAndSet(Typed<?> target, OpticFinder<T> optic, Dynamic<?> value) @ L125

  • 方法名:readAndSet
  • 源码定位:L125
  • 返回类型: Typed<?>
  • 修饰符:public static

参数:

  • target: Typed<?>
  • optic: OpticFinder
  • value: Dynamic<?>

说明:

TODO

代码

public class ExtraDataFixUtils {
    public static Dynamic<?> fixBlockPos(Dynamic<?> pos) {
        Optional<Number> x = pos.get("X").asNumber().result();
        Optional<Number> y = pos.get("Y").asNumber().result();
        Optional<Number> z = pos.get("Z").asNumber().result();
        return !x.isEmpty() && !y.isEmpty() && !z.isEmpty() ? createBlockPos(pos, x.get().intValue(), y.get().intValue(), z.get().intValue()) : pos;
    }
 
    public static Dynamic<?> fixInlineBlockPos(Dynamic<?> input, String fieldX, String fieldY, String fieldZ, String newField) {
        Optional<Number> x = input.get(fieldX).asNumber().result();
        Optional<Number> y = input.get(fieldY).asNumber().result();
        Optional<Number> z = input.get(fieldZ).asNumber().result();
        return !x.isEmpty() && !y.isEmpty() && !z.isEmpty()
            ? input.remove(fieldX)
                .remove(fieldY)
                .remove(fieldZ)
                .set(newField, createBlockPos(input, x.get().intValue(), y.get().intValue(), z.get().intValue()))
            : input;
    }
 
    public static Dynamic<?> createBlockPos(Dynamic<?> dynamic, int x, int y, int z) {
        return dynamic.createIntList(IntStream.of(x, y, z));
    }
 
    public static <T, R> Typed<R> cast(Type<R> type, Typed<T> typed) {
        return new Typed<>(type, typed.getOps(), (R)typed.getValue());
    }
 
    public static <T> Typed<T> cast(Type<T> type, Object value, DynamicOps<?> ops) {
        return new Typed<>(type, ops, (T)value);
    }
 
    public static Type<?> patchSubType(Type<?> type, Type<?> find, Type<?> replace) {
        return type.all(typePatcher(find, replace), true, false).view().newType();
    }
 
    private static <A, B> TypeRewriteRule typePatcher(Type<A> inputEntityType, Type<B> outputEntityType) {
        RewriteResult<A, B> view = RewriteResult.create(View.create("Patcher", inputEntityType, outputEntityType, ops -> a -> {
            throw new UnsupportedOperationException();
        }), new BitSet());
        return TypeRewriteRule.everywhere(TypeRewriteRule.ifSame(inputEntityType, view), PointFreeRule.nop(), true, true);
    }
 
    @SafeVarargs
    public static <T> Function<Typed<?>, Typed<?>> chainAllFilters(Function<Typed<?>, Typed<?>>... fixers) {
        return typed -> {
            for (Function<Typed<?>, Typed<?>> fixer : fixers) {
                typed = fixer.apply(typed);
            }
 
            return typed;
        };
    }
 
    public static Dynamic<?> blockState(String id, Map<String, String> properties) {
        Dynamic<Tag> dynamic = new Dynamic<>(NbtOps.INSTANCE, new CompoundTag());
        Dynamic<Tag> blockState = dynamic.set("Name", dynamic.createString(id));
        if (!properties.isEmpty()) {
            blockState = blockState.set(
                "Properties",
                dynamic.createMap(
                    properties.entrySet()
                        .stream()
                        .collect(Collectors.toMap(entry -> dynamic.createString(entry.getKey()), entry -> dynamic.createString(entry.getValue())))
                )
            );
        }
 
        return blockState;
    }
 
    public static Dynamic<?> blockState(String id) {
        return blockState(id, Map.of());
    }
 
    public static Dynamic<?> fixStringField(Dynamic<?> dynamic, String fieldName, UnaryOperator<String> fix) {
        return dynamic.update(fieldName, field -> DataFixUtils.orElse(field.asString().map(fix).map(dynamic::createString).result(), field));
    }
 
    public static String dyeColorIdToName(int id) {
        return switch (id) {
            case 1 -> "orange";
            case 2 -> "magenta";
            case 3 -> "light_blue";
            case 4 -> "yellow";
            case 5 -> "lime";
            case 6 -> "pink";
            case 7 -> "gray";
            case 8 -> "light_gray";
            case 9 -> "cyan";
            case 10 -> "purple";
            case 11 -> "blue";
            case 12 -> "brown";
            case 13 -> "green";
            case 14 -> "red";
            case 15 -> "black";
            default -> "white";
        };
    }
 
    public static <T> Typed<?> readAndSet(Typed<?> target, OpticFinder<T> optic, Dynamic<?> value) {
        return target.set(optic, Util.readTypedOrThrow(optic.type(), value, true));
    }
}

引用的其他类

  • CompoundTag

    • 引用位置: 构造调用
    • 关联成员: CompoundTag()
  • Util

    • 引用位置: 方法调用
    • 关联成员: Util.readTypedOrThrow()
  • ResolvableProfile

    • 引用位置: 参数/返回值