Fixes to BiomeSources

This commit is contained in:
Frank 2022-03-14 17:00:44 +01:00
parent ff70a2b1a8
commit 2eccb1cb9e
3 changed files with 30 additions and 17 deletions

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<Biome> biomeRegistry) {
public void updateActualBiomes(Registry<Holder<Biome>> biomeRegistry) {
subbiomes.forEach((sub) -> {
if (sub != this) {
sub.updateActualBiomes(biomeRegistry);
@ -200,12 +200,15 @@ public class BCLBiome extends BCLBiomeSettings {
if (edge != null && edge != this) {
edge.updateActualBiomes(biomeRegistry);
}
this.actualBiome = biomeRegistry.getHolder(ResourceKey.create(Registry.BIOME_REGISTRY, biomeID)).orElse(null);
final ResourceKey<Holder<Biome>> key = ResourceKey.create(biomeRegistry.key(), biomeID);
this.actualBiome = biomeRegistry.get(key);
if (actualBiome==null) {
BCLib.LOGGER.error("Unable to find actual Biome for " + biomeID);
}
if (!this.structures.isEmpty()) {
//TODO: 1.18.2 This need to be done by BiomeTags now
structures.forEach(s -> BiomeAPI.addBiomeStructure(BiomeAPI.getBiomeKey(actualBiome), s));
}

View file

@ -1,10 +1,13 @@
package ru.bclib.world.generator;
import com.mojang.datafixers.kinds.Applicative;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biome.BiomeCategory;
@ -31,8 +34,7 @@ import java.util.List;
import java.util.function.Function;
public class BCLibEndBiomeSource extends BCLBiomeSource {
public static Codec<BCLibEndBiomeSource> CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps
.retrieveRegistry(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> theEndBiomeSource.biomeRegistry), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> theEndBiomeSource.seed)).apply(instance, instance.stable(BCLibEndBiomeSource::new)));
public static Codec<BCLibEndBiomeSource> CODEC = RecordCodecBuilder.create((instance) -> instance.group(RegistryOps.retrieveRegistry(Registry.BIOME_REGISTRY).forGetter((theEndBiomeSource) -> null), Codec.LONG.fieldOf("seed").stable().forGetter((theEndBiomeSource) -> theEndBiomeSource.seed)).apply(instance, instance.stable(BCLibEndBiomeSource::new)));
private static final OpenSimplexNoise SMALL_NOISE = new OpenSimplexNoise(8324);
private Function<Point, Boolean> endLandFunction;
@ -43,7 +45,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
private BiomeMap mapVoid;
private final Point pos;
public BCLibEndBiomeSource(Registry<Biome> biomeRegistry, long seed) {
public BCLibEndBiomeSource(Registry<Holder<Biome>> biomeRegistry, long seed) {
super(biomeRegistry, seed, getBiomes(biomeRegistry));
BiomeAPI.END_LAND_BIOME_PICKER.clearMutables();
@ -51,11 +53,11 @@ 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.value());
ResourceLocation key = biomeRegistry.getKey(biome);
String group = key.getNamespace() + "." + key.getPath();
if (!BiomeAPI.hasBiome(key)) {
BCLBiome bclBiome = new BCLBiome(key, biome);
BCLBiome bclBiome = new BCLBiome(key, biome.value());
if (includeVoid.contains(key.toString())) {
BiomeAPI.END_VOID_BIOME_PICKER.addBiomeMutable(bclBiome);
@ -96,8 +98,8 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
this.mapVoid = new HexBiomeMap(seed, GeneratorOptions.getBiomeSizeEndVoid(), BiomeAPI.END_VOID_BIOME_PICKER);
}
this.centerBiome = biomeRegistry.getHolderOrThrow(Biomes.THE_END);
this.barrens = biomeRegistry.getHolderOrThrow(Biomes.END_BARRENS);
this.centerBiome = biomeRegistry.get(Biomes.THE_END.location());
this.barrens = biomeRegistry.get(Biomes.END_BARRENS.location());
WorldgenRandom chunkRandom = new WorldgenRandom(new LegacyRandomSource(seed));
chunkRandom.consumeCount(17292);
@ -107,7 +109,7 @@ public class BCLibEndBiomeSource extends BCLBiomeSource {
this.pos = new Point();
}
private static List<Biome> getBiomes(Registry<Biome> biomeRegistry) {
private static List<Holder<Biome>> getBiomes(Registry<Holder<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();

View file

@ -2,8 +2,10 @@ package ru.bclib.world.generator;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.core.Holder;
import net.minecraft.core.Registry;
import net.minecraft.resources.RegistryOps;
import net.minecraft.resources.ResourceKey;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.biome.Biome.BiomeCategory;
@ -29,7 +31,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
.create(instance -> instance
.group(RegistryOps
.retrieveRegistry(Registry.BIOME_REGISTRY)
.forGetter(source -> source.biomeRegistry)
.forGetter(source -> null)
,
Codec
.LONG
@ -65,16 +67,16 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
BCLibNetherBiomeSource.worldHeight = worldHeight;
}
public BCLibNetherBiomeSource(Registry<Biome> biomeRegistry, long seed) {
public BCLibNetherBiomeSource(Registry<Holder<Biome>> biomeRegistry, long seed) {
super(biomeRegistry, seed, getBiomes(biomeRegistry));
BiomeAPI.NETHER_BIOME_PICKER.clearMutables();
this.possibleBiomes().forEach(biome -> {
ResourceLocation key = biomeRegistry.getKey(biome.value());
ResourceLocation key = biome.unwrapKey().orElseThrow().location();
if (!BiomeAPI.hasBiome(key)) {
BCLBiome bclBiome = new BCLBiome(key, biome);
BCLBiome bclBiome = new BCLBiome(key, biome.value());
BiomeAPI.NETHER_BIOME_PICKER.addBiomeMutable(bclBiome);
}
else {
@ -95,7 +97,7 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
initMap();
}
private static List<Biome> getBiomes(Registry<Biome> biomeRegistry) {
private static List<Holder<Biome>> getBiomes(Registry<Holder<Biome>> biomeRegistry) {
List<String> include = Configs.BIOMES_CONFIG.getEntry("force_include", "nether_biomes", StringArrayEntry.class).getValue();
return biomeRegistry.stream().filter(biome -> {
@ -116,12 +118,18 @@ public class BCLibNetherBiomeSource extends BCLBiomeSource {
}
key = bclBiome.getID();
}
return BiomeAPI.NETHER_BIOME_PICKER.containsImmutable(key) || (biome.getBiomeCategory() == BiomeCategory.NETHER && BiomeAPI.isDatapackBiome(key));
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();
}
@Override
public Biome getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler var4) {
public Holder<Biome> getNoiseBiome(int biomeX, int biomeY, int biomeZ, Climate.Sampler var4) {
if (lastWorldHeight != worldHeight) {
lastWorldHeight = worldHeight;
initMap();