ReorganizePoi.java

net.minecraft.util.datafix.fixes.ReorganizePoi

信息

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

    TODO

字段/常量

内部类/嵌套类型

构造器

public ReorganizePoi(Schema outputSchema, boolean changesType) @ L17

  • 构造器名:ReorganizePoi
  • 源码定位:L17
  • 修饰符:public

参数:

  • outputSchema: Schema
  • changesType: boolean

说明:

TODO

方法

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

protected TypeRewriteRule makeRule() @ L21

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

参数:

说明:

TODO

private static <T> Dynamic<T> cap(Dynamic<T> input) @ L31

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

参数:

  • input: Dynamic

说明:

TODO

代码

public class ReorganizePoi extends DataFix {
    public ReorganizePoi(Schema outputSchema, boolean changesType) {
        super(outputSchema, changesType);
    }
 
    @Override
    protected TypeRewriteRule makeRule() {
        Type<Pair<String, Dynamic<?>>> poiChunkType = DSL.named(References.POI_CHUNK.typeName(), DSL.remainderType());
        if (!Objects.equals(poiChunkType, this.getInputSchema().getType(References.POI_CHUNK))) {
            throw new IllegalStateException("Poi type is not what was expected.");
        } else {
            return this.fixTypeEverywhere("POI reorganization", poiChunkType, ops -> input -> input.mapSecond(ReorganizePoi::cap));
        }
    }
 
    private static <T> Dynamic<T> cap(Dynamic<T> input) {
        Map<Dynamic<T>, Dynamic<T>> sections = Maps.newHashMap();
 
        for (int i = 0; i < 16; i++) {
            String key = String.valueOf(i);
            Optional<Dynamic<T>> section = input.get(key).result();
            if (section.isPresent()) {
                Dynamic<T> sectionRecords = section.get();
                Dynamic<T> newSection = input.createMap(ImmutableMap.of(input.createString("Records"), sectionRecords));
                sections.put(input.createString(Integer.toString(i)), newSection);
                input = input.remove(key);
            }
        }
 
        return input.set("Sections", input.createMap(sections));
    }
}

引用的其他类