FeatureFlagRemoveFix.java

net.minecraft.util.datafix.fixes.FeatureFlagRemoveFix

信息

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

    TODO

字段/常量

  • name

    • 类型: String
    • 修饰符: private final
    • 源码定位: L16
    • 说明:

      TODO

  • flagsToRemove

    • 类型: Set<String>
    • 修饰符: private final
    • 源码定位: L17
    • 说明:

      TODO

内部类/嵌套类型

构造器

public FeatureFlagRemoveFix(Schema outputSchema, String name, Set<String> flagsToRemove) @ L19

  • 构造器名:FeatureFlagRemoveFix
  • 源码定位:L19
  • 修饰符:public

参数:

  • outputSchema: Schema
  • name: String
  • flagsToRemove: Set

说明:

TODO

方法

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

protected TypeRewriteRule makeRule() @ L25

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

参数:

说明:

TODO

private <T> Dynamic<T> fixTag(Dynamic<T> tag) @ L32

  • 方法名:fixTag
  • 源码定位:L32
  • 返回类型: Dynamic
  • 修饰符:private

参数:

  • tag: Dynamic

说明:

TODO

代码

public class FeatureFlagRemoveFix extends DataFix {
    private final String name;
    private final Set<String> flagsToRemove;
 
    public FeatureFlagRemoveFix(Schema outputSchema, String name, Set<String> flagsToRemove) {
        super(outputSchema, false);
        this.name = name;
        this.flagsToRemove = flagsToRemove;
    }
 
    @Override
    protected TypeRewriteRule makeRule() {
        return this.fixTypeEverywhereTyped(
            this.name, this.getInputSchema().getType(References.LIGHTWEIGHT_LEVEL), input -> input.update(DSL.remainderFinder(), this::fixTag)
        );
    }
 
    private <T> Dynamic<T> fixTag(Dynamic<T> tag) {
        List<Dynamic<T>> inactiveFeatures = tag.get("removed_features").asStream().collect(Collectors.toCollection(ArrayList::new));
        Dynamic<T> result = tag.update("enabled_features", features -> DataFixUtils.orElse(features.asStreamOpt().result().map(s -> s.filter(feature -> {
            Optional<String> asString = feature.asString().result();
            if (asString.isEmpty()) {
                return true;
            } else {
                boolean shouldRemove = this.flagsToRemove.contains(asString.get());
                if (shouldRemove) {
                    inactiveFeatures.add(tag.createString(asString.get()));
                }
 
                return !shouldRemove;
            }
        })).map(tag::createList), features));
        if (!inactiveFeatures.isEmpty()) {
            result = result.set("removed_features", tag.createList(inactiveFeatures.stream()));
        }
 
        return result;
    }
}

引用的其他类