DebugProfileLookingAtSplitFix.java

net.minecraft.util.datafix.fixes.DebugProfileLookingAtSplitFix

信息

  • 全限定名:net.minecraft.util.datafix.fixes.DebugProfileLookingAtSplitFix
  • 类型:public class
  • 包:net.minecraft.util.datafix.fixes
  • 源码路径:src/main/java/net/minecraft/util/datafix/fixes/DebugProfileLookingAtSplitFix.java
  • 起始行号:L13
  • 继承:DataFix
  • 职责:

    TODO

字段/常量

内部类/嵌套类型

构造器

public DebugProfileLookingAtSplitFix(Schema outputSchema) @ L14

  • 构造器名:DebugProfileLookingAtSplitFix
  • 源码定位:L14
  • 修饰符:public

参数:

  • outputSchema: Schema

说明:

TODO

方法

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

public TypeRewriteRule makeRule() @ L18

  • 方法名:makeRule
  • 源码定位:L18
  • 返回类型:TypeRewriteRule
  • 修饰符:public

参数:

说明:

TODO

private static <T> Dynamic<T> updateOptions(Dynamic<T> custom) @ L27

  • 方法名:updateOptions
  • 源码定位:L27
  • 返回类型: Dynamic
  • 修饰符:private static

参数:

  • custom: Dynamic

说明:

TODO

private static <T> Optional<Dynamic<T>> renamedKey(Dynamic<T> keyDynamic) @ L47

  • 方法名:renamedKey
  • 源码定位:L47
  • 返回类型: Optional<Dynamic>
  • 修饰符:private static

参数:

  • keyDynamic: Dynamic

说明:

TODO

代码

public class DebugProfileLookingAtSplitFix extends DataFix {
    public DebugProfileLookingAtSplitFix(Schema outputSchema) {
        super(outputSchema, false);
    }
 
    @Override
    public TypeRewriteRule makeRule() {
        return this.fixTypeEverywhereTyped(
            "DebugProfileLookingAtSplitFix",
            this.getInputSchema().getType(References.DEBUG_PROFILE),
            input -> input.update(DSL.remainderFinder(), tag -> tag.update("custom", DebugProfileLookingAtSplitFix::updateOptions))
        );
    }
 
    private static <T> Dynamic<T> updateOptions(Dynamic<T> custom) {
        return DataFixUtils.orElse(
            custom.getMapValues()
                .map(
                    map -> {
                        Map<Dynamic<T>, Dynamic<T>> newOptions = new HashMap<>();
                        map.forEach(
                            (key, value) -> renamedKey((Dynamic<T>)key)
                                .ifPresentOrElse(
                                    newKey -> newOptions.putIfAbsent((Dynamic<T>)newKey, value), () -> newOptions.put((Dynamic<T>)key, (Dynamic<T>)value)
                                )
                        );
                        return custom.createMap(newOptions);
                    }
                )
                .result(),
            custom
        );
    }
 
    private static <T> Optional<Dynamic<T>> renamedKey(Dynamic<T> keyDynamic) {
        return keyDynamic.asString().result().flatMap(key -> {
            return switch (key) {
                case "minecraft:looking_at_block" -> Optional.of("minecraft:looking_at_block_state");
                case "minecraft:looking_at_fluid" -> Optional.of("minecraft:looking_at_fluid_state");
                default -> Optional.empty();
            };
        }).map(keyDynamic::createString);
    }
}

引用的其他类