More BiomeSource related fixes

This commit is contained in:
Frank 2022-03-14 17:23:57 +01:00
parent 2eccb1cb9e
commit 6c015a9a53
6 changed files with 93 additions and 84 deletions

View file

@ -75,7 +75,7 @@ public class BiomeAPI {
private static final Map<ResourceLocation, BCLBiome> ID_MAP = Maps.newHashMap(); private static final Map<ResourceLocation, BCLBiome> ID_MAP = Maps.newHashMap();
private static final Map<Biome, BCLBiome> CLIENT = Maps.newHashMap(); private static final Map<Biome, BCLBiome> CLIENT = Maps.newHashMap();
private static Registry<Holder<Biome>> biomeRegistry; private static Registry<Biome> biomeRegistry;
private static final Map<PlacedFeature, Integer> FEATURE_ORDER = Maps.newHashMap(); private static final Map<PlacedFeature, Integer> FEATURE_ORDER = Maps.newHashMap();
private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0); private static final MutableInt FEATURE_ORDER_ID = new MutableInt(0);
@ -94,8 +94,8 @@ public class BiomeAPI {
public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS).value(), 0.5F); public static final BCLBiome END_MIDLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_MIDLANDS).value(), 0.5F);
public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS).value(), 0.5F); public static final BCLBiome END_HIGHLANDS = registerSubBiome(THE_END, getFromRegistry(Biomes.END_HIGHLANDS).value(), 0.5F);
public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")).value()); public static final BCLBiome END_BARRENS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("end_barrens")));
public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")).value()); public static final BCLBiome SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")));
private static void initFeatureOrder() { private static void initFeatureOrder() {
if (!FEATURE_ORDER.isEmpty()) { if (!FEATURE_ORDER.isEmpty()) {
@ -123,7 +123,7 @@ public class BiomeAPI {
* Initialize registry for current server. * Initialize registry for current server.
* @param biomeRegistry - {@link Registry} for {@link Biome}. * @param biomeRegistry - {@link Registry} for {@link Biome}.
*/ */
public static void initRegistry(Registry<Holder<Biome>> biomeRegistry) { public static void initRegistry(Registry<Biome> biomeRegistry) {
if (biomeRegistry != BiomeAPI.biomeRegistry) { if (biomeRegistry != BiomeAPI.biomeRegistry) {
BiomeAPI.biomeRegistry = biomeRegistry; BiomeAPI.biomeRegistry = biomeRegistry;
CLIENT.clear(); CLIENT.clear();
@ -143,15 +143,17 @@ public class BiomeAPI {
/** /**
* Register {@link BCLBiome} instance and its {@link Biome} if necessary. * Register {@link BCLBiome} instance and its {@link Biome} if necessary.
* @param biome {@link BCLBiome} * @param bclbiome {@link BCLBiome}
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerBiome(BCLBiome biome) { public static BCLBiome registerBiome(BCLBiome bclbiome) {
if (BuiltinRegistries.BIOME.get(biome.getID()) == null) { if (BuiltinRegistries.BIOME.get(bclbiome.getID()) == null) {
Registry.register(BuiltinRegistries.BIOME, biome.getID(), biome.getBiome()); final Biome biome = bclbiome.getBiome();
ResourceLocation loc = bclbiome.getID();
Registry.register(BuiltinRegistries.BIOME, loc, biome);
} }
ID_MAP.put(biome.getID(), biome); ID_MAP.put(bclbiome.getID(), bclbiome);
return biome; return bclbiome;
} }
public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) { public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) {
@ -273,8 +275,8 @@ public class BiomeAPI {
* @param biome {@link BCLBiome} * @param biome {@link BCLBiome}
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndVoidBiome(Biome biome) { public static BCLBiome registerEndVoidBiome(Holder<Biome> biome) {
BCLBiome bclBiome = new BCLBiome(biome, null); BCLBiome bclBiome = new BCLBiome(biome.value(), null);
END_VOID_BIOME_PICKER.addBiome(bclBiome); END_VOID_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
@ -288,8 +290,8 @@ public class BiomeAPI {
* @param genChance float generation chance. * @param genChance float generation chance.
* @return {@link BCLBiome} * @return {@link BCLBiome}
*/ */
public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) { public static BCLBiome registerEndVoidBiome(Holder<Biome> biome, float genChance) {
BCLBiome bclBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build()); BCLBiome bclBiome = new BCLBiome(biome.value(), VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
END_VOID_BIOME_PICKER.addBiome(bclBiome); END_VOID_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome); registerBiome(bclBiome);
@ -301,7 +303,7 @@ public class BiomeAPI {
* @param biome - {@link Biome} from world. * @param biome - {@link Biome} from world.
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}. * @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
*/ */
public static BCLBiome getFromBiome(Holder<Biome> biome) { public static BCLBiome getFromBiome(Biome biome) {
if (biomeRegistry == null) { if (biomeRegistry == null) {
return EMPTY_BIOME; return EMPTY_BIOME;
} }
@ -334,7 +336,7 @@ public class BiomeAPI {
public static ResourceKey getBiomeKey(Biome biome) { public static ResourceKey getBiomeKey(Biome biome) {
return BuiltinRegistries.BIOME return BuiltinRegistries.BIOME
.getResourceKey(biome) .getResourceKey(biome)
.orElse(null); .orElseGet(() -> biomeRegistry != null ? biomeRegistry.getResourceKey(biome).orElse(null) : null);
} }
/** /**
@ -344,9 +346,9 @@ public class BiomeAPI {
*/ */
public static ResourceLocation getBiomeID(Biome biome) { public static ResourceLocation getBiomeID(Biome biome) {
ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome); ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome);
// if (id == null && biomeRegistry != null) { if (id == null && biomeRegistry != null) {
// id = biomeRegistry.getKey(biome); id = biomeRegistry.getKey(biome);
//} }
return id == null ? EMPTY_BIOME.getID() : id; return id == null ? EMPTY_BIOME.getID() : id;
} }

View file

@ -12,7 +12,7 @@ import java.util.function.Function;
public interface NumericProvider { public interface NumericProvider {
ResourceKey<Registry<Codec<? extends NumericProvider>>> NUMERIC_PROVIDER_REGISTRY = ResourceKey.createRegistryKey(BCLib.makeID("worldgen/numeric_provider")); ResourceKey<Registry<Codec<? extends NumericProvider>>> NUMERIC_PROVIDER_REGISTRY = ResourceKey.createRegistryKey(BCLib.makeID("worldgen/numeric_provider"));
Registry<Codec<? extends NumericProvider>> NUMERIC_PROVIDER = new MappedRegistry<>(NUMERIC_PROVIDER_REGISTRY, Lifecycle.experimental()); Registry<Codec<? extends NumericProvider>> NUMERIC_PROVIDER = new MappedRegistry<>(NUMERIC_PROVIDER_REGISTRY, Lifecycle.experimental(), null);
Codec<NumericProvider> CODEC = NUMERIC_PROVIDER.byNameCodec().dispatch(NumericProvider::pcodec, Function.identity()); Codec<NumericProvider> CODEC = NUMERIC_PROVIDER.byNameCodec().dispatch(NumericProvider::pcodec, Function.identity());
int getNumber(SurfaceRulesContextAccessor context); int getNumber(SurfaceRulesContextAccessor context);

View file

@ -191,7 +191,7 @@ public class BCLBiome extends BCLBiomeSettings {
* Recursively update biomes to correct world biome registry instances, for internal usage only. * Recursively update biomes to correct world biome registry instances, for internal usage only.
* @param biomeRegistry {@link Registry} for {@link Biome}. * @param biomeRegistry {@link Registry} for {@link Biome}.
*/ */
public void updateActualBiomes(Registry<Holder<Biome>> biomeRegistry) { public void updateActualBiomes(Registry<Biome> biomeRegistry) {
subbiomes.forEach((sub) -> { subbiomes.forEach((sub) -> {
if (sub != this) { if (sub != this) {
sub.updateActualBiomes(biomeRegistry); sub.updateActualBiomes(biomeRegistry);
@ -201,8 +201,8 @@ public class BCLBiome extends BCLBiomeSettings {
edge.updateActualBiomes(biomeRegistry); edge.updateActualBiomes(biomeRegistry);
} }
final ResourceKey<Holder<Biome>> key = ResourceKey.create(biomeRegistry.key(), biomeID); final ResourceKey<Biome> key = biomeRegistry.getResourceKey(biomeRegistry.get(biomeID)).orElseThrow();
this.actualBiome = biomeRegistry.get(key); this.actualBiome = biomeRegistry.getOrCreateHolder(key);
if (actualBiome==null) { if (actualBiome==null) {
BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID); BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID);
} }

View file

@ -9,15 +9,15 @@ import ru.bclib.api.biomes.BiomeAPI;
import java.util.List; import java.util.List;
public abstract class BCLBiomeSource extends BiomeSource { public abstract class BCLBiomeSource extends BiomeSource {
protected final Registry<Holder<Biome>> biomeRegistry; protected final Registry<Biome> biomeRegistry;
protected final long seed; protected final long seed;
private static List<Holder<Biome>> preInit(Registry<Holder<Biome>> biomeRegistry, List<Holder<Biome>> biomes){ private static List<Holder<Biome>> preInit(Registry<Biome> biomeRegistry, List<Holder<Biome>> biomes){
biomes.forEach(biome -> BiomeAPI.sortBiomeFeatures(biome)); biomes.forEach(biome -> BiomeAPI.sortBiomeFeatures(biome));
return biomes; return biomes;
} }
protected BCLBiomeSource(Registry<Holder<Biome>> biomeRegistry, long seed, List<Holder<Biome>> list) { protected BCLBiomeSource(Registry<Biome> biomeRegistry, long seed, List<Holder<Biome>> list) {
super(preInit(biomeRegistry, list)); super(preInit(biomeRegistry, list));
this.seed = seed; this.seed = seed;

View file

@ -45,7 +45,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
private BiomeMap mapVoid; private BiomeMap mapVoid;
private final Point pos; private final Point pos;
public BCLibEndBiomeSource(Registry<Holder<Biome>> biomeRegistry, long seed) { public BCLibEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
super(biomeRegistry, seed, getBiomes(biomeRegistry)); super(biomeRegistry, seed, getBiomes(biomeRegistry));
BiomeAPI.END_LAND_BIOME_PICKER.clearMutables(); BiomeAPI.END_LAND_BIOME_PICKER.clearMutables();
@ -53,7 +53,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
List<String> includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue(); List<String> includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue();
this.possibleBiomes().forEach(biome -> { this.possibleBiomes().forEach(biome -> {
ResourceLocation key = biomeRegistry.getKey(biome); ResourceLocation key = biome.unwrapKey().orElseThrow().location();
String group = key.getNamespace() + "." + key.getPath(); String group = key.getNamespace() + "." + key.getPath();
if (!BiomeAPI.hasBiome(key)) { if (!BiomeAPI.hasBiome(key)) {
@ -98,8 +98,8 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER); this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER);
} }
this.centerBiome = biomeRegistry.get(Biomes.THE_END.location()); this.centerBiome = biomeRegistry.getOrCreateHolder(Biomes.THE_END);
this.barrens = biomeRegistry.get(Biomes.END_BARRENS.location()); this.barrens = biomeRegistry.getOrCreateHolder(Biomes.END_BARRENS);
WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed)); WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed));
chunkRandom.consumeCount(17292); chunkRandom.consumeCount(17292);
@ -109,35 +109,39 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
this.pos = new Point(); this.pos = new Point();
} }
private static List<Holder<Biome>> getBiomes(Registry<Holder<Biome>> biomeRegistry) { private static List<Holder<Biome>> getBiomes(Registry<Biome> biomeRegistry) {
List<String> includeLand = Configs.BIOMES_CONFIG.getEntry("force_include", "end_land_biomes", StringArrayEntry.class).getValue(); List<String> includeLand = Configs.BIOMES_CONFIG.getEntry("force_include", "end_land_biomes", StringArrayEntry.class).getValue();
List<String> includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue(); List<String> includeVoid = Configs.BIOMES_CONFIG.getEntry("force_include", "end_void_biomes", StringArrayEntry.class).getValue();
return biomeRegistry.stream().filter(biome -> { return biomeRegistry.stream()
ResourceLocation key = biomeRegistry.getKey(biome); .filter(biome -> biomeRegistry.getResourceKey(biome).isPresent())
.map(biome -> biomeRegistry.getOrCreateHolder(biomeRegistry.getResourceKey(biome).get()))
if (includeLand.contains(key.toString()) || includeVoid.contains(key.toString())) { .filter(biome -> {
return true; ResourceLocation key = biome.unwrapKey().orElseThrow().location();
}
final boolean isEndBiome;
if ((Object)biome instanceof BiomeAccessor bacc) { if (includeLand.contains(key.toString()) || includeVoid.contains(key.toString())) {
isEndBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.THEEND; return true;
if (GeneratorOptions.addEndBiomesByCategory() && isEndBiome) { }
return true;
} final boolean isEndBiome;
} else { if ((Object)biome instanceof BiomeAccessor bacc) {
isEndBiome = false; isEndBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.THEEND;
} if (GeneratorOptions.addEndBiomesByCategory() && isEndBiome) {
return true;
BCLBiome bclBiome = BiomeAPI.getBiome(key); }
if (bclBiome != BiomeAPI.EMPTY_BIOME) { } else {
if (bclBiome.getParentBiome() != null) { isEndBiome = false;
bclBiome = bclBiome.getParentBiome(); }
}
key = bclBiome.getID(); BCLBiome bclBiome = BiomeAPI.getBiome(key);
} if (bclBiome != BiomeAPI.EMPTY_BIOME) {
return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (isEndBiome && BiomeAPI.isDatapackBiome(key)); if (bclBiome.getParentBiome() != null) {
bclBiome = bclBiome.getParentBiome();
}
key = bclBiome.getID();
}
return BiomeAPI.END_LAND_BIOME_PICKER.containsImmutable(key) || BiomeAPI.END_VOID_BIOME_PICKER.containsImmutable(key) || (isEndBiome && BiomeAPI.isDatapackBiome(key));
}).toList(); }).toList();
} }

View file

@ -31,7 +31,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
.create(instance -> instance .create(instance -> instance
.group(RegistryOps .group(RegistryOps
.retrieveRegistry(Registry.BIOME_REGISTRY) .retrieveRegistry(Registry.BIOME_REGISTRY)
.forGetter(source -> null) .forGetter(source -> source.biomeRegistry)
, ,
Codec Codec
.LONG .LONG
@ -67,7 +67,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
BCLibNetherBiomeSource.worldHeight = worldHeight; BCLibNetherBiomeSource.worldHeight = worldHeight;
} }
public BCLibNetherBiomeSource(Registry<Holder<Biome>> biomeRegistry, long seed) { public BCLibNetherBiomeSource(Registry<Biome> biomeRegistry, long seed) {
super(biomeRegistry, seed, getBiomes(biomeRegistry)); super(biomeRegistry, seed, getBiomes(biomeRegistry));
BiomeAPI.NETHER_BIOME_PICKER.clearMutables(); BiomeAPI.NETHER_BIOME_PICKER.clearMutables();
@ -97,34 +97,37 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
initMap(); initMap();
} }
private static List<Holder<Biome>> getBiomes(Registry<Holder<Biome>> biomeRegistry) { private static List<Holder<Biome>> getBiomes(Registry<Biome> biomeRegistry) {
List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include", "nether_biomes", StringArrayEntry.class).getValue(); List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include", "nether_biomes", StringArrayEntry.class).getValue();
return biomeRegistry.stream().filter(biome -> { return biomeRegistry.stream()
ResourceLocation key = biomeRegistry.getKey(biome); .filter(biome -> biomeRegistry.getResourceKey(biome).isPresent())
.map(biome -> biomeRegistry.getOrCreateHolder(biomeRegistry.getResourceKey(biome).get()))
if (include.contains(key.toString())) { .filter(biome -> {
return true; ResourceLocation key = biome.unwrapKey().orElseThrow().location();
}
if (include.contains(key.toString())) {
if (GeneratorOptions.addNetherBiomesByCategory() && (biome instanceof BiomeAccessor) && ((BiomeAccessor)(Object)biome).bclib_getBiomeCategory()== BiomeCategory.NETHER) { return true;
return true; }
}
if (GeneratorOptions.addNetherBiomesByCategory() && (biome instanceof BiomeAccessor) && ((BiomeAccessor)(Object)biome).bclib_getBiomeCategory()== BiomeCategory.NETHER) {
BCLBiome bclBiome = BiomeAPI.getBiome(key); return true;
if (bclBiome != BiomeAPI.EMPTY_BIOME) { }
if (bclBiome.getParentBiome() != null) {
bclBiome = bclBiome.getParentBiome(); BCLBiome bclBiome = BiomeAPI.getBiome(key);
} if (bclBiome != BiomeAPI.EMPTY_BIOME) {
key = bclBiome.getID(); if (bclBiome.getParentBiome() != null) {
} bclBiome = bclBiome.getParentBiome();
final boolean isNetherBiome; }
if ((Object)biome instanceof BiomeAccessor bacc) { key = bclBiome.getID();
isNetherBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.NETHER; }
} else { final boolean isNetherBiome;
isNetherBiome = false; if ((Object)biome instanceof BiomeAccessor bacc) {
} isNetherBiome = bacc.bclib_getBiomeCategory() == BiomeCategory.NETHER;
return BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key) || (isNetherBiome && BiomeAPI.isDatapackBiome(key)); } else {
isNetherBiome = false;
}
return BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key) || (isNetherBiome && BiomeAPI.isDatapackBiome(key));
}).toList(); }).toList();
} }