Vanilla biome weights are now configurable

This commit is contained in:
Adubbz 2020-02-18 22:53:47 +11:00
parent efca80836c
commit 42680921e5
4 changed files with 109 additions and 52 deletions

View file

@ -131,24 +131,6 @@ public enum BOPClimates
return new WeightedBiomeEntry(100, Biomes.OCEAN);
}
static
{
// Set up vanilla biomes
BOPClimates.ICE_CAP.addBiome(10, Biomes.SNOWY_TUNDRA);
BOPClimates.TUNDRA.addBiome(10, Biomes.SNOWY_TAIGA).addBiome(7, Biomes.MOUNTAINS);
BOPClimates.WET_BOREAL.addBiome(10, Biomes.TAIGA);
BOPClimates.DRY_BOREAL.addBiome(5, Biomes.GIANT_TREE_TAIGA);
BOPClimates.WET_TEMPERATE.addBiome(5, Biomes.DARK_FOREST).addBiome(7, Biomes.SWAMP);
BOPClimates.DRY_TEMPERATE.addBiome(7, Biomes.BIRCH_FOREST);
BOPClimates.COOL_TEMPERATE.addBiome(10, Biomes.FOREST);
BOPClimates.WARM_TEMPERATE.addBiome(10, Biomes.PLAINS);
BOPClimates.TROPICAL.addBiome(15, Biomes.JUNGLE);
BOPClimates.SAVANNA.addBiome(10, Biomes.SAVANNA);
BOPClimates.HOT_DESERT.addBiome(15, Biomes.DESERT).addBiome(10, Biomes.BADLANDS_PLATEAU).addBiome(3, Biomes.WOODED_BADLANDS_PLATEAU);
BOPClimates.NETHER.addBiome(10, Biomes.NETHER);
}
private static BOPClimates[] values = BOPClimates.values();
public static BOPClimates lookup(int i) {return values[i];}

View file

@ -7,18 +7,15 @@
******************************************************************************/
package biomesoplenty.common.biome;
import biomesoplenty.api.enums.BOPClimates;
import biomesoplenty.core.BiomesOPlenty;
import com.google.common.collect.Maps;
import com.google.gson.annotations.SerializedName;
import java.util.Map;
import java.util.TreeMap;
public class BiomeConfigData
{
@SerializedName("standard_weights")
public TreeMap<String, StandardBiomeEntry> standardBiomeWeights = Maps.newTreeMap();
public TreeMap<String, WeightedBiomeEntry> standardBiomeWeights = Maps.newTreeMap();
@SerializedName("sub_biome_weights")
public TreeMap<String, SubBiomeEntry> subBiomeEntries = Maps.newTreeMap();
@ -26,11 +23,14 @@ public class BiomeConfigData
//@SerializedName("island_biome_weights")
//public Map<String, IslandBiomeEntry> islandBiomeEntries = Maps.newHashMap();
public static class StandardBiomeEntry
@SerializedName("vanilla_biome_weights")
public TreeMap<String, WeightedBiomeEntry> vanillaBiomeEntries = Maps.newTreeMap();
public static class WeightedBiomeEntry
{
public int weight;
public StandardBiomeEntry(int weight)
public WeightedBiomeEntry(int weight)
{
this.weight = weight;
}
@ -47,14 +47,4 @@ public class BiomeConfigData
this.rarity = rarity;
}
}
public static class IslandBiomeEntry
{
public int weight;
public IslandBiomeEntry(int weight)
{
this.weight = weight;
}
}
}

View file

@ -49,13 +49,18 @@ public class BiomeRegistry
public static void deferIslandBiomeRegistration(Biome biome, BOPClimates climate, int weight)
{
defer(RegistrationType.ISLAND_BIOME, new IslandBiomeRegistrationData(biome, climate, weight));
defer(RegistrationType.ISLAND_BIOME, new SingleClimateRegistrationData(biome, climate, weight));
}
public static void deferVanillaBiomeRegistration(Biome biome, BOPClimates climate, int weight)
{
defer(RegistrationType.VANILLA_BIOME, new SingleClimateRegistrationData(biome, climate, weight));
}
public static void configureStandardBiomes()
{
List<DeferredRegistration> standardRegistrations = deferrances.get(RegistrationType.STANDARD_BIOME);
TreeMap<String, BiomeConfigData.StandardBiomeEntry> defaultEntries = Maps.newTreeMap();
TreeMap<String, BiomeConfigData.WeightedBiomeEntry> defaultEntries = Maps.newTreeMap();
Map<String, StandardBiomeRegistrationData> regDataMap = Maps.newHashMap();
for (DeferredRegistration<StandardBiomeRegistrationData> registration : standardRegistrations)
@ -67,21 +72,19 @@ public class BiomeRegistry
{
String biomeName = new ResourceLocation(BiomesOPlenty.MOD_ID, regData.getName()).toString();
Pair<BOPClimates, Integer> primaryWeight = regData.getPrimaryWeight();
defaultEntries.put(biomeName, new BiomeConfigData.StandardBiomeEntry(primaryWeight.getValue()));
defaultEntries.put(biomeName, new BiomeConfigData.WeightedBiomeEntry(primaryWeight.getValue()));
regDataMap.put(biomeName, registration.regData);
}
}
BiomesOPlenty.logger.info(defaultEntries.keySet());
BiomeConfigData defaultConfigData = new BiomeConfigData();
defaultConfigData.standardBiomeWeights = defaultEntries;
BiomeConfigData configData = getConfigData(defaultConfigData);
TreeMap<String, BiomeConfigData.StandardBiomeEntry> revisedStandardBiomeWeights = Maps.newTreeMap(defaultEntries);
TreeMap<String, BiomeConfigData.WeightedBiomeEntry> revisedStandardBiomeWeights = Maps.newTreeMap(defaultEntries);
// Merge the config file with the default values
for (Map.Entry<String, BiomeConfigData.StandardBiomeEntry> biomeEntry : configData.standardBiomeWeights.entrySet())
for (Map.Entry<String, BiomeConfigData.WeightedBiomeEntry> biomeEntry : configData.standardBiomeWeights.entrySet())
{
if (revisedStandardBiomeWeights.containsKey(biomeEntry.getKey()))
{
@ -93,10 +96,10 @@ public class BiomeRegistry
configData.standardBiomeWeights = revisedStandardBiomeWeights;
JsonUtil.writeFile(getConfigFile(), configData);
for (Map.Entry<String, BiomeConfigData.StandardBiomeEntry> biomeEntry : configData.standardBiomeWeights.entrySet())
for (Map.Entry<String, BiomeConfigData.WeightedBiomeEntry> biomeEntry : configData.standardBiomeWeights.entrySet())
{
String name = biomeEntry.getKey();
BiomeConfigData.StandardBiomeEntry weight = biomeEntry.getValue();
BiomeConfigData.WeightedBiomeEntry weight = biomeEntry.getValue();
// Replace the default weight map for this biome with those from the config file
if (regDataMap.containsKey(name))
@ -203,6 +206,53 @@ public class BiomeRegistry
// }
}
public static void configureVanillaBiomes()
{
List<DeferredRegistration> islandBiomeReistrations = deferrances.get(RegistrationType.VANILLA_BIOME);
TreeMap<String, BiomeConfigData.WeightedBiomeEntry> defaultBiomeEntries = Maps.newTreeMap();
Map<String, SingleClimateRegistrationData> regDataMap = Maps.newHashMap();
for (DeferredRegistration<SingleClimateRegistrationData> registration : islandBiomeReistrations)
{
SingleClimateRegistrationData regData = registration.regData;
String biomeName = registration.regData.getBiome().delegate.name().toString();
defaultBiomeEntries.put(biomeName, new BiomeConfigData.WeightedBiomeEntry(regData.getWeight()));
regDataMap.put(biomeName, registration.regData);
}
BiomeConfigData defaultConfigData = new BiomeConfigData();
defaultConfigData.vanillaBiomeEntries = defaultBiomeEntries;
BiomeConfigData configData = getConfigData(defaultConfigData);
TreeMap<String, BiomeConfigData.WeightedBiomeEntry> revisedBiomeEntries = Maps.newTreeMap(defaultBiomeEntries);
// Merge the config file with the default values
for (Map.Entry<String, BiomeConfigData.WeightedBiomeEntry> biomeEntry : configData.vanillaBiomeEntries.entrySet())
{
if (revisedBiomeEntries.containsKey(biomeEntry.getKey()))
{
revisedBiomeEntries.put(biomeEntry.getKey(), biomeEntry.getValue());
}
}
// Write back to the config file
configData.vanillaBiomeEntries = revisedBiomeEntries;
JsonUtil.writeFile(getConfigFile(), configData);
for (Map.Entry<String, BiomeConfigData.WeightedBiomeEntry> biomeEntry : configData.vanillaBiomeEntries.entrySet())
{
String name = biomeEntry.getKey();
BiomeConfigData.WeightedBiomeEntry islandBiomeEntry = biomeEntry.getValue();
// Replace the default values for this biome with those from the config file
if (regDataMap.containsKey(name))
{
SingleClimateRegistrationData registrationData = regDataMap.get(name);
registrationData.setWeight(islandBiomeEntry.weight);
}
}
}
private static File getConfigDirFile()
{
Path configPath = FMLPaths.CONFIGDIR.get();
@ -264,7 +314,7 @@ public class BiomeRegistry
// Don't register biomes with their weight set to 0, that normally have weights that are non-zero
if (!biome.getWeightMap().isEmpty() && (data.weightMap.isEmpty() || data.weightMap.entrySet().stream().allMatch((entry) -> entry.getValue().equals(0))))
{
BiomesOPlenty.logger.info("Weights absent for " + data.getName() + ", disabling...");
BiomesOPlenty.logger.debug("Weights absent for " + data.getName() + ", disabling...");
return;
}
@ -282,7 +332,7 @@ public class BiomeRegistry
{
BOPClimates climate = entry.getKey();
int weight = entry.getValue();
BiomesOPlenty.logger.info(String.format("%s weight set to %d for climate %s", name, weight, climate.name()));
BiomesOPlenty.logger.debug(String.format("%s weight set to %d for climate %s", name, weight, climate.name()));
climate.addBiome(weight, biome);
}
}
@ -300,25 +350,34 @@ public class BiomeRegistry
SUB_BIOME((SubBiomeRegistrationData data) -> {
if (data.getWeight() == 0)
{
BiomesOPlenty.logger.warn("Weights absent for sub biome" + data.getChild().getName() + ", disabling...");
BiomesOPlenty.logger.debug("Weights absent for sub biome" + data.getChild().getName() + ", disabling...");
return;
}
String childName = data.getChild().delegate.name().toString();
BiomesOPlenty.logger.info(String.format("Sub biome %s weight set to %d", childName, data.getWeight()));
BiomesOPlenty.logger.debug(String.format("Sub biome %s weight set to %d", childName, data.getWeight()));
ModBiomes.subBiomes.put(Registry.BIOME.getId(data.getParent()), new ModBiomes.WeightedSubBiome(data.getChild(), data.getRarity(), data.getWeight()));
}),
ISLAND_BIOME((IslandBiomeRegistrationData data) -> {
ISLAND_BIOME((SingleClimateRegistrationData data) -> {
if (data.getWeight() == 0)
{
BiomesOPlenty.logger.warn("Weights absent for island biome" + data.getBiome().getName() + ", disabling...");
BiomesOPlenty.logger.debug("Weights absent for island biome" + data.getBiome().getName() + ", disabling...");
return;
}
String biomeName = data.getBiome().delegate.name().toString();
BiomesOPlenty.logger.info(String.format("Island biome %s weight set to %d for climate %s", biomeName, data.getWeight(), data.getClimate().name()));
BiomesOPlenty.logger.debug(String.format("Island biome %s weight set to %d for climate %s", biomeName, data.getWeight(), data.getClimate().name()));
ModBiomes.islandBiomeIds.add(Registry.BIOME.getId(data.getBiome()));
data.getClimate().addIslandBiome(data.getWeight(), data.getBiome());
}),
VANILLA_BIOME((SingleClimateRegistrationData data) -> {
if (data.getWeight() == 0)
{
BiomesOPlenty.logger.debug("Weights absent for vanilla biome" + data.getBiome().getName() + ", disabling...");
return;
}
data.getClimate().addBiome(data.getWeight(), data.getBiome());
});
public final Consumer<? extends RegistrationData> regFunc;
@ -446,12 +505,12 @@ public class BiomeRegistry
}
}
private static class IslandBiomeRegistrationData extends RegistrationData
private static class SingleClimateRegistrationData extends RegistrationData
{
private final BOPClimates climate;
private int weight;
public IslandBiomeRegistrationData(Biome biome, BOPClimates climate, int weight)
public SingleClimateRegistrationData(Biome biome, BOPClimates climate, int weight)
{
super(biome);
this.climate = climate;

View file

@ -158,6 +158,27 @@ public class ModBiomes
//BiomeRegistry.configureIslandBiomes();
BiomeRegistry.finalizeRegistrations(BiomeRegistry.RegistrationType.ISLAND_BIOME);
// Set up vanilla biomes
registerVanillaBiome(Biomes.SNOWY_TUNDRA, BOPClimates.ICE_CAP, 10);
registerVanillaBiome(Biomes.MOUNTAINS, BOPClimates.TUNDRA, 7);
registerVanillaBiome(Biomes.TAIGA, BOPClimates.WET_BOREAL, 10);
registerVanillaBiome(Biomes.GIANT_TREE_TAIGA, BOPClimates.DRY_BOREAL, 5);
registerVanillaBiome(Biomes.DARK_FOREST, BOPClimates.WET_TEMPERATE, 5);
registerVanillaBiome(Biomes.SWAMP, BOPClimates.WET_TEMPERATE, 7);
registerVanillaBiome(Biomes.BIRCH_FOREST, BOPClimates.DRY_TEMPERATE, 7);
registerVanillaBiome(Biomes.FOREST, BOPClimates.COOL_TEMPERATE, 10);
registerVanillaBiome(Biomes.PLAINS, BOPClimates.WARM_TEMPERATE, 10);
registerVanillaBiome(Biomes.JUNGLE, BOPClimates.TROPICAL, 15);
registerVanillaBiome(Biomes.SAVANNA, BOPClimates.SAVANNA, 10);
registerVanillaBiome(Biomes.DESERT, BOPClimates.HOT_DESERT, 15);
registerVanillaBiome(Biomes.BADLANDS_PLATEAU, BOPClimates.HOT_DESERT, 10);
registerVanillaBiome(Biomes.WOODED_BADLANDS_PLATEAU, BOPClimates.HOT_DESERT, 3);
registerVanillaBiome(Biomes.NETHER, BOPClimates.NETHER, 10);
BiomeRegistry.configureVanillaBiomes();
BiomeRegistry.finalizeRegistrations(BiomeRegistry.RegistrationType.VANILLA_BIOME);
registerBiomeDictionaryTags();
registerVillagerTypes();
}
@ -363,6 +384,11 @@ public class ModBiomes
registerIslandBiome(biome.get(), climate, weight);
}
private static void registerVanillaBiome(Biome biome, BOPClimates climate, int weight)
{
BiomeRegistry.deferVanillaBiomeRegistration(biome, climate, weight);
}
public static class WeightedSubBiome
{
public final Biome biome;