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<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 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_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 SMALL_END_ISLANDS = registerEndVoidBiome(getFromRegistry(new ResourceLocation("small_end_islands")).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")));
private static void initFeatureOrder() {
if (!FEATURE_ORDER.isEmpty()) {
@ -123,7 +123,7 @@ public class BiomeAPI {
* Initialize registry for current server.
* @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) {
BiomeAPI.biomeRegistry = biomeRegistry;
CLIENT.clear();
@ -143,15 +143,17 @@ public class BiomeAPI {
/**
* Register {@link BCLBiome} instance and its {@link Biome} if necessary.
* @param biome {@link BCLBiome}
* @param bclbiome {@link BCLBiome}
* @return {@link BCLBiome}
*/
public static BCLBiome registerBiome(BCLBiome biome) {
if (BuiltinRegistries.BIOME.get(biome.getID()) == null) {
Registry.register(BuiltinRegistries.BIOME, biome.getID(), biome.getBiome());
public static BCLBiome registerBiome(BCLBiome bclbiome) {
if (BuiltinRegistries.BIOME.get(bclbiome.getID()) == null) {
final Biome biome = bclbiome.getBiome();
ResourceLocation loc = bclbiome.getID();
Registry.register(BuiltinRegistries.BIOME, loc, biome);
}
ID_MAP.put(biome.getID(), biome);
return biome;
ID_MAP.put(bclbiome.getID(), bclbiome);
return bclbiome;
}
public static BCLBiome registerSubBiome(BCLBiome parent, BCLBiome subBiome) {
@ -273,8 +275,8 @@ public class BiomeAPI {
* @param biome {@link BCLBiome}
* @return {@link BCLBiome}
*/
public static BCLBiome registerEndVoidBiome(Biome biome) {
BCLBiome bclBiome = new BCLBiome(biome, null);
public static BCLBiome registerEndVoidBiome(Holder<Biome> biome) {
BCLBiome bclBiome = new BCLBiome(biome.value(), null);
END_VOID_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome);
@ -288,8 +290,8 @@ public class BiomeAPI {
* @param genChance float generation chance.
* @return {@link BCLBiome}
*/
public static BCLBiome registerEndVoidBiome(Biome biome, float genChance) {
BCLBiome bclBiome = new BCLBiome(biome, VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
public static BCLBiome registerEndVoidBiome(Holder<Biome> biome, float genChance) {
BCLBiome bclBiome = new BCLBiome(biome.value(), VanillaBiomeSettings.createVanilla().setGenChance(genChance).build());
END_VOID_BIOME_PICKER.addBiome(bclBiome);
registerBiome(bclBiome);
@ -301,7 +303,7 @@ public class BiomeAPI {
* @param biome - {@link Biome} from world.
* @return {@link BCLBiome} or {@code BiomeAPI.EMPTY_BIOME}.
*/
public static BCLBiome getFromBiome(Holder<Biome> biome) {
public static BCLBiome getFromBiome(Biome biome) {
if (biomeRegistry == null) {
return EMPTY_BIOME;
}
@ -334,7 +336,7 @@ public class BiomeAPI {
public static ResourceKey getBiomeKey(Biome biome) {
return BuiltinRegistries.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) {
ResourceLocation id = BuiltinRegistries.BIOME.getKey(biome);
// if (id == null && biomeRegistry != null) {
// id = biomeRegistry.getKey(biome);
//}
if (id == null && biomeRegistry != null) {
id = biomeRegistry.getKey(biome);
}
return id == null ? EMPTY_BIOME.getID() : id;
}

View file

@ -12,7 +12,7 @@ import java.util.function.Function;
public interface NumericProvider {
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());
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.
* @param biomeRegistry {@link Registry} for {@link Biome}.
*/
public void updateActualBiomes(Registry<Holder<Biome>> biomeRegistry) {
public void updateActualBiomes(Registry<Biome> biomeRegistry) {
subbiomes.forEach((sub) -> {
if (sub != this) {
sub.updateActualBiomes(biomeRegistry);
@ -201,8 +201,8 @@ public class BCLBiome extends BCLBiomeSettings {
edge.updateActualBiomes(biomeRegistry);
}
final ResourceKey<Holder<Biome>> key = ResourceKey.create(biomeRegistry.key(), biomeID);
this.actualBiome = biomeRegistry.get(key);
final ResourceKey<Biome> key = biomeRegistry.getResourceKey(biomeRegistry.get(biomeID)).orElseThrow();
this.actualBiome = biomeRegistry.getOrCreateHolder(key);
if (actualBiome==null) {
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;
public abstract class BCLBiomeSource extends BiomeSource {
protected final Registry<Holder<Biome>> biomeRegistry;
protected final Registry<Biome> biomeRegistry;
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));
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));
this.seed = seed;

View file

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

View file

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