Write all entries from BCL_BIOMES_REGISTRY
in DataGen
This commit is contained in:
parent
b322453889
commit
8fdcef7986
4 changed files with 141 additions and 8 deletions
|
@ -22,7 +22,7 @@ public class BCLibDatagen implements DataGeneratorEntrypoint {
|
|||
pack.addProvider(WorldgenProvider::new);
|
||||
//pack.addProvider(BiomeProvider::new);
|
||||
//pack.addProvider(new BiomeProvider());
|
||||
//pack.addProvider(CustomRegistriesDataProvider::new);
|
||||
pack.addProvider(CustomRegistriesDataProvider::new);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -31,8 +31,8 @@ public class BCLibDatagen implements DataGeneratorEntrypoint {
|
|||
if (ADD_TESTS) {
|
||||
registryBuilder.add(Registries.CONFIGURED_FEATURE, TestConfiguredFeatures::bootstrap);
|
||||
registryBuilder.add(Registries.PLACED_FEATURE, TestPlacedFeatures::bootstrap);
|
||||
registryBuilder.add(Registries.BIOME, TestBiomes::bootstrap);
|
||||
}
|
||||
registryBuilder.add(Registries.BIOME, TestBiomes::bootstrap);
|
||||
registryBuilder.add(Registries.NOISE_SETTINGS, NoiseDatagen::bootstrap);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,132 @@
|
|||
package org.betterx.bclib.datagen;
|
||||
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeData;
|
||||
import org.betterx.worlds.together.WorldsTogether;
|
||||
import org.betterx.worlds.together.surfaceRules.AssignedSurfaceRule;
|
||||
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
|
||||
|
||||
import com.mojang.serialization.DynamicOps;
|
||||
import com.mojang.serialization.Encoder;
|
||||
import com.mojang.serialization.JsonOps;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.CachedOutput;
|
||||
import net.minecraft.data.DataProvider;
|
||||
import net.minecraft.data.PackOutput;
|
||||
import net.minecraft.data.registries.VanillaRegistries;
|
||||
import net.minecraft.resources.RegistryDataLoader;
|
||||
import net.minecraft.resources.RegistryOps;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
|
||||
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
|
||||
|
||||
import com.google.gson.JsonElement;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.concurrent.CompletableFuture;
|
||||
|
||||
public class CustomRegistriesDataProvider implements DataProvider {
|
||||
public static final List<RegistryDataLoader.RegistryData<?>> REGISTRIES = List.of(
|
||||
new RegistryDataLoader.RegistryData<>(BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC),
|
||||
new RegistryDataLoader.RegistryData<>(
|
||||
SurfaceRuleRegistry.SURFACE_RULES_REGISTRY,
|
||||
AssignedSurfaceRule.CODEC
|
||||
)
|
||||
// new RegistryDataLoader.RegistryData<>(Registries.BIOME, Biome.DIRECT_CODEC),
|
||||
// new RegistryDataLoader.RegistryData<>(Registries.CONFIGURED_FEATURE, ConfiguredFeature.DIRECT_CODEC),
|
||||
// new RegistryDataLoader.RegistryData<>(Registries.PLACED_FEATURE, PlacedFeature.DIRECT_CODEC),
|
||||
// new RegistryDataLoader.RegistryData<>(Registries.STRUCTURE, Structure.DIRECT_CODEC)
|
||||
);
|
||||
|
||||
|
||||
private final PackOutput output;
|
||||
|
||||
public CustomRegistriesDataProvider(FabricDataOutput generator) {
|
||||
this.output = generator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompletableFuture<?> run(CachedOutput cachedOutput) {
|
||||
HolderLookup.Provider registryAccess = VanillaRegistries.createLookup();
|
||||
RegistryOps<JsonElement> dynamicOps = RegistryOps.create(JsonOps.INSTANCE, registryAccess);
|
||||
final List<CompletableFuture<?>> futures = new ArrayList<>();
|
||||
|
||||
for (RegistryDataLoader.RegistryData<?> registryData : REGISTRIES) {
|
||||
futures.add(this.dumpRegistryCapFuture(
|
||||
cachedOutput,
|
||||
registryAccess,
|
||||
dynamicOps,
|
||||
(RegistryDataLoader.RegistryData) registryData
|
||||
));
|
||||
}
|
||||
return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
|
||||
}
|
||||
|
||||
private <T> CompletableFuture dumpRegistryCapFuture(
|
||||
CachedOutput cachedOutput,
|
||||
HolderLookup.Provider registryAccess,
|
||||
DynamicOps<JsonElement> dynamicOps,
|
||||
RegistryDataLoader.RegistryData<T> registryData
|
||||
) {
|
||||
return CompletableFuture.runAsync(() -> dumpRegistryCap(
|
||||
cachedOutput,
|
||||
registryAccess,
|
||||
dynamicOps,
|
||||
registryData
|
||||
));
|
||||
}
|
||||
|
||||
private <T> void dumpRegistryCap(
|
||||
CachedOutput cachedOutput,
|
||||
HolderLookup.Provider registryAccess,
|
||||
DynamicOps<JsonElement> dynamicOps,
|
||||
RegistryDataLoader.RegistryData<T> registryData
|
||||
) {
|
||||
ResourceKey<? extends Registry<T>> resourceKey = registryData.key();
|
||||
|
||||
HolderLookup.RegistryLookup<T> registry = registryAccess.lookupOrThrow(resourceKey);
|
||||
PackOutput.PathProvider pathProvider = this.output.createPathProvider(
|
||||
PackOutput.Target.DATA_PACK,
|
||||
resourceKey.location().getPath()
|
||||
);
|
||||
registry.listElementIds().forEach(entry ->
|
||||
dumpValue(
|
||||
pathProvider.json(entry.location()),
|
||||
cachedOutput,
|
||||
dynamicOps,
|
||||
registryData.elementCodec(),
|
||||
registry.get(entry).orElseThrow().value()
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
private static <E> void dumpValue(
|
||||
Path path,
|
||||
CachedOutput cachedOutput,
|
||||
DynamicOps<JsonElement> dynamicOps,
|
||||
Encoder<E> encoder,
|
||||
E object
|
||||
) {
|
||||
|
||||
Optional<JsonElement> optional = encoder.encodeStart(dynamicOps, object)
|
||||
.resultOrPartial(string -> WorldsTogether.LOGGER.error(
|
||||
"Couldn't serialize element {}: {}",
|
||||
path,
|
||||
string
|
||||
));
|
||||
if (optional.isPresent()) {
|
||||
DataProvider.saveStable(cachedOutput, optional.get(), path);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "BCL Registries";
|
||||
}
|
||||
}
|
|
@ -1,8 +1,5 @@
|
|||
package org.betterx.bclib.datagen;
|
||||
|
||||
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
|
||||
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
|
||||
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.registries.Registries;
|
||||
|
||||
|
@ -23,8 +20,8 @@ public class WorldgenProvider extends FabricDynamicRegistryProvider {
|
|||
protected void configure(HolderLookup.Provider registries, Entries entries) {
|
||||
entries.addAll(registries.lookupOrThrow(Registries.NOISE_SETTINGS));
|
||||
entries.addAll(registries.lookupOrThrow(Registries.WORLD_PRESET));
|
||||
entries.addAll(registries.lookupOrThrow(BCLBiomeRegistry.BCL_BIOMES_REGISTRY));
|
||||
entries.addAll(registries.lookupOrThrow(SurfaceRuleRegistry.SURFACE_RULES_REGISTRY));
|
||||
//entries.addAll(registries.lookupOrThrow(BCLBiomeRegistry.BCL_BIOMES_REGISTRY));
|
||||
//entries.addAll(registries.lookupOrThrow(SurfaceRuleRegistry.SURFACE_RULES_REGISTRY));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -32,9 +32,11 @@ public class WorldPresets {
|
|||
LevelStem make(BiomeSource biomeSource, Holder<NoiseGeneratorSettings> noiseGeneratorSettings);
|
||||
}
|
||||
|
||||
private static Map<ResourceKey<WorldPreset>, PresetBuilder> BUILDERS = Maps.newHashMap();
|
||||
|
||||
public static final TagRegistry.UnTyped<WorldPreset> WORLD_PRESETS =
|
||||
TagManager.registerType(Registries.WORLD_PRESET, "tags/worldgen/world_preset");
|
||||
private static Map<ResourceKey<WorldPreset>, PresetBuilder> BUILDERS = Maps.newHashMap();
|
||||
|
||||
private static ResourceKey<WorldPreset> DEFAULT = net.minecraft.world.level.levelgen.presets.WorldPresets.NORMAL;
|
||||
|
||||
public static Holder<WorldPreset> get(RegistryAccess access, ResourceKey<WorldPreset> key) {
|
||||
|
@ -98,6 +100,8 @@ public class WorldPresets {
|
|||
HolderGetter<NoiseGeneratorSettings> noiseSettings,
|
||||
OverworldBuilder noiseBasedOverworld
|
||||
) {
|
||||
if (BUILDERS == null)
|
||||
return;
|
||||
EntrypointUtil.getCommon(WorldPresetBootstrap.class)
|
||||
.forEach(e -> e.bootstrapWorldPresets());
|
||||
|
||||
|
|
Loading…
Reference in a new issue