Fixed all biomes being classed as "ocean"

This commit is contained in:
Adubbz 2020-09-19 19:44:25 +10:00
parent 7970d1bfff
commit 83f0b8d4be
6 changed files with 35 additions and 23 deletions

View file

@ -8,6 +8,7 @@
package biomesoplenty.common.util.biome; package biomesoplenty.common.util.biome;
import biomesoplenty.common.biome.BiomeMetadata; import biomesoplenty.common.biome.BiomeMetadata;
import biomesoplenty.core.BiomesOPlenty;
import biomesoplenty.init.ModBiomes; import biomesoplenty.init.ModBiomes;
import net.minecraft.util.RegistryKey; import net.minecraft.util.RegistryKey;
import net.minecraft.util.registry.DynamicRegistries; import net.minecraft.util.registry.DynamicRegistries;
@ -31,21 +32,21 @@ public class BiomeUtil
public static Biome getBiome(RegistryKey<Biome> key) public static Biome getBiome(RegistryKey<Biome> key)
{ {
Biome biome = ForgeRegistries.BIOMES.getValue(key.location()); Biome biome = ForgeRegistries.BIOMES.getValue(key.location());
if (biome == null) throw new RuntimeException("Attempted to get unregistered biome " + key); if (biome == null) BiomesOPlenty.logger.error("Attempted to get unregistered biome " + key);
return biome; return biome;
} }
public static Biome getBiome(int id) public static Biome getBiome(int id)
{ {
if (id == -1) throw new RuntimeException("Attempted to get biome with id -1"); if (id == -1) BiomesOPlenty.logger.error("Attempted to get biome with id -1");
return getBiome(((ForgeRegistry<Biome>)ForgeRegistries.BIOMES).getKey(id)); return getBiome(((ForgeRegistry<Biome>)ForgeRegistries.BIOMES).getKey(id));
} }
public static int getBiomeId(Biome biome) public static int getBiomeId(Biome biome)
{ {
if (biome == null) throw new RuntimeException("Attempted to get id of null biome"); if (biome == null) BiomesOPlenty.logger.error("Attempted to get id of null biome");
int id = ((ForgeRegistry<Biome>)ForgeRegistries.BIOMES).getID(biome); int id = ((ForgeRegistry<Biome>)ForgeRegistries.BIOMES).getID(biome);
if (id == -1) throw new RuntimeException("Biome id is -1 for biome " + biome.delegate.name()); if (id == -1) BiomesOPlenty.logger.error("Biome id is -1 for biome " + biome.delegate.name());
return id; return id;
} }

View file

@ -28,7 +28,7 @@ public class BOPBiomeGeneratorTypeScreen extends BiomeGeneratorTypeScreens
@Override @Override
protected ChunkGenerator generator(Registry<Biome> biomeRegistry, Registry<DimensionSettings> dimensionSettingsRegistry, long seed) protected ChunkGenerator generator(Registry<Biome> biomeRegistry, Registry<DimensionSettings> dimensionSettingsRegistry, long seed)
{ {
return BOPWorldTypeUtil.createChunkGenerator(seed); return BOPWorldTypeUtil.makeOverworld(biomeRegistry, dimensionSettingsRegistry, seed);
} }
@Override @Override

View file

@ -15,11 +15,13 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.util.RegistryKey; import net.minecraft.util.RegistryKey;
import net.minecraft.util.registry.DynamicRegistries; import net.minecraft.util.registry.DynamicRegistries;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryLookupCodec;
import net.minecraft.util.registry.WorldGenRegistries; import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes; import net.minecraft.world.biome.Biomes;
import net.minecraft.world.biome.provider.BiomeProvider; import net.minecraft.world.biome.provider.BiomeProvider;
import net.minecraft.world.gen.layer.Layer; import net.minecraft.world.gen.layer.Layer;
import net.minecraft.world.gen.layer.LayerUtil;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
import java.util.List; import java.util.List;
@ -30,21 +32,24 @@ public class BOPBiomeProvider extends BiomeProvider
{ {
public static final Codec<BOPBiomeProvider> CODEC = RecordCodecBuilder.create((builder) -> public static final Codec<BOPBiomeProvider> CODEC = RecordCodecBuilder.create((builder) ->
{ {
return builder.group(Codec.LONG.fieldOf("seed").stable().forGetter((biomeProvider) -> biomeProvider.seed)).apply(builder, builder.stable(BOPBiomeProvider::new)); return builder.group(
Codec.LONG.fieldOf("seed").stable().forGetter((biomeProvider) -> biomeProvider.seed),
RegistryLookupCodec.create(Registry.BIOME_REGISTRY).forGetter((biomeProvider) -> biomeProvider.biomes)
).apply(builder, builder.stable(BOPBiomeProvider::new));
}); });
private static final List<RegistryKey<Biome>> VANILLA_POSSIBLE_BIOMES = ImmutableList.of(Biomes.OCEAN, Biomes.PLAINS, Biomes.DESERT, Biomes.MOUNTAINS, Biomes.FOREST, Biomes.TAIGA, Biomes.SWAMP, Biomes.RIVER, Biomes.FROZEN_OCEAN, Biomes.FROZEN_RIVER, Biomes.SNOWY_TUNDRA, Biomes.SNOWY_MOUNTAINS, Biomes.MUSHROOM_FIELDS, Biomes.MUSHROOM_FIELD_SHORE, Biomes.BEACH, Biomes.DESERT_HILLS, Biomes.WOODED_HILLS, Biomes.TAIGA_HILLS, Biomes.MOUNTAIN_EDGE, Biomes.JUNGLE, Biomes.JUNGLE_HILLS, Biomes.JUNGLE_EDGE, Biomes.DEEP_OCEAN, Biomes.STONE_SHORE, Biomes.SNOWY_BEACH, Biomes.BIRCH_FOREST, Biomes.BIRCH_FOREST_HILLS, Biomes.DARK_FOREST, Biomes.SNOWY_TAIGA, Biomes.SNOWY_TAIGA_HILLS, Biomes.GIANT_TREE_TAIGA, Biomes.GIANT_TREE_TAIGA_HILLS, Biomes.WOODED_MOUNTAINS, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU, Biomes.BADLANDS, Biomes.WOODED_BADLANDS_PLATEAU, Biomes.BADLANDS_PLATEAU, Biomes.WARM_OCEAN, Biomes.LUKEWARM_OCEAN, Biomes.COLD_OCEAN, Biomes.DEEP_WARM_OCEAN, Biomes.DEEP_LUKEWARM_OCEAN, Biomes.DEEP_COLD_OCEAN, Biomes.DEEP_FROZEN_OCEAN, Biomes.SUNFLOWER_PLAINS, Biomes.DESERT_LAKES, Biomes.GRAVELLY_MOUNTAINS, Biomes.FLOWER_FOREST, Biomes.TAIGA_MOUNTAINS, Biomes.SWAMP_HILLS, Biomes.ICE_SPIKES, Biomes.MODIFIED_JUNGLE, Biomes.MODIFIED_JUNGLE_EDGE, Biomes.TALL_BIRCH_FOREST, Biomes.TALL_BIRCH_HILLS, Biomes.DARK_FOREST_HILLS, Biomes.SNOWY_TAIGA_MOUNTAINS, Biomes.GIANT_SPRUCE_TAIGA, Biomes.GIANT_SPRUCE_TAIGA_HILLS, Biomes.MODIFIED_GRAVELLY_MOUNTAINS, Biomes.SHATTERED_SAVANNA, Biomes.SHATTERED_SAVANNA_PLATEAU, Biomes.ERODED_BADLANDS, Biomes.MODIFIED_WOODED_BADLANDS_PLATEAU, Biomes.MODIFIED_BADLANDS_PLATEAU); private static final List<RegistryKey<Biome>> VANILLA_POSSIBLE_BIOMES = ImmutableList.of(Biomes.OCEAN, Biomes.PLAINS, Biomes.DESERT, Biomes.MOUNTAINS, Biomes.FOREST, Biomes.TAIGA, Biomes.SWAMP, Biomes.RIVER, Biomes.FROZEN_OCEAN, Biomes.FROZEN_RIVER, Biomes.SNOWY_TUNDRA, Biomes.SNOWY_MOUNTAINS, Biomes.MUSHROOM_FIELDS, Biomes.MUSHROOM_FIELD_SHORE, Biomes.BEACH, Biomes.DESERT_HILLS, Biomes.WOODED_HILLS, Biomes.TAIGA_HILLS, Biomes.MOUNTAIN_EDGE, Biomes.JUNGLE, Biomes.JUNGLE_HILLS, Biomes.JUNGLE_EDGE, Biomes.DEEP_OCEAN, Biomes.STONE_SHORE, Biomes.SNOWY_BEACH, Biomes.BIRCH_FOREST, Biomes.BIRCH_FOREST_HILLS, Biomes.DARK_FOREST, Biomes.SNOWY_TAIGA, Biomes.SNOWY_TAIGA_HILLS, Biomes.GIANT_TREE_TAIGA, Biomes.GIANT_TREE_TAIGA_HILLS, Biomes.WOODED_MOUNTAINS, Biomes.SAVANNA, Biomes.SAVANNA_PLATEAU, Biomes.BADLANDS, Biomes.WOODED_BADLANDS_PLATEAU, Biomes.BADLANDS_PLATEAU, Biomes.WARM_OCEAN, Biomes.LUKEWARM_OCEAN, Biomes.COLD_OCEAN, Biomes.DEEP_WARM_OCEAN, Biomes.DEEP_LUKEWARM_OCEAN, Biomes.DEEP_COLD_OCEAN, Biomes.DEEP_FROZEN_OCEAN, Biomes.SUNFLOWER_PLAINS, Biomes.DESERT_LAKES, Biomes.GRAVELLY_MOUNTAINS, Biomes.FLOWER_FOREST, Biomes.TAIGA_MOUNTAINS, Biomes.SWAMP_HILLS, Biomes.ICE_SPIKES, Biomes.MODIFIED_JUNGLE, Biomes.MODIFIED_JUNGLE_EDGE, Biomes.TALL_BIRCH_FOREST, Biomes.TALL_BIRCH_HILLS, Biomes.DARK_FOREST_HILLS, Biomes.SNOWY_TAIGA_MOUNTAINS, Biomes.GIANT_SPRUCE_TAIGA, Biomes.GIANT_SPRUCE_TAIGA_HILLS, Biomes.MODIFIED_GRAVELLY_MOUNTAINS, Biomes.SHATTERED_SAVANNA, Biomes.SHATTERED_SAVANNA_PLATEAU, Biomes.ERODED_BADLANDS, Biomes.MODIFIED_WOODED_BADLANDS_PLATEAU, Biomes.MODIFIED_BADLANDS_PLATEAU);
private final long seed; private final long seed;
private final Layer noiseBiomeLayer; private final Layer noiseBiomeLayer;
private final Registry<Biome> biomeRegistry; private final Registry<Biome> biomes;
public BOPBiomeProvider(long seed) public BOPBiomeProvider(long seed, Registry<Biome> biomes)
{ {
super(Stream.concat(VANILLA_POSSIBLE_BIOMES.stream(), BOPClimates.getOverworldBiomes().stream()).map(BiomeUtil::getBiome).collect(Collectors.toList())); super(Stream.concat(VANILLA_POSSIBLE_BIOMES.stream(), BOPClimates.getOverworldBiomes().stream()).map(BiomeUtil::getBiome).collect(Collectors.toList()));
this.seed = seed; this.seed = seed;
this.noiseBiomeLayer = BOPLayerUtil.createGenLayers(seed, new BOPOverworldGenSettings()); this.noiseBiomeLayer = BOPLayerUtil.createGenLayers(seed, new BOPOverworldGenSettings());
this.biomeRegistry = DynamicRegistries.builtin().registryOrThrow(Registry.BIOME_REGISTRY); this.biomes = biomes;
} }
@Override @Override
@ -56,12 +61,12 @@ public class BOPBiomeProvider extends BiomeProvider
@Override @Override
public BiomeProvider withSeed(long seed) public BiomeProvider withSeed(long seed)
{ {
return new BOPBiomeProvider(seed); return new BOPBiomeProvider(seed, this.biomes);
} }
@Override @Override
public Biome getNoiseBiome(int x, int y, int z) public Biome getNoiseBiome(int x, int y, int z)
{ {
return this.noiseBiomeLayer.get(biomeRegistry, x, z); return this.noiseBiomeLayer.get(this.biomes, x, z);
} }
} }

View file

@ -46,7 +46,7 @@ public class BOPDimensionType extends DimensionType
if (ModConfig.GenerationConfig.useBopNether.get()) if (ModConfig.GenerationConfig.useBopNether.get())
{ {
biomeProvider = new BOPNetherBiomeProvider(seed); biomeProvider = new BOPNetherBiomeProvider(seed, biomeRegistry);
} }
else else
{ {

View file

@ -13,6 +13,8 @@ import com.google.common.collect.ImmutableList;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.util.RegistryKey; import net.minecraft.util.RegistryKey;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryLookupCodec;
import net.minecraft.util.registry.WorldGenRegistries; import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.Biomes; import net.minecraft.world.biome.Biomes;
@ -26,18 +28,25 @@ import java.util.stream.Stream;
public class BOPNetherBiomeProvider extends BiomeProvider public class BOPNetherBiomeProvider extends BiomeProvider
{ {
public static final Codec<BOPNetherBiomeProvider> CODEC = RecordCodecBuilder.create((builder) -> builder.group(Codec.LONG.fieldOf("seed").stable().forGetter((biomeProvider) -> biomeProvider.seed)).apply(builder, builder.stable(BOPNetherBiomeProvider::new))); public static final Codec<BOPNetherBiomeProvider> CODEC = RecordCodecBuilder.create((builder) ->
{
return builder.group(
Codec.LONG.fieldOf("seed").stable().forGetter((biomeProvider) -> biomeProvider.seed),
RegistryLookupCodec.create(Registry.BIOME_REGISTRY).forGetter((biomeProvider) -> biomeProvider.biomes)
).apply(builder, builder.stable(BOPNetherBiomeProvider::new));
});
private static final List<RegistryKey<Biome>> VANILLA_POSSIBLE_BIOMES = ImmutableList.of(Biomes.NETHER_WASTES, Biomes.SOUL_SAND_VALLEY, Biomes.CRIMSON_FOREST, Biomes.WARPED_FOREST, Biomes.BASALT_DELTAS); private static final List<RegistryKey<Biome>> VANILLA_POSSIBLE_BIOMES = ImmutableList.of(Biomes.NETHER_WASTES, Biomes.SOUL_SAND_VALLEY, Biomes.CRIMSON_FOREST, Biomes.WARPED_FOREST, Biomes.BASALT_DELTAS);
private final long seed; private final long seed;
private final Layer noiseBiomeLayer; private final Layer noiseBiomeLayer;
private final Registry<Biome> biomes;
public BOPNetherBiomeProvider(long seed) public BOPNetherBiomeProvider(long seed, Registry<Biome> biomes)
{ {
super(Stream.concat(VANILLA_POSSIBLE_BIOMES.stream(), BOPClimates.NETHER.getLandBiomes().stream().map((entry) -> entry.biome)).map(BiomeUtil::getBiome).collect(Collectors.toList())); super(Stream.concat(VANILLA_POSSIBLE_BIOMES.stream(), BOPClimates.NETHER.getLandBiomes().stream().map((entry) -> entry.biome)).map(BiomeUtil::getBiome).collect(Collectors.toList()));
this.seed = seed; this.seed = seed;
this.noiseBiomeLayer = BOPNetherLayerUtil.createGenLayers(seed); this.noiseBiomeLayer = BOPNetherLayerUtil.createGenLayers(seed);
this.biomes = biomes;
} }
@Override @Override
@ -49,12 +58,12 @@ public class BOPNetherBiomeProvider extends BiomeProvider
@Override @Override
public BiomeProvider withSeed(long seed) public BiomeProvider withSeed(long seed)
{ {
return new BOPNetherBiomeProvider(seed); return new BOPNetherBiomeProvider(seed, this.biomes);
} }
@Override @Override
public Biome getNoiseBiome(int x, int y, int z) public Biome getNoiseBiome(int x, int y, int z)
{ {
return this.noiseBiomeLayer.get(WorldGenRegistries.BIOME, x, z); return this.noiseBiomeLayer.get(this.biomes, x, z);
} }
} }

View file

@ -18,15 +18,12 @@ import net.minecraft.util.registry.WorldGenRegistries;
import net.minecraft.world.Dimension; import net.minecraft.world.Dimension;
import net.minecraft.world.DimensionType; import net.minecraft.world.DimensionType;
import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome;
import net.minecraft.world.biome.provider.EndBiomeProvider;
import net.minecraft.world.biome.provider.NetherBiomeProvider; import net.minecraft.world.biome.provider.NetherBiomeProvider;
import net.minecraft.world.gen.ChunkGenerator; import net.minecraft.world.gen.ChunkGenerator;
import net.minecraft.world.gen.DimensionSettings; import net.minecraft.world.gen.DimensionSettings;
import net.minecraft.world.gen.NoiseChunkGenerator; import net.minecraft.world.gen.NoiseChunkGenerator;
import net.minecraft.world.gen.settings.DimensionGeneratorSettings; import net.minecraft.world.gen.settings.DimensionGeneratorSettings;
import net.minecraft.world.storage.ServerWorldInfo; import net.minecraft.world.storage.ServerWorldInfo;
import net.minecraftforge.registries.ForgeRegistries;
import org.spongepowered.asm.mixin.Dynamic;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
@ -74,9 +71,9 @@ public class BOPWorldTypeUtil
return true; return true;
} }
public static ChunkGenerator createChunkGenerator(long seed) public static ChunkGenerator makeOverworld(Registry<Biome> biomes, Registry<DimensionSettings> noiseGeneratorSettings, long seed)
{ {
return new NoiseChunkGenerator(new BOPBiomeProvider(seed), seed, () -> WorldGenRegistries.NOISE_GENERATOR_SETTINGS.getOrThrow(DimensionSettings.OVERWORLD)); return new NoiseChunkGenerator(new BOPBiomeProvider(seed, biomes), seed, () -> noiseGeneratorSettings.getOrThrow(DimensionSettings.OVERWORLD));
} }
public static DimensionGeneratorSettings createDimensionGeneratorSettings(DynamicRegistries registries, long seed, boolean generateFeatures, boolean generateBonusChest) public static DimensionGeneratorSettings createDimensionGeneratorSettings(DynamicRegistries registries, long seed, boolean generateFeatures, boolean generateBonusChest)
@ -84,7 +81,7 @@ public class BOPWorldTypeUtil
Registry<Biome> biomeRegistry = registries.registryOrThrow(Registry.BIOME_REGISTRY); Registry<Biome> biomeRegistry = registries.registryOrThrow(Registry.BIOME_REGISTRY);
Registry<DimensionSettings> dimensionSettingsRegistry = registries.registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY); Registry<DimensionSettings> dimensionSettingsRegistry = registries.registryOrThrow(Registry.NOISE_GENERATOR_SETTINGS_REGISTRY);
Registry<DimensionType> dimensionTypeRegistry = registries.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY); Registry<DimensionType> dimensionTypeRegistry = registries.registryOrThrow(Registry.DIMENSION_TYPE_REGISTRY);
return new DimensionGeneratorSettings(seed, generateFeatures, generateBonusChest, DimensionGeneratorSettings.withOverworld(dimensionTypeRegistry, BOPDimensionType.bopDimensions(biomeRegistry, dimensionSettingsRegistry, seed), createChunkGenerator(seed))); return new DimensionGeneratorSettings(seed, generateFeatures, generateBonusChest, DimensionGeneratorSettings.withOverworld(dimensionTypeRegistry, BOPDimensionType.bopDimensions(biomeRegistry, dimensionSettingsRegistry, seed), makeOverworld(biomeRegistry, dimensionSettingsRegistry, seed)));
} }
public static void setupForDedicatedServer(DedicatedServer server) public static void setupForDedicatedServer(DedicatedServer server)