Ensure registries get written after Registry Bootstrap

This commit is contained in:
Frank 2022-12-04 20:07:32 +01:00
parent ef1e899589
commit b1679114cf
9 changed files with 361 additions and 173 deletions

View file

@ -130,7 +130,9 @@ public abstract class BCLBiomeSource extends BiomeSource implements BiomeSourceW
) {
final RegistryAccess access = WorldBootstrap.getLastRegistryAccess();
if (access == null) {
if (Configs.MAIN_CONFIG.verboseLogging() && !BCLib.isDatagen()) {
BCLib.LOGGER.info("Unable to build Biome List yet");
}
return null;
}

View file

@ -5,6 +5,7 @@ import org.betterx.bclib.api.v2.generator.config.BCLEndBiomeSourceConfig;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeAPI;
import org.betterx.bclib.config.Configs;
import org.betterx.bclib.interfaces.BiomeMap;
import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig;
@ -179,19 +180,23 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
}
if (endVoidBiomePicker.isEmpty()) {
if (Configs.MAIN_CONFIG.verboseLogging() && !BCLib.isDatagen())
BCLib.LOGGER.info("No Void Biomes found. Disabling by using barrens");
endVoidBiomePicker = endBarrensBiomePicker;
}
if (endBarrensBiomePicker.isEmpty()) {
if (Configs.MAIN_CONFIG.verboseLogging() && !BCLib.isDatagen())
BCLib.LOGGER.info("No Barrens Biomes found. Disabling by using land Biomes");
endBarrensBiomePicker = endLandBiomePicker;
endVoidBiomePicker = endLandBiomePicker;
}
if (endCenterBiomePicker.isEmpty()) {
if (Configs.MAIN_CONFIG.verboseLogging() && !BCLib.isDatagen())
BCLib.LOGGER.warning("No Center Island Biomes found. Forcing use of vanilla center.");
endCenterBiomePicker.addBiome(BiomeAPI.THE_END);
endCenterBiomePicker.rebuild();
if (endCenterBiomePicker.isEmpty()) {
if (Configs.MAIN_CONFIG.verboseLogging() && !BCLib.isDatagen())
BCLib.LOGGER.error("Unable to force vanilla central Island. Falling back to land Biomes...");
endCenterBiomePicker = endLandBiomePicker;
}

View file

@ -2,162 +2,69 @@ package org.betterx.bclib.api.v3.datagen;
import org.betterx.worlds.together.util.Logger;
import com.mojang.serialization.Codec;
import com.mojang.serialization.DynamicOps;
import com.mojang.serialization.Encoder;
import com.mojang.serialization.JsonOps;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.data.CachedOutput;
import net.minecraft.data.DataProvider;
import net.minecraft.data.PackOutput;
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.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.CompletableFuture;
import org.jetbrains.annotations.Nullable;
public abstract class RegistriesDataProvider implements DataProvider {
public class InfoList extends LinkedList<RegistryInfo<?>> {
public <T> void add(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec) {
this.add(new RegistryInfo<T>(key, elementCodec));
}
public <T> void add(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, String... modIDs) {
this.add(new RegistryInfo<T>(key, elementCodec, modIDs));
}
public <T> void add(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, List<String> modIDs) {
this.add(new RegistryInfo<T>(key, elementCodec, modIDs));
}
public <T> void addUnfiltered(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec) {
this.add(new RegistryInfo<T>(key, elementCodec, RegistryInfo.UNFILTERED));
}
}
public final class RegistryInfo<T> {
public static final List<String> UNFILTERED = null;
public final RegistryDataLoader.RegistryData<T> data;
public final List<String> modIDs;
public RegistryInfo(RegistryDataLoader.RegistryData<T> data, List<String> modIDs) {
this.data = data;
this.modIDs = modIDs;
}
public RegistryInfo(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec) {
this(new RegistryDataLoader.RegistryData<>(key, elementCodec), RegistriesDataProvider.this.defaultModIDs);
}
public RegistryInfo(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, String... modIDs) {
this(new RegistryDataLoader.RegistryData<>(key, elementCodec), List.of(modIDs));
}
public RegistryInfo(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, List<String> modIDs) {
this(new RegistryDataLoader.RegistryData<>(key, elementCodec), modIDs);
}
public ResourceKey<? extends Registry<T>> key() {
return data.key();
}
public Codec<T> elementCodec() {
return data.elementCodec();
}
List<Holder<T>> allElements(HolderLookup.Provider registryAccess) {
final HolderLookup.RegistryLookup<T> registry = registryAccess.lookupOrThrow(key());
return registry
.listElementIds()
.filter(k -> modIDs == null || modIDs.isEmpty() || modIDs.contains(k.location().getNamespace()))
.map(k -> (Holder<T>) registry.get(k).orElseThrow())
.toList();
}
public RegistryDataLoader.RegistryData<T> data() {
return data;
}
public List<String> modIDs() {
return modIDs;
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (RegistryInfo) obj;
return Objects.equals(this.data, that.data) &&
Objects.equals(this.modIDs, that.modIDs);
}
@Override
public int hashCode() {
return Objects.hash(data, modIDs);
}
@Override
public String toString() {
return "RegistryInfo[" +
"data=" + data + ", " +
"modIDs=" + modIDs + ']';
}
}
protected final List<RegistryInfo<?>> registries;
protected final RegistrySupplier registries;
protected final PackOutput output;
protected final Logger LOGGER;
protected final CompletableFuture<HolderLookup.Provider> registriesFuture;
private @Nullable List<String> defaultModIDs;
protected RegistriesDataProvider(
Logger logger,
@Nullable List<String> defaultModIDs,
RegistrySupplier registries,
FabricDataOutput generator,
CompletableFuture<HolderLookup.Provider> registriesFuture
) {
this.defaultModIDs = defaultModIDs;
this.LOGGER = logger;
this.output = generator;
this.registriesFuture = registriesFuture;
this.registries = initializeRegistryList(defaultModIDs);
this.registries = registries;
}
protected abstract List<RegistryInfo<?>> initializeRegistryList(@Nullable List<String> modIDs);
@Override
public CompletableFuture<?> run(CachedOutput cachedOutput) {
LOGGER.info("Serialize Registries " + defaultModIDs);
LOGGER.info("Serialize Registries " + registries.defaultModIDs);
return registriesFuture.thenCompose(registriesProvider -> CompletableFuture
.supplyAsync(() -> registries)
.thenCompose(entries -> {
final List<CompletableFuture<?>> futures = new ArrayList<>();
futures.add(CompletableFuture.runAsync(() -> {
registries.acquireLock();
final RegistryOps<JsonElement> dynamicOps = RegistryOps.create(
JsonOps.INSTANCE,
registriesProvider
);
futures.add(CompletableFuture.runAsync(() -> {
for (RegistryInfo<?> registryData : entries) {
// futures.add(CompletableFuture.runAsync(() ->
for (RegistrySupplier.RegistryInfo<?> registryData : entries.allRegistries) {
serializeRegistry(
cachedOutput, registriesProvider, dynamicOps, registryData
);
// ));
}
registries.releaseLock();
}));
return CompletableFuture.allOf(futures.toArray(CompletableFuture[]::new));
@ -168,9 +75,10 @@ public abstract class RegistriesDataProvider implements DataProvider {
CachedOutput cachedOutput,
HolderLookup.Provider registryAccess,
DynamicOps<JsonElement> dynamicOps,
RegistryInfo<T> registryData
RegistrySupplier.RegistryInfo<T> registryData
) {
final List<Holder<T>> elements = registryData.allElements(registryAccess);
LOGGER.info("Serializing " + elements.size() + " elements from " + registryData.data.key());
if (!elements.isEmpty()) {
PackOutput.PathProvider pathProvider = this.output.createPathProvider(
@ -188,7 +96,6 @@ public abstract class RegistriesDataProvider implements DataProvider {
)
);
}
}
private <E> void serializeElements(
@ -207,7 +114,15 @@ public abstract class RegistriesDataProvider implements DataProvider {
if (optional.isPresent()) {
DataProvider.saveStable(cachedOutput, optional.get(), path);
}
}
public void buildRegistry(RegistrySetBuilder registryBuilder) {
registries.allRegistries
.stream()
.filter(nfo -> nfo.registryBootstrap != null)
.forEach(nfo -> {
});
}
@Override

View file

@ -0,0 +1,246 @@
package org.betterx.bclib.api.v3.datagen;
import com.mojang.serialization.Codec;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.resources.RegistryDataLoader;
import net.minecraft.resources.ResourceKey;
import java.util.LinkedList;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.Semaphore;
import org.jetbrains.annotations.Nullable;
public abstract class RegistrySupplier {
private static final int MAX_PERMITS = 1000;
private final Semaphore BOOTSTRAP_LOCK = new Semaphore(MAX_PERMITS);
final List<RegistrySupplier.RegistryInfo<?>> allRegistries;
@Nullable List<String> defaultModIDs;
protected RegistrySupplier(
@Nullable List<String> defaultModIDs
) {
this.defaultModIDs = defaultModIDs;
this.allRegistries = initializeRegistryList(defaultModIDs);
}
protected abstract List<RegistrySupplier.RegistryInfo<?>> initializeRegistryList(@Nullable List<String> modIDs);
public void bootstrapRegistries(RegistrySetBuilder registryBuilder) {
for (RegistrySupplier.RegistryInfo<?> nfo : allRegistries) {
if (nfo.registryBootstrap != null) {
nfo.add(registryBuilder, BOOTSTRAP_LOCK);
}
}
}
void acquireLock() {
try {
BOOTSTRAP_LOCK.acquire(MAX_PERMITS);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
void releaseLock() {
BOOTSTRAP_LOCK.release(MAX_PERMITS);
}
public class InfoList extends LinkedList<RegistrySupplier.RegistryInfo<?>> {
public <T> void add(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec) {
this.add(new RegistrySupplier.RegistryInfo<T>(key, elementCodec));
}
public <T> void add(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, String... modIDs) {
this.add(new RegistrySupplier.RegistryInfo<T>(key, elementCodec, modIDs));
}
public <T> void add(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, List<String> modIDs) {
this.add(new RegistrySupplier.RegistryInfo<T>(key, elementCodec, modIDs));
}
public <T> void addUnfiltered(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec) {
this.add(new RegistrySupplier.RegistryInfo<T>(
key,
elementCodec,
RegistrySupplier.RegistryInfo.UNFILTERED
));
}
public <T> void add(
ResourceKey<? extends Registry<T>> key,
Codec<T> elementCodec,
RegistrySetBuilder.RegistryBootstrap<T> registryBootstrap
) {
this.add(new RegistrySupplier.RegistryInfo<T>(key, elementCodec, registryBootstrap));
}
public <T> void add(
ResourceKey<? extends Registry<T>> key,
Codec<T> elementCodec,
RegistrySetBuilder.RegistryBootstrap<T> registryBootstrap,
String... modIDs
) {
this.add(new RegistrySupplier.RegistryInfo<T>(key, elementCodec, registryBootstrap, modIDs));
}
public <T> void add(
ResourceKey<? extends Registry<T>> key,
Codec<T> elementCodec,
RegistrySetBuilder.RegistryBootstrap<T> registryBootstrap,
List<String> modIDs
) {
this.add(new RegistrySupplier.RegistryInfo<T>(key, elementCodec, registryBootstrap, modIDs));
}
public <T> void addUnfiltered(
ResourceKey<? extends Registry<T>> key,
Codec<T> elementCodec,
RegistrySetBuilder.RegistryBootstrap<T> registryBootstrap
) {
this.add(new RegistrySupplier.RegistryInfo<T>(
key,
elementCodec,
registryBootstrap,
RegistryInfo.UNFILTERED
));
}
public <T> void addBootstrapOnly(
ResourceKey<? extends Registry<T>> key,
Codec<T> elementCodec,
RegistrySetBuilder.RegistryBootstrap<T> registryBootstrap
) {
this.add(new RegistrySupplier.RegistryInfo<T>(key, elementCodec, registryBootstrap, List.of()));
}
}
public final class RegistryInfo<T> {
public static final List<String> UNFILTERED = null;
public final RegistryDataLoader.RegistryData<T> data;
public final List<String> modIDs;
public final RegistrySetBuilder.RegistryBootstrap<T> registryBootstrap;
public RegistryInfo(
RegistryDataLoader.RegistryData<T> data,
List<String> modIDs,
RegistrySetBuilder.RegistryBootstrap<T> registryBootstrap
) {
this.data = data;
this.modIDs = modIDs;
this.registryBootstrap = registryBootstrap;
}
public RegistryInfo(
ResourceKey<? extends Registry<T>> key,
Codec<T> elementCodec,
RegistrySetBuilder.RegistryBootstrap<T> registryBootstrap
) {
this(
new RegistryDataLoader.RegistryData<>(key, elementCodec),
RegistrySupplier.this.defaultModIDs,
registryBootstrap
);
}
public RegistryInfo(
ResourceKey<? extends Registry<T>> key,
Codec<T> elementCodec,
RegistrySetBuilder.RegistryBootstrap<T> registryBootstrap,
String... modIDs
) {
this(new RegistryDataLoader.RegistryData<>(key, elementCodec), List.of(modIDs), registryBootstrap);
}
public RegistryInfo(
ResourceKey<? extends Registry<T>> key,
Codec<T> elementCodec,
RegistrySetBuilder.RegistryBootstrap<T> registryBootstrap,
List<String> modIDs
) {
this(new RegistryDataLoader.RegistryData<>(key, elementCodec), modIDs, registryBootstrap);
}
public RegistryInfo(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec) {
this(
new RegistryDataLoader.RegistryData<>(key, elementCodec),
RegistrySupplier.this.defaultModIDs,
null
);
}
public RegistryInfo(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, String... modIDs) {
this(new RegistryDataLoader.RegistryData<>(key, elementCodec), List.of(modIDs), null);
}
public RegistryInfo(ResourceKey<? extends Registry<T>> key, Codec<T> elementCodec, List<String> modIDs) {
this(new RegistryDataLoader.RegistryData<>(key, elementCodec), modIDs, null);
}
public ResourceKey<? extends Registry<T>> key() {
return data.key();
}
public Codec<T> elementCodec() {
return data.elementCodec();
}
List<Holder<T>> allElements(HolderLookup.Provider registryAccess) {
final HolderLookup.RegistryLookup<T> registry = registryAccess.lookupOrThrow(key());
return registry
.listElementIds()
.filter(k -> modIDs == null || modIDs.contains(k.location().getNamespace()))
.map(k -> (Holder<T>) registry.get(k).orElseThrow())
.toList();
}
private void add(RegistrySetBuilder registryBuilder, final Semaphore LOCK_BOOSTRAP) {
try {
LOCK_BOOSTRAP.acquire();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
registryBuilder.add(key(), (BootstapContext<T> ctx) -> {
registryBootstrap.run(ctx);
LOCK_BOOSTRAP.release();
});
}
public RegistryDataLoader.RegistryData<T> data() {
return data;
}
public List<String> modIDs() {
return modIDs;
}
@Override
public boolean equals(Object obj) {
if (obj == this) return true;
if (obj == null || obj.getClass() != this.getClass()) return false;
var that = (RegistryInfo) obj;
return Objects.equals(this.data, that.data) &&
Objects.equals(this.modIDs, that.modIDs);
}
@Override
public int hashCode() {
return Objects.hash(data, modIDs);
}
@Override
public String toString() {
return "RegistryInfo[" +
"data=" + data + ", " +
"modIDs=" + modIDs + ']';
}
}
}

View file

@ -0,0 +1,69 @@
package org.betterx.datagen.bclib;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeData;
import org.betterx.bclib.api.v3.datagen.RegistrySupplier;
import org.betterx.datagen.bclib.preset.WorldPresetDataProvider;
import org.betterx.datagen.bclib.tests.TestBiomes;
import org.betterx.datagen.bclib.tests.TestConfiguredFeatures;
import org.betterx.datagen.bclib.tests.TestPlacedFeatures;
import org.betterx.datagen.bclib.tests.TestStructure;
import org.betterx.datagen.bclib.worldgen.NoiseTypesDataProvider;
import org.betterx.worlds.together.WorldsTogether;
import org.betterx.worlds.together.surfaceRules.AssignedSurfaceRule;
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.StructureSet;
import java.util.List;
import org.jetbrains.annotations.Nullable;
public class BCLRegistrySupplier extends RegistrySupplier {
public static final BCLRegistrySupplier INSTANCE = new BCLRegistrySupplier();
private BCLRegistrySupplier() {
super(List.of(
BCLib.MOD_ID,
WorldsTogether.MOD_ID
));
}
@Override
protected List<RegistryInfo<?>> initializeRegistryList(@Nullable List<String> modIDs) {
InfoList registries = new InfoList();
registries.addUnfiltered(BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC);
registries.addUnfiltered(SurfaceRuleRegistry.SURFACE_RULES_REGISTRY, AssignedSurfaceRule.CODEC);
if (BCLibDatagen.ADD_TESTS) {
registries.add(Registries.STRUCTURE, Structure.DIRECT_CODEC, TestStructure::bootstrap);
registries.add(Registries.STRUCTURE_SET, StructureSet.DIRECT_CODEC, TestStructure::bootstrapSet);
registries.add(
Registries.CONFIGURED_FEATURE,
ConfiguredFeature.DIRECT_CODEC,
TestConfiguredFeatures::bootstrap
);
registries.add(Registries.PLACED_FEATURE, PlacedFeature.DIRECT_CODEC, TestPlacedFeatures::bootstrap);
registries.add(Registries.BIOME, Biome.DIRECT_CODEC, TestBiomes::bootstrap);
} else {
registries.addBootstrapOnly(Registries.BIOME, Biome.DIRECT_CODEC, TestBiomes::bootstrap);
}
registries.add(
Registries.NOISE_SETTINGS,
NoiseGeneratorSettings.DIRECT_CODEC,
NoiseTypesDataProvider::bootstrap
);
registries.add(Registries.WORLD_PRESET, WorldPreset.DIRECT_CODEC, WorldPresetDataProvider::bootstrap);
return registries;
}
}

View file

@ -2,13 +2,12 @@ package org.betterx.datagen.bclib;
import org.betterx.bclib.BCLib;
import org.betterx.datagen.bclib.preset.WorldPresetDataProvider;
import org.betterx.datagen.bclib.tests.*;
import org.betterx.datagen.bclib.tests.TestBiomes;
import org.betterx.datagen.bclib.tests.TestWorldgenProvider;
import org.betterx.datagen.bclib.worldgen.BCLibRegistriesDataProvider;
import org.betterx.datagen.bclib.worldgen.NoiseTypesDataProvider;
import org.betterx.datagen.bclib.worldgen.VanillaBCLBiomesDataProvider;
import net.minecraft.core.RegistrySetBuilder;
import net.minecraft.core.registries.Registries;
import net.fabricmc.fabric.api.datagen.v1.DataGeneratorEntrypoint;
import net.fabricmc.fabric.api.datagen.v1.FabricDataGenerator;
@ -32,19 +31,9 @@ public class BCLibDatagen implements DataGeneratorEntrypoint {
pack.addProvider(BCLibRegistriesDataProvider::new);
}
@Override
public void buildRegistry(RegistrySetBuilder registryBuilder) {
BCLib.LOGGER.info("Datagen buildRegistry");
if (ADD_TESTS) {
registryBuilder.add(Registries.CONFIGURED_FEATURE, TestConfiguredFeatures::bootstrap);
registryBuilder.add(Registries.PLACED_FEATURE, TestPlacedFeatures::bootstrap);
//registryBuilder.add(Registries.STRUCTURE_PIECE, TestStructure::bootstrapPiece);
//registryBuilder.add(Registries.STRUCTURE_TYPE, TestStructure::bootstrapType);
registryBuilder.add(Registries.STRUCTURE, TestStructure::bootstrap);
registryBuilder.add(Registries.STRUCTURE_SET, TestStructure::bootstrapSet);
}
registryBuilder.add(Registries.BIOME, TestBiomes::bootstrap);
registryBuilder.add(Registries.NOISE_SETTINGS, NoiseTypesDataProvider::bootstrap);
registryBuilder.add(Registries.WORLD_PRESET, WorldPresetDataProvider::bootstrap);
BCLRegistrySupplier.INSTANCE.bootstrapRegistries(registryBuilder);
}
}

View file

@ -32,8 +32,8 @@ public class TestConfiguredFeatures {
YELLOW_FEATURE.id
));
BCLib.LOGGER.info("Bootstrap CONFIGUREDFeatures" + holder);
if (BCLibDatagen.ADD_TESTS && BCLib.isDevEnvironment()) {
BCLib.LOGGER.info("Bootstrap CONFIGUREDFeatures" + holder);
//YELLOW_FEATURE = YELLOW_FEATURE.register(bootstrapContext);
BCLFeatureBuilder.registerUnbound(bootstrapContext);
}

View file

@ -26,9 +26,8 @@ public class TestPlacedFeatures {
.build();
public static void bootstrap(BootstapContext<PlacedFeature> bootstrapContext) {
BCLib.LOGGER.info("Bootstrap PLACEDFeatures");
if (BCLibDatagen.ADD_TESTS && BCLib.isDevEnvironment()) {
BCLib.LOGGER.info("Bootstrap PLACEDFeatures");
YELLOW_PLACED = YELLOW_PLACED.register(bootstrapContext);
}
}

View file

@ -1,57 +1,20 @@
package org.betterx.datagen.bclib.worldgen;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
import org.betterx.bclib.api.v2.levelgen.biomes.BiomeData;
import org.betterx.bclib.api.v3.datagen.RegistriesDataProvider;
import org.betterx.datagen.bclib.BCLibDatagen;
import org.betterx.worlds.together.WorldsTogether;
import org.betterx.worlds.together.surfaceRules.AssignedSurfaceRule;
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
import org.betterx.datagen.bclib.BCLRegistrySupplier;
import net.minecraft.core.HolderLookup;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.NoiseGeneratorSettings;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
import net.minecraft.world.level.levelgen.presets.WorldPreset;
import net.minecraft.world.level.levelgen.structure.Structure;
import net.minecraft.world.level.levelgen.structure.StructureSet;
import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.jetbrains.annotations.Nullable;
public class BCLibRegistriesDataProvider extends RegistriesDataProvider {
public BCLibRegistriesDataProvider(
FabricDataOutput generator,
CompletableFuture<HolderLookup.Provider> registriesFuture
) {
super(BCLib.LOGGER, List.of(BCLib.MOD_ID, WorldsTogether.MOD_ID), generator, registriesFuture);
}
@Override
protected List<RegistryInfo<?>> initializeRegistryList(@Nullable List<String> modIDs) {
InfoList registries = new InfoList();
registries.addUnfiltered(BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC);
registries.addUnfiltered(SurfaceRuleRegistry.SURFACE_RULES_REGISTRY, AssignedSurfaceRule.CODEC);
if (BCLibDatagen.ADD_TESTS) {
registries.add(Registries.STRUCTURE, Structure.DIRECT_CODEC);
registries.add(Registries.STRUCTURE_SET, StructureSet.DIRECT_CODEC);
registries.add(Registries.CONFIGURED_FEATURE, ConfiguredFeature.DIRECT_CODEC);
registries.add(Registries.PLACED_FEATURE, PlacedFeature.DIRECT_CODEC);
registries.add(Registries.BIOME, Biome.DIRECT_CODEC);
}
registries.add(Registries.NOISE_SETTINGS, NoiseGeneratorSettings.DIRECT_CODEC);
registries.add(Registries.WORLD_PRESET, WorldPreset.DIRECT_CODEC);
return registries;
super(BCLib.LOGGER, BCLRegistrySupplier.INSTANCE, generator, registriesFuture);
}
}