| 1 | package net.minecraft.data.info;
|
| 2 |
|
| 3 | import com.google.gson.JsonElement;
|
| 4 | import com.google.gson.JsonObject;
|
| 5 | import java.nio.file.Path;
|
| 6 | import java.util.concurrent.CompletableFuture;
|
| 7 | import net.minecraft.core.DefaultedRegistry;
|
| 8 | import net.minecraft.core.Registry;
|
| 9 | import net.minecraft.core.registries.BuiltInRegistries;
|
| 10 | import net.minecraft.data.CachedOutput;
|
| 11 | import net.minecraft.data.DataProvider;
|
| 12 | import net.minecraft.data.PackOutput;
|
| 13 | import net.minecraft.resources.Identifier;
|
| 14 |
|
| 15 | /**
|
| 16 | * Access widened by fabric-data-generation-api-v1 to extendable
|
| 17 | */
|
| 18 | public class RegistryDumpReport implements DataProvider {
|
| 19 | private final PackOutput output;
|
| 20 |
|
| 21 | public RegistryDumpReport(final PackOutput output) {
|
| 22 | this.output = output;
|
| 23 | }
|
| 24 |
|
| 25 | @Override
|
| 26 | public CompletableFuture<?> run(final CachedOutput cache) {
|
| 27 | JsonObject root = new JsonObject();
|
| 28 | BuiltInRegistries.REGISTRY.listElements().forEach(e -> root.add(e.key().identifier().toString(), dumpRegistry((Registry<?>)e.value())));
|
| 29 | Path path = this.output.getOutputFolder(PackOutput.Target.REPORTS).resolve("registries.json");
|
| 30 | return DataProvider.saveStable(cache, root, path);
|
| 31 | }
|
| 32 |
|
| 33 | private static <T> JsonElement dumpRegistry(final Registry<T> registry) {
|
| 34 | JsonObject result = new JsonObject();
|
| 35 | if (registry instanceof DefaultedRegistry) {
|
| 36 | Identifier defaultKey = ((DefaultedRegistry)registry).getDefaultKey();
|
| 37 | result.addProperty("default", defaultKey.toString());
|
| 38 | }
|
| 39 |
|
| 40 | int registryId = BuiltInRegistries.REGISTRY.getId(registry);
|
| 41 | result.addProperty("protocol_id", registryId);
|
| 42 | JsonObject entries = new JsonObject();
|
| 43 | registry.listElements().forEach(holder -> {
|
| 44 | T value = holder.value();
|
| 45 | int protocolId = registry.getId(value);
|
| 46 | JsonObject entry = new JsonObject();
|
| 47 | entry.addProperty("protocol_id", protocolId);
|
| 48 | entries.add(holder.key().identifier().toString(), entry);
|
| 49 | });
|
| 50 | result.add("entries", entries);
|
| 51 | return result;
|
| 52 | }
|
| 53 |
|
| 54 | /**
|
| 55 | * Access widened by fabric-data-generation-api-v1 to extendable
|
| 56 | */
|
| 57 | @Override
|
| 58 | public String getName() {
|
| 59 | return "Registry Dump";
|
| 60 | }
|
| 61 | }
|
| 62 |
|