DatapackStructureReport.java

net.minecraft.data.info.DatapackStructureReport

信息

  • 全限定名:net.minecraft.data.info.DatapackStructureReport
  • 类型:public class
  • 包:net.minecraft.data.info
  • 源码路径:src/main/java/net/minecraft/data/info/DatapackStructureReport.java
  • 起始行号:L22
  • 实现:DataProvider
  • 职责:

    TODO

字段/常量

  • output

    • 类型: PackOutput
    • 修饰符: private final
    • 源码定位: L23
    • 说明:

      TODO

  • PSEUDO_REGISTRY

    • 类型: DatapackStructureReport.Entry
    • 修饰符: private static final
    • 源码定位: L24
    • 说明:

      TODO

  • STABLE_DYNAMIC_REGISTRY

    • 类型: DatapackStructureReport.Entry
    • 修饰符: private static final
    • 源码定位: L25
    • 说明:

      TODO

  • UNSTABLE_DYNAMIC_REGISTRY

    • 类型: DatapackStructureReport.Entry
    • 修饰符: private static final
    • 源码定位: L26
    • 说明:

      TODO

  • BUILT_IN_REGISTRY

    • 类型: DatapackStructureReport.Entry
    • 修饰符: private static final
    • 源码定位: L27
    • 说明:

      TODO

  • MANUAL_ENTRIES

    • 类型: Map<ResourceKey<?extends Registry<?>>,DatapackStructureReport.Entry>
    • 修饰符: private static final
    • 源码定位: L28
    • 说明:

      TODO

  • NON_REGISTRY_ENTRIES

    • 类型: Map<String,DatapackStructureReport.CustomPackEntry>
    • 修饰符: private static final
    • 源码定位: L40
    • 说明:

      TODO

  • REGISTRY_KEY_CODEC

    • 类型: Codec<ResourceKey<?extends Registry<?>>>
    • 修饰符: private static final
    • 源码定位: L46
    • 说明:

      TODO

内部类/嵌套类型

  • net.minecraft.data.info.DatapackStructureReport.CustomPackEntry

    • 类型: record
    • 修饰符: private
    • 源码定位: L85
    • 说明:

      TODO

  • net.minecraft.data.info.DatapackStructureReport.Entry

    • 类型: record
    • 修饰符: private
    • 源码定位: L95
    • 说明:

      TODO

  • net.minecraft.data.info.DatapackStructureReport.Format

    • 类型: enum
    • 修饰符: private static
    • 源码定位: L107
    • 说明:

      TODO

  • net.minecraft.data.info.DatapackStructureReport.Report

    • 类型: record
    • 修饰符: private
    • 源码定位: L124
    • 说明:

      TODO

构造器

public DatapackStructureReport(PackOutput output) @ L49

  • 构造器名:DatapackStructureReport
  • 源码定位:L49
  • 修饰符:public

参数:

  • output: PackOutput

说明:

TODO

方法

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

public CompletableFuture<?> run(CachedOutput cache) @ L53

  • 方法名:run
  • 源码定位:L53
  • 返回类型:CompletableFuture<?>
  • 修饰符:public

参数:

  • cache: CachedOutput

说明:

TODO

public String getName() @ L60

  • 方法名:getName
  • 源码定位:L60
  • 返回类型:String
  • 修饰符:public

参数:

说明:

TODO

private void putIfNotPresent(Map<ResourceKey<?extends Registry<?>>,DatapackStructureReport.Entry> output, ResourceKey<?extends Registry<?>> key, DatapackStructureReport.Entry entry) @ L65

  • 方法名:putIfNotPresent
  • 源码定位:L65
  • 返回类型:void
  • 修饰符:private

参数:

  • output: Map<ResourceKey>,DatapackStructureReport.Entry>
  • key: ResourceKey>
  • entry: DatapackStructureReport.Entry

说明:

TODO

private Map<ResourceKey<?extends Registry<?>>,DatapackStructureReport.Entry> listRegistries() @ L76

  • 方法名:listRegistries
  • 源码定位:L76
  • 返回类型:Map<ResourceKey>,DatapackStructureReport.Entry>
  • 修饰符:private

参数:

说明:

TODO

代码

public class DatapackStructureReport implements DataProvider {
    private final PackOutput output;
    private static final DatapackStructureReport.Entry PSEUDO_REGISTRY = new DatapackStructureReport.Entry(true, false, true);
    private static final DatapackStructureReport.Entry STABLE_DYNAMIC_REGISTRY = new DatapackStructureReport.Entry(true, true, true);
    private static final DatapackStructureReport.Entry UNSTABLE_DYNAMIC_REGISTRY = new DatapackStructureReport.Entry(true, true, false);
    private static final DatapackStructureReport.Entry BUILT_IN_REGISTRY = new DatapackStructureReport.Entry(false, true, true);
    private static final Map<ResourceKey<? extends Registry<?>>, DatapackStructureReport.Entry> MANUAL_ENTRIES = Map.of(
        Registries.RECIPE,
        PSEUDO_REGISTRY,
        Registries.ADVANCEMENT,
        PSEUDO_REGISTRY,
        Registries.LOOT_TABLE,
        STABLE_DYNAMIC_REGISTRY,
        Registries.ITEM_MODIFIER,
        STABLE_DYNAMIC_REGISTRY,
        Registries.PREDICATE,
        STABLE_DYNAMIC_REGISTRY
    );
    private static final Map<String, DatapackStructureReport.CustomPackEntry> NON_REGISTRY_ENTRIES = Map.of(
        "structure",
        new DatapackStructureReport.CustomPackEntry(DatapackStructureReport.Format.STRUCTURE, new DatapackStructureReport.Entry(true, false, true)),
        "function",
        new DatapackStructureReport.CustomPackEntry(DatapackStructureReport.Format.MCFUNCTION, new DatapackStructureReport.Entry(true, true, true))
    );
    private static final Codec<ResourceKey<? extends Registry<?>>> REGISTRY_KEY_CODEC = Identifier.CODEC
        .xmap(ResourceKey::createRegistryKey, ResourceKey::identifier);
 
    public DatapackStructureReport(PackOutput output) {
        this.output = output;
    }
 
    @Override
    public CompletableFuture<?> run(CachedOutput cache) {
        DatapackStructureReport.Report report = new DatapackStructureReport.Report(this.listRegistries(), NON_REGISTRY_ENTRIES);
        Path path = this.output.getOutputFolder(PackOutput.Target.REPORTS).resolve("datapack.json");
        return DataProvider.saveStable(cache, DatapackStructureReport.Report.CODEC.encodeStart(JsonOps.INSTANCE, report).getOrThrow(), path);
    }
 
    @Override
    public String getName() {
        return "Datapack Structure";
    }
 
    private void putIfNotPresent(
        Map<ResourceKey<? extends Registry<?>>, DatapackStructureReport.Entry> output,
        ResourceKey<? extends Registry<?>> key,
        DatapackStructureReport.Entry entry
    ) {
        DatapackStructureReport.Entry previous = output.putIfAbsent(key, entry);
        if (previous != null) {
            throw new IllegalStateException("Duplicate entry for key " + key.identifier());
        }
    }
 
    private Map<ResourceKey<? extends Registry<?>>, DatapackStructureReport.Entry> listRegistries() {
        Map<ResourceKey<? extends Registry<?>>, DatapackStructureReport.Entry> result = new HashMap<>();
        BuiltInRegistries.REGISTRY.forEach(entry -> this.putIfNotPresent(result, entry.key(), BUILT_IN_REGISTRY));
        RegistryDataLoader.WORLDGEN_REGISTRIES.forEach(entry -> this.putIfNotPresent(result, entry.key(), UNSTABLE_DYNAMIC_REGISTRY));
        RegistryDataLoader.DIMENSION_REGISTRIES.forEach(entry -> this.putIfNotPresent(result, entry.key(), UNSTABLE_DYNAMIC_REGISTRY));
        MANUAL_ENTRIES.forEach((key, entry) -> this.putIfNotPresent(result, (ResourceKey<? extends Registry<?>>)key, entry));
        return result;
    }
 
    private record CustomPackEntry(DatapackStructureReport.Format format, DatapackStructureReport.Entry entry) {
        public static final Codec<DatapackStructureReport.CustomPackEntry> CODEC = RecordCodecBuilder.create(
            i -> i.group(
                    DatapackStructureReport.Format.CODEC.fieldOf("format").forGetter(DatapackStructureReport.CustomPackEntry::format),
                    DatapackStructureReport.Entry.MAP_CODEC.forGetter(DatapackStructureReport.CustomPackEntry::entry)
                )
                .apply(i, DatapackStructureReport.CustomPackEntry::new)
        );
    }
 
    private record Entry(boolean elements, boolean tags, boolean stable) {
        public static final MapCodec<DatapackStructureReport.Entry> MAP_CODEC = RecordCodecBuilder.mapCodec(
            i -> i.group(
                    Codec.BOOL.fieldOf("elements").forGetter(DatapackStructureReport.Entry::elements),
                    Codec.BOOL.fieldOf("tags").forGetter(DatapackStructureReport.Entry::tags),
                    Codec.BOOL.fieldOf("stable").forGetter(DatapackStructureReport.Entry::stable)
                )
                .apply(i, DatapackStructureReport.Entry::new)
        );
        public static final Codec<DatapackStructureReport.Entry> CODEC = MAP_CODEC.codec();
    }
 
    private static enum Format implements StringRepresentable {
        STRUCTURE("structure"),
        MCFUNCTION("mcfunction");
 
        public static final Codec<DatapackStructureReport.Format> CODEC = StringRepresentable.fromEnum(DatapackStructureReport.Format::values);
        private final String name;
 
        private Format(String name) {
            this.name = name;
        }
 
        @Override
        public String getSerializedName() {
            return this.name;
        }
    }
 
    private record Report(
        Map<ResourceKey<? extends Registry<?>>, DatapackStructureReport.Entry> registries, Map<String, DatapackStructureReport.CustomPackEntry> others
    ) {
        public static final Codec<DatapackStructureReport.Report> CODEC = RecordCodecBuilder.create(
            i -> i.group(
                    Codec.unboundedMap(DatapackStructureReport.REGISTRY_KEY_CODEC, DatapackStructureReport.Entry.CODEC)
                        .fieldOf("registries")
                        .forGetter(DatapackStructureReport.Report::registries),
                    Codec.unboundedMap(Codec.STRING, DatapackStructureReport.CustomPackEntry.CODEC)
                        .fieldOf("others")
                        .forGetter(DatapackStructureReport.Report::others)
                )
                .apply(i, DatapackStructureReport.Report::new)
        );
    }
}

引用的其他类