RegistriesDatapackGenerator.java

net.minecraft.data.registries.RegistriesDatapackGenerator

信息

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

    TODO

字段/常量

  • output

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

      TODO

  • registries

    • 类型: CompletableFuture<HolderLookup.Provider>
    • 修饰符: private final
    • 源码定位: L20
    • 说明:

      TODO

内部类/嵌套类型

构造器

public RegistriesDatapackGenerator(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) @ L22

  • 构造器名:RegistriesDatapackGenerator
  • 源码定位:L22
  • 修饰符:public

参数:

  • output: PackOutput
  • registries: CompletableFuture<HolderLookup.Provider>

说明:

TODO

方法

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

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

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

参数:

  • cache: CachedOutput

说明:

TODO

private <T> Optional<CompletableFuture<?>> dumpRegistryCap(CachedOutput cache, HolderLookup.Provider registries, DynamicOps<JsonElement> writeOps, RegistryDataLoader.RegistryData<T> v) @ L43

  • 方法名:dumpRegistryCap
  • 源码定位:L43
  • 返回类型: Optional<CompletableFuture<?>>
  • 修饰符:private

参数:

  • cache: CachedOutput
  • registries: HolderLookup.Provider
  • writeOps: DynamicOps
  • v: RegistryDataLoader.RegistryData

说明:

TODO

private static <E> CompletableFuture<?> dumpValue(Path path, CachedOutput cache, DynamicOps<JsonElement> ops, Encoder<E> codec, E value) @ L60

  • 方法名:dumpValue
  • 源码定位:L60
  • 返回类型: CompletableFuture<?>
  • 修饰符:private static

参数:

  • path: Path
  • cache: CachedOutput
  • ops: DynamicOps
  • codec: Encoder
  • value: E

说明:

TODO

public final String getName() @ L68

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

参数:

说明:

TODO

代码

public class RegistriesDatapackGenerator implements DataProvider {
    private final PackOutput output;
    private final CompletableFuture<HolderLookup.Provider> registries;
 
    public RegistriesDatapackGenerator(PackOutput output, CompletableFuture<HolderLookup.Provider> registries) {
        this.registries = registries;
        this.output = output;
    }
 
    @Override
    public CompletableFuture<?> run(CachedOutput cache) {
        return this.registries
            .thenCompose(
                access -> {
                    DynamicOps<JsonElement> registryOps = access.createSerializationContext(JsonOps.INSTANCE);
                    return CompletableFuture.allOf(
                        RegistryDataLoader.WORLDGEN_REGISTRIES
                            .stream()
                            .flatMap(v -> this.dumpRegistryCap(cache, access, registryOps, (RegistryDataLoader.RegistryData<?>)v).stream())
                            .toArray(CompletableFuture[]::new)
                    );
                }
            );
    }
 
    private <T> Optional<CompletableFuture<?>> dumpRegistryCap(
        CachedOutput cache, HolderLookup.Provider registries, DynamicOps<JsonElement> writeOps, RegistryDataLoader.RegistryData<T> v
    ) {
        ResourceKey<? extends Registry<T>> registryKey = v.key();
        return registries.lookup(registryKey)
            .map(
                registry -> {
                    PackOutput.PathProvider pathProvider = this.output.createRegistryElementsPathProvider(registryKey);
                    return CompletableFuture.allOf(
                        registry.listElements()
                            .<CompletableFuture<?>>map(e -> dumpValue(pathProvider.json(e.key().identifier()), cache, writeOps, v.elementCodec(), e.value()))
                            .toArray(CompletableFuture[]::new)
                    );
                }
            );
    }
 
    private static <E> CompletableFuture<?> dumpValue(Path path, CachedOutput cache, DynamicOps<JsonElement> ops, Encoder<E> codec, E value) {
        return codec.encodeStart(ops, value)
            .mapOrElse(
                result -> DataProvider.saveStable(cache, result, path),
                error -> CompletableFuture.failedFuture(new IllegalStateException("Couldn't generate file '" + path + "': " + error.message()))
            );
    }
 
    @Override
    public final String getName() {
        return "Registries";
    }
}

引用的其他类