[Changes] Simplified and streamlined some aspects of BCLBiomeRegistry`

This commit is contained in:
Frank 2022-12-11 23:58:11 +01:00
parent 82c9b62fd3
commit ce9288d4e3
16 changed files with 63 additions and 138 deletions

View file

@ -53,7 +53,7 @@ public class BCLib implements ModInitializer {
PresetsRegistry.register();
LevelGenEvents.register();
BlockPredicates.ensureStaticInitialization();
BCLBiomeRegistry.ensureStaticallyLoaded();
BCLBiomeRegistry.register();
BaseRegistry.register();
GeneratorOptions.init();
BaseBlockEntities.register();

View file

@ -3,7 +3,6 @@ package org.betterx.bclib.api.v2.generator;
import org.betterx.bclib.BCLib;
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;
@ -11,10 +10,11 @@ import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.*;
import net.minecraft.core.Holder;
import net.minecraft.core.QuartPos;
import net.minecraft.core.Registry;
import net.minecraft.core.SectionPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BiomeTags;
@ -34,8 +34,6 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
public static Codec<BCLibEndBiomeSource> CODEC
= RecordCodecBuilder.create((instance) -> instance
.group(
RegistryOps.retrieveGetter(Registries.BIOME),
RegistryOps.retrieveGetter(BCLBiomeRegistry.BCL_BIOMES_REGISTRY),
Codec
.LONG
.fieldOf("seed")
@ -67,36 +65,20 @@ public class BCLibEndBiomeSource extends BCLBiomeSource implements BiomeSourceWi
private BCLEndBiomeSourceConfig config;
private BCLibEndBiomeSource(
HolderGetter<Biome> biomeRegistry,
HolderGetter<BCLBiome> bclBiomeRegistry,
long seed,
BCLEndBiomeSourceConfig config
) {
this(biomeRegistry, bclBiomeRegistry, seed, config, true);
this(seed, config, true);
}
public BCLibEndBiomeSource(
HolderGetter<Biome> biomeRegistry,
HolderGetter<BCLBiome> bclBiomeRegistry,
BCLEndBiomeSourceConfig config
) {
this(biomeRegistry, bclBiomeRegistry, 0, config, false);
this(0, config, false);
}
private BCLibEndBiomeSource(
HolderGetter<Biome> biomeRegistry,
HolderGetter<BCLBiome> bclBiomeRegistry,
long seed,
BCLEndBiomeSourceConfig config,
boolean initMaps
) {
this(biomeRegistry, bclBiomeRegistry, null, seed, config, initMaps);
}
private BCLibEndBiomeSource(
HolderGetter<Biome> biomeRegistry,
HolderGetter<BCLBiome> bclBiomeRegistry,
List<Holder<Biome>> list,
long seed,
BCLEndBiomeSourceConfig config,
boolean initMaps

View file

@ -49,7 +49,7 @@ public class LevelGenUtil {
}
public static LevelStem getBCLEndLevelStem(WorldGenUtil.Context context, BCLEndBiomeSourceConfig config) {
BCLibEndBiomeSource endSource = new BCLibEndBiomeSource(context.biomes, context.bclBiomes, config);
BCLibEndBiomeSource endSource = new BCLibEndBiomeSource(config);
return new LevelStem(
context.dimension,
new BCLChunkGenerator(

View file

@ -320,7 +320,8 @@ public class BCLBiome implements BiomeData {
subbiomes.add(this, 1.0f);
if (acc == null) return subbiomes;
Registry<BCLBiome> reg = acc.registryOrThrow(BCLBiomeRegistry.BCL_BIOMES_REGISTRY);
Registry<BCLBiome> reg = acc.registry(BCLBiomeRegistry.BCL_BIOMES_REGISTRY).orElse(null);
if (reg == null) reg = BCLBiomeRegistry.BUILTIN_BCL_BIOMES;
for (Map.Entry<ResourceKey<BCLBiome>, BCLBiome> entry : reg.entrySet()) {
BCLBiome b = entry.getValue();

View file

@ -1,7 +1,6 @@
package org.betterx.bclib.api.v2.levelgen.biomes;
import org.betterx.bclib.BCLib;
import org.betterx.datagen.bclib.worldgen.VanillaBCLBiomesDataProvider;
import org.betterx.worlds.together.WorldsTogether;
import org.betterx.worlds.together.world.event.WorldBootstrap;
@ -10,14 +9,18 @@ import com.mojang.serialization.Lifecycle;
import net.minecraft.core.MappedRegistry;
import net.minecraft.core.Registry;
import net.minecraft.core.RegistryAccess;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.worldgen.BootstapContext;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.KeyDispatchDataCodec;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biomes;
import net.fabricmc.fabric.api.event.registry.FabricRegistryBuilder;
import net.fabricmc.fabric.api.event.registry.RegistryAttribute;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Stream;
import org.jetbrains.annotations.ApiStatus;
@ -30,11 +33,11 @@ public class BCLBiomeRegistry {
public static final ResourceKey<Registry<Codec<? extends BCLBiome>>> BCL_BIOME_CODEC_REGISTRY =
createRegistryKey(WorldsTogether.makeID("worldgen/betterx/biome_codec"));
public static Registry<Codec<? extends BCLBiome>> BIOME_CODECS = BuiltInRegistries.registerSimple(
BCL_BIOME_CODEC_REGISTRY,
BCLBiomeRegistry::bootstrapCodecs
);
public static Registry<BCLBiome> BUILTIN_BCL_BIOMES = new MappedRegistry<>(
public static Registry<Codec<? extends BCLBiome>> BIOME_CODECS = FabricRegistryBuilder
.from(new MappedRegistry<>(BCL_BIOME_CODEC_REGISTRY, Lifecycle.stable()))
.attribute(RegistryAttribute.MODDED)
.buildAndRegister();
public static MappedRegistry<BCLBiome> BUILTIN_BCL_BIOMES = new MappedRegistry<>(
BCL_BIOMES_REGISTRY,
Lifecycle.stable()
);
@ -185,17 +188,16 @@ public class BCLBiomeRegistry {
}
}
public static void ensureStaticallyLoaded() {
@ApiStatus.Internal
public static void register() {
bootstrapCodecs(BIOME_CODECS);
}
public static void prepareForDatagen() {
if (didCreate) return;
didCreate = true;
BUILTIN_BCL_BIOMES = BuiltInRegistries.registerSimple(
BCL_BIOMES_REGISTRY,
VanillaBCLBiomesDataProvider::bootstrap
);
@ApiStatus.Internal
public static void bootstrap(BootstapContext<BCLBiome> ctx) {
//copy from builtin
for (Map.Entry<ResourceKey<BCLBiome>, BCLBiome> e : BUILTIN_BCL_BIOMES.entrySet()) {
ctx.register(e.getKey(), e.getValue());
}
}
}

View file

@ -1,5 +1,7 @@
package org.betterx.bclib.api.v3.datagen;
import org.betterx.bclib.BCLib;
import com.mojang.serialization.Codec;
import net.minecraft.core.Holder;
import net.minecraft.core.HolderLookup;
@ -38,10 +40,8 @@ public abstract class RegistrySupplier {
public void bootstrapRegistries(RegistrySetBuilder registryBuilder) {
for (RegistrySupplier.RegistryInfo<?> nfo : allRegistries) {
if (nfo.registryBootstrap != null) {
nfo.add(registryBuilder, BOOTSTRAP_LOCK);
}
}
BOOTSTRAP_LOCK.release();
}
@ -213,8 +213,11 @@ public abstract class RegistrySupplier {
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
BCLib.LOGGER.info("Adding:" + key());
registryBuilder.add(key(), (BootstapContext<T> ctx) -> {
if (registryBootstrap != null) {
registryBootstrap.run(ctx);
}
LOCK_BOOSTRAP.release();
});
}

View file

@ -1,43 +0,0 @@
package org.betterx.bclib.mixin.common;
import org.betterx.bclib.BCLib;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
import com.mojang.serialization.Lifecycle;
import net.minecraft.core.Registry;
import net.minecraft.core.WritableRegistry;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceKey;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@Mixin(BuiltInRegistries.class)
public abstract class BuiltinRegistriesMixin {
@Shadow
private static <T, R extends WritableRegistry<T>> R internalRegister(
ResourceKey<? extends Registry<T>> resourceKey,
R writableRegistry,
BuiltInRegistries.RegistryBootstrap<T> registryBootstrap,
Lifecycle lifecycle
) {
throw new RuntimeException("Shadowed");
}
//this needs to be added BEFORE the WORLD_PRESET-Registry. Otherwise decoding will fail!
@Inject(method = "<clinit>", at = @At(value = "INVOKE", ordinal = 0, target = "Lnet/minecraft/core/registries/BuiltInRegistries;registerSimple(Lnet/minecraft/resources/ResourceKey;Lnet/minecraft/core/registries/BuiltInRegistries$RegistryBootstrap;)Lnet/minecraft/core/Registry;"))
private static void bcl_registerBuiltin(CallbackInfo ci) {
BCLBiomeRegistry.ensureStaticallyLoaded();
if (BCLib.isDatagen()) {
// BCLBiomeRegistry.BUILTIN_BCL_BIOMES = internalRegister(
// BCLBiomeRegistry.BCL_BIOMES_REGISTRY,
// BCLBiomeRegistry.BUILTIN_BCL_BIOMES,
// BCLBiomeRegistry::bootstrap,
// Lifecycle.stable()
// );
}
}
}

View file

@ -25,6 +25,7 @@ public class RegistryDataLoaderMixin {
@Inject(method = "<clinit>", at = @At("TAIL"))
private static void wt_init(CallbackInfo ci) {
//we need this to ensure, that the BCL-Biome Registry is loaded at the correct time
List<RegistryDataLoader.RegistryData<?>> enhanced = new ArrayList(RegistryDataLoader.WORLDGEN_REGISTRIES.size() + 1);
enhanced.addAll(RegistryDataLoader.WORLDGEN_REGISTRIES);
enhanced.add(new RegistryDataLoader.RegistryData<>(

View file

@ -10,6 +10,7 @@ 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.datagen.bclib.worldgen.VanillaBCLBiomesDataProvider;
import org.betterx.worlds.together.WorldsTogether;
import org.betterx.worlds.together.surfaceRules.AssignedSurfaceRule;
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
@ -40,7 +41,11 @@ public class BCLRegistrySupplier extends RegistrySupplier {
protected List<RegistryInfo<?>> initializeRegistryList(@Nullable List<String> modIDs) {
InfoList registries = new InfoList();
registries.addUnfiltered(BCLBiomeRegistry.BCL_BIOMES_REGISTRY, BiomeData.CODEC);
registries.addUnfiltered(
BCLBiomeRegistry.BCL_BIOMES_REGISTRY,
BiomeData.CODEC,
VanillaBCLBiomesDataProvider::bootstrap
);
registries.addUnfiltered(SurfaceRuleRegistry.SURFACE_RULES_REGISTRY, AssignedSurfaceRule.CODEC);
if (BCLibDatagen.ADD_TESTS) {

View file

@ -6,7 +6,6 @@ import org.betterx.datagen.bclib.preset.WorldPresetDataProvider;
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.VanillaBCLBiomesDataProvider;
import net.minecraft.core.RegistrySetBuilder;
@ -19,8 +18,6 @@ public class BCLibDatagen implements DataGeneratorEntrypoint {
@Override
public void onInitializeDataGenerator(FabricDataGenerator dataGenerator) {
BCLib.LOGGER.info("Bootstrap onInitializeDataGenerator");
VanillaBCLBiomesDataProvider.create();
final FabricDataGenerator.Pack pack = dataGenerator.createPack();
if (ADD_TESTS) {

View file

@ -66,8 +66,6 @@ public class WorldPresetDataProvider extends FabricTagProvider<WorldPreset> {
.getOrThrow(NoiseGeneratorSettings.AMPLIFIED);
WorldGenUtil.Context amplifiedNetherContext = new WorldGenUtil.Context(
ctx.netherContext.biomes,
ctx.netherContext.bclBiomes,
ctx.netherContext.dimension,
ctx.netherContext.structureSets,
ctx.noiseSettings.getOrThrow(BCLChunkGenerator.AMPLIFIED_NETHER)

View file

@ -4,51 +4,35 @@ 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 net.minecraft.core.Registry;
import net.minecraft.data.worldgen.BootstapContext;
public class VanillaBCLBiomesDataProvider {
private static boolean didBootstrap = false;
public static void create() {
BCLBiomeRegistry.prepareForDatagen();
bootstrap(BCLBiomeRegistry.BUILTIN_BCL_BIOMES);
}
public static BCLBiome bootstrap(Registry<BCLBiome> reg) {
if (didBootstrap) return BCLBiomeRegistry.EMPTY_BIOME;
didBootstrap = true;
Registry.register(reg, BiomeAPI.SMALL_END_ISLANDS.getBCLBiomeKey(), BiomeAPI.SMALL_END_ISLANDS);
Registry.register(reg, BiomeAPI.END_BARRENS.getBCLBiomeKey(), BiomeAPI.END_BARRENS);
Registry.register(reg, BiomeAPI.END_HIGHLANDS.getBCLBiomeKey(), BiomeAPI.END_HIGHLANDS);
Registry.register(reg, BiomeAPI.END_MIDLANDS.getBCLBiomeKey(), BiomeAPI.END_MIDLANDS);
Registry.register(reg, BiomeAPI.THE_END.getBCLBiomeKey(), BiomeAPI.THE_END);
Registry.register(
reg,
public static void bootstrap(BootstapContext<BCLBiome> ctx) {
ctx.register(BiomeAPI.SMALL_END_ISLANDS.getBCLBiomeKey(), BiomeAPI.SMALL_END_ISLANDS);
ctx.register(BiomeAPI.END_BARRENS.getBCLBiomeKey(), BiomeAPI.END_BARRENS);
ctx.register(BiomeAPI.END_HIGHLANDS.getBCLBiomeKey(), BiomeAPI.END_HIGHLANDS);
ctx.register(BiomeAPI.END_MIDLANDS.getBCLBiomeKey(), BiomeAPI.END_MIDLANDS);
ctx.register(BiomeAPI.THE_END.getBCLBiomeKey(), BiomeAPI.THE_END);
ctx.register(
BiomeAPI.BASALT_DELTAS_BIOME.getBCLBiomeKey(),
BiomeAPI.BASALT_DELTAS_BIOME
);
Registry.register(
reg,
ctx.register(
BiomeAPI.SOUL_SAND_VALLEY_BIOME.getBCLBiomeKey(),
BiomeAPI.SOUL_SAND_VALLEY_BIOME
);
Registry.register(
reg,
ctx.register(
BiomeAPI.WARPED_FOREST_BIOME.getBCLBiomeKey(),
BiomeAPI.WARPED_FOREST_BIOME
);
Registry.register(
reg,
ctx.register(
BiomeAPI.CRIMSON_FOREST_BIOME.getBCLBiomeKey(),
BiomeAPI.CRIMSON_FOREST_BIOME
);
Registry.register(
reg,
ctx.register(
BiomeAPI.NETHER_WASTES_BIOME.getBCLBiomeKey(),
BiomeAPI.NETHER_WASTES_BIOME
);
return Registry.register(reg, BCLBiomeRegistry.EMPTY_BIOME.getBCLBiomeKey(), BCLBiomeRegistry.EMPTY_BIOME);
ctx.register(BCLBiomeRegistry.EMPTY_BIOME.getBCLBiomeKey(), BCLBiomeRegistry.EMPTY_BIOME);
}
}

View file

@ -1,6 +1,5 @@
package org.betterx.worlds.together.levelgen;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiome;
import org.betterx.worlds.together.WorldsTogether;
import org.betterx.worlds.together.biomesource.BiomeSourceWithConfig;
import org.betterx.worlds.together.biomesource.ReloadableBiomeSource;
@ -100,19 +99,14 @@ public class WorldGenUtil {
}
public static class Context extends StemContext {
public final HolderGetter<Biome> biomes;
public final HolderGetter<BCLBiome> bclBiomes;
public Context(
HolderGetter<Biome> biomes,
HolderGetter<BCLBiome> bclBiomes,
Holder<DimensionType> dimension,
HolderGetter<StructureSet> structureSets,
Holder<NoiseGeneratorSettings> generatorSettings
) {
super(dimension, structureSets, generatorSettings);
this.biomes = biomes;
this.bclBiomes = bclBiomes;
}
}

View file

@ -1,5 +1,6 @@
package org.betterx.worlds.together.mixin.common;
import org.betterx.bclib.api.v2.levelgen.biomes.BCLBiomeRegistry;
import org.betterx.worlds.together.surfaceRules.SurfaceRuleRegistry;
import net.minecraft.core.RegistrySetBuilder;
@ -20,6 +21,11 @@ public class VanillaRegistriesMixin {
@Inject(method = "<clinit>", at = @At(value = "TAIL"))
private static void together_registerSurface(CallbackInfo ci) {
BUILDER.add(
BCLBiomeRegistry.BCL_BIOMES_REGISTRY,
BCLBiomeRegistry::bootstrap
);
BUILDER.add(
SurfaceRuleRegistry.SURFACE_RULES_REGISTRY,
SurfaceRuleRegistry::bootstrap

View file

@ -115,16 +115,12 @@ public class WorldPresets {
HolderGetter<BCLBiome> bclBiomes = bootstapContext.lookup(BCLBiomeRegistry.BCL_BIOMES_REGISTRY);
this.netherContext = new WorldGenUtil.Context(
this.biomes,
bclBiomes,
this.netherStem.type(),
this.structureSets,
netherSettings
);
this.endContext = new WorldGenUtil.Context(
this.biomes,
bclBiomes,
this.endStem.type(),
this.structureSets,
endSettings

View file

@ -10,7 +10,6 @@
"BiomeMixin",
"BiomeSourceMixin",
"BoneMealItemMixin",
"BuiltinRegistriesMixin",
"ChunkGeneratorAccessor",
"ChunkGeneratorMixin",
"ChunkGeneratorsMixin",