Allow configuration of vanilla biome weights
This commit is contained in:
parent
f003accc02
commit
e07420ae52
5 changed files with 91 additions and 75 deletions
|
@ -74,7 +74,7 @@ public class BOPBiome extends BiomeGenBase implements IExtendedBiome
|
||||||
{
|
{
|
||||||
Integer weight = confWeights.getInt(type.name().toLowerCase(), null);
|
Integer weight = confWeights.getInt(type.name().toLowerCase(), null);
|
||||||
if (weight == null) {continue;}
|
if (weight == null) {continue;}
|
||||||
if (weight.intValue() == 0)
|
if (weight.intValue() < 1)
|
||||||
{
|
{
|
||||||
this.weightMap.remove(type);
|
this.weightMap.remove(type);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,6 +40,6 @@ public class BOPBiomeManager
|
||||||
int idx = type.ordinal();
|
int idx = type.ordinal();
|
||||||
List<BiomeEntry> list = idx > biomes.length ? null : biomes[idx];
|
List<BiomeEntry> list = idx > biomes.length ? null : biomes[idx];
|
||||||
|
|
||||||
return list != null ? ImmutableList.copyOf(list) : null;
|
return list == null ? ImmutableList.<BiomeEntry>of() : ImmutableList.copyOf(list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,6 +32,7 @@ import biomesoplenty.common.biome.overworld.BiomeGenShrubland;
|
||||||
import biomesoplenty.common.biome.overworld.BiomeGenSteppe;
|
import biomesoplenty.common.biome.overworld.BiomeGenSteppe;
|
||||||
import biomesoplenty.common.biome.overworld.BiomeGenThicket;
|
import biomesoplenty.common.biome.overworld.BiomeGenThicket;
|
||||||
import biomesoplenty.common.command.BOPCommand;
|
import biomesoplenty.common.command.BOPCommand;
|
||||||
|
import biomesoplenty.common.util.biome.BiomeUtils;
|
||||||
import biomesoplenty.common.util.config.BOPConfig;
|
import biomesoplenty.common.util.config.BOPConfig;
|
||||||
import biomesoplenty.common.world.WorldTypeBOP;
|
import biomesoplenty.common.world.WorldTypeBOP;
|
||||||
import biomesoplenty.core.BiomesOPlenty;
|
import biomesoplenty.core.BiomesOPlenty;
|
||||||
|
@ -57,7 +58,6 @@ public class ModBiomes
|
||||||
biomeIdMap = new HashMap<String, Integer>();
|
biomeIdMap = new HashMap<String, Integer>();
|
||||||
|
|
||||||
registerBiomes();
|
registerBiomes();
|
||||||
registerExternalBiomes();
|
|
||||||
|
|
||||||
// save the biome ids to the config file (creating it if it doesn't exist)
|
// save the biome ids to the config file (creating it if it doesn't exist)
|
||||||
BOPConfig.writeFile(biomeIdMapFile, biomeIdMap);
|
BOPConfig.writeFile(biomeIdMapFile, biomeIdMap);
|
||||||
|
@ -67,21 +67,24 @@ public class ModBiomes
|
||||||
|
|
||||||
private static void registerBiomes()
|
private static void registerBiomes()
|
||||||
{
|
{
|
||||||
alps = registerBOPBiome(new BiomeGenAlps(), "Alps", "alps");
|
alps = registerBOPBiome(new BiomeGenAlps(), "Alps");
|
||||||
arctic = registerBOPBiome(new BiomeGenArctic(), "Arctic", "arctic");
|
arctic = registerBOPBiome(new BiomeGenArctic(), "Arctic");
|
||||||
crag = registerBOPBiome(new BiomeGenCrag(), "Crag", "crag");
|
crag = registerBOPBiome(new BiomeGenCrag(), "Crag");
|
||||||
denseForest = registerBOPBiome(new BiomeGenDenseForest(), "Dense Forest", "dense_forest");
|
denseForest = registerBOPBiome(new BiomeGenDenseForest(), "Dense Forest");
|
||||||
flowerField = registerBOPBiome(new BiomeGenFlowerField(), "Flower Field", "flower_field");
|
flowerField = registerBOPBiome(new BiomeGenFlowerField(), "Flower Field");
|
||||||
lavenderFields = registerBOPBiome(new BiomeGenLavenderFields(), "Lavender Fields", "lavender_fields");
|
lavenderFields = registerBOPBiome(new BiomeGenLavenderFields(), "Lavender Fields");
|
||||||
originValley = registerBOPBiome(new BiomeGenOriginValley(), "Origin Valley", "origin_valley");
|
originValley = registerBOPBiome(new BiomeGenOriginValley(), "Origin Valley");
|
||||||
shrubland = registerBOPBiome(new BiomeGenShrubland(), "Shrubland", "shrubland");
|
shrubland = registerBOPBiome(new BiomeGenShrubland(), "Shrubland");
|
||||||
steppe = registerBOPBiome(new BiomeGenSteppe(), "Steppe", "steppe");
|
steppe = registerBOPBiome(new BiomeGenSteppe(), "Steppe");
|
||||||
thicket = registerBOPBiome(new BiomeGenThicket(), "Thicket", "thicket");
|
thicket = registerBOPBiome(new BiomeGenThicket(), "Thicket");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<BiomeGenBase> registerBOPBiome(BOPBiome biome, String name, String idName)
|
private static Optional<BiomeGenBase> registerBOPBiome(BOPBiome biome, String name)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
biome.setBiomeName(name);
|
||||||
|
String idName = BiomeUtils.getBiomeIdentifier(biome);
|
||||||
|
|
||||||
Integer id = biomeIdMapConf.getInt(idName, null);
|
Integer id = biomeIdMapConf.getInt(idName, null);
|
||||||
if (id == null) {id = new Integer(getNextFreeBiomeId());}
|
if (id == null) {id = new Integer(getNextFreeBiomeId());}
|
||||||
biomeIdMap.put(idName, id);
|
biomeIdMap.put(idName, id);
|
||||||
|
@ -93,7 +96,6 @@ public class ModBiomes
|
||||||
|
|
||||||
BOPCommand.biomeCount++;
|
BOPCommand.biomeCount++;
|
||||||
biome.biomeID = id;
|
biome.biomeID = id;
|
||||||
biome.setBiomeName(name);
|
|
||||||
// If there was a valid config file, then use it to configure the biome
|
// If there was a valid config file, then use it to configure the biome
|
||||||
if (!conf.isEmpty()) {biome.configure(conf);}
|
if (!conf.isEmpty()) {biome.configure(conf);}
|
||||||
// log any warnings from parsing the config file
|
// log any warnings from parsing the config file
|
||||||
|
@ -118,58 +120,6 @@ public class ModBiomes
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private static void registerExternalBiomes()
|
|
||||||
{
|
|
||||||
/*registerExternalBiome(BiomeGenBase.ocean, "ocean");
|
|
||||||
registerExternalBiome(BiomeGenBase.plains, "plains");
|
|
||||||
registerExternalBiome(BiomeGenBase.desert, "desert");
|
|
||||||
registerExternalBiome(BiomeGenBase.extremeHills, "extreme_hills");
|
|
||||||
registerExternalBiome(BiomeGenBase.forest, "forest");
|
|
||||||
registerExternalBiome(BiomeGenBase.taiga, "taiga");
|
|
||||||
registerExternalBiome(BiomeGenBase.swampland, "swampland");
|
|
||||||
registerExternalBiome(BiomeGenBase.river, "river");
|
|
||||||
registerExternalBiome(BiomeGenBase.hell, "hell");
|
|
||||||
registerExternalBiome(BiomeGenBase.sky, "sky");
|
|
||||||
registerExternalBiome(BiomeGenBase.frozenOcean, "frozen_ocean");
|
|
||||||
registerExternalBiome(BiomeGenBase.frozenRiver, "frozen_river");
|
|
||||||
registerExternalBiome(BiomeGenBase.icePlains, "ice_plains");
|
|
||||||
registerExternalBiome(BiomeGenBase.iceMountains, "ice_mountains");
|
|
||||||
registerExternalBiome(BiomeGenBase.mushroomIsland, "mushroom_island");
|
|
||||||
registerExternalBiome(BiomeGenBase.mushroomIslandShore, "mushroom_island_shore");
|
|
||||||
registerExternalBiome(BiomeGenBase.beach, "beach");
|
|
||||||
registerExternalBiome(BiomeGenBase.desertHills, "beach_hills");
|
|
||||||
registerExternalBiome(BiomeGenBase.forestHills, "forest_hills");
|
|
||||||
registerExternalBiome(BiomeGenBase.taigaHills, "taiga_hills");
|
|
||||||
registerExternalBiome(BiomeGenBase.extremeHillsEdge, "extreme_hills_edge");
|
|
||||||
registerExternalBiome(BiomeGenBase.jungle, "jungle");
|
|
||||||
registerExternalBiome(BiomeGenBase.jungleHills, "jungle_hills");
|
|
||||||
registerExternalBiome(BiomeGenBase.jungleEdge, "jungle_edge");
|
|
||||||
registerExternalBiome(BiomeGenBase.deepOcean, "deep_ocean");
|
|
||||||
registerExternalBiome(BiomeGenBase.stoneBeach, "stone_beach");
|
|
||||||
registerExternalBiome(BiomeGenBase.coldBeach, "cold_beach");
|
|
||||||
registerExternalBiome(BiomeGenBase.birchForest, "birch_forest");
|
|
||||||
registerExternalBiome(BiomeGenBase.birchForestHills, "birch_forest_hills");
|
|
||||||
registerExternalBiome(BiomeGenBase.roofedForest, "roofed_forest");
|
|
||||||
registerExternalBiome(BiomeGenBase.coldTaiga, "cold_taiga");
|
|
||||||
registerExternalBiome(BiomeGenBase.coldTaigaHills, "cold_taiga_hills");
|
|
||||||
registerExternalBiome(BiomeGenBase.megaTaiga, "mega_taiga");
|
|
||||||
registerExternalBiome(BiomeGenBase.megaTaigaHills, "mega_taiga_hills");
|
|
||||||
registerExternalBiome(BiomeGenBase.extremeHillsPlus, "extreme_hills_plus");
|
|
||||||
registerExternalBiome(BiomeGenBase.savanna, "savanna");
|
|
||||||
registerExternalBiome(BiomeGenBase.savannaPlateau, "savanna_plateau");
|
|
||||||
registerExternalBiome(BiomeGenBase.mesa, "mesa");
|
|
||||||
registerExternalBiome(BiomeGenBase.mesaPlateau_F, "mesa_plateau_f");
|
|
||||||
registerExternalBiome(BiomeGenBase.mesaPlateau, "mesa_plateau");*/
|
|
||||||
}
|
|
||||||
|
|
||||||
/*private static void registerExternalBiome(BiomeGenBase biome, String id)
|
|
||||||
{
|
|
||||||
ExtendedBiomeRegistry.createExtension(biome);
|
|
||||||
BiomeConfigurationHandler.translateVanillaValues(biome);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public static int getNextFreeBiomeId()
|
public static int getNextFreeBiomeId()
|
||||||
{
|
{
|
||||||
for (int i = nextBiomeId; i < 256; i++)
|
for (int i = nextBiomeId; i < 256; i++)
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
|
|
||||||
package biomesoplenty.common.util.biome;
|
package biomesoplenty.common.util.biome;
|
||||||
|
|
||||||
|
import com.google.common.base.CaseFormat;
|
||||||
|
|
||||||
import net.minecraft.util.BlockPos;
|
import net.minecraft.util.BlockPos;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
import net.minecraft.world.biome.BiomeGenBase;
|
import net.minecraft.world.biome.BiomeGenBase;
|
||||||
|
@ -16,6 +18,14 @@ import net.minecraft.world.biome.WorldChunkManager;
|
||||||
public class BiomeUtils
|
public class BiomeUtils
|
||||||
{
|
{
|
||||||
|
|
||||||
|
public static String getBiomeIdentifier(BiomeGenBase biome)
|
||||||
|
{
|
||||||
|
// Vanilla Biomes are typically named in upper camel case, sometimes with spaces
|
||||||
|
// We follow the same convention with BOP Biomes
|
||||||
|
// return a standardised identifier for use in json files, etc by converting to lowercase with underscores
|
||||||
|
return CaseFormat.UPPER_CAMEL.to(CaseFormat.LOWER_UNDERSCORE, biome.biomeName.replace(" ", ""));
|
||||||
|
}
|
||||||
|
|
||||||
public static BlockPos spiralOutwardsLookingForBiome(World world, BiomeGenBase biomeToFind, double startX, double startZ, int maxDist)
|
public static BlockPos spiralOutwardsLookingForBiome(World world, BiomeGenBase biomeToFind, double startX, double startZ, int maxDist)
|
||||||
{
|
{
|
||||||
// TODO: make default sample spacing dependent on size of biomes
|
// TODO: make default sample spacing dependent on size of biomes
|
||||||
|
|
|
@ -13,8 +13,12 @@ import static net.minecraftforge.common.BiomeManager.BiomeType.DESERT;
|
||||||
import static net.minecraftforge.common.BiomeManager.BiomeType.ICY;
|
import static net.minecraftforge.common.BiomeManager.BiomeType.ICY;
|
||||||
import static net.minecraftforge.common.BiomeManager.BiomeType.WARM;
|
import static net.minecraftforge.common.BiomeManager.BiomeType.WARM;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
import net.minecraft.util.WeightedRandom;
|
import net.minecraft.util.WeightedRandom;
|
||||||
import net.minecraft.world.WorldType;
|
import net.minecraft.world.WorldType;
|
||||||
|
@ -24,10 +28,13 @@ import net.minecraft.world.gen.layer.GenLayerBiome;
|
||||||
import net.minecraft.world.gen.layer.IntCache;
|
import net.minecraft.world.gen.layer.IntCache;
|
||||||
import net.minecraftforge.common.BiomeManager;
|
import net.minecraftforge.common.BiomeManager;
|
||||||
import net.minecraftforge.common.BiomeManager.BiomeEntry;
|
import net.minecraftforge.common.BiomeManager.BiomeEntry;
|
||||||
|
import net.minecraftforge.common.BiomeManager.BiomeType;
|
||||||
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
import net.minecraftforge.fml.relauncher.ReflectionHelper;
|
||||||
import biomesoplenty.common.biome.BOPBiomeManager;
|
import biomesoplenty.common.biome.BOPBiomeManager;
|
||||||
|
import biomesoplenty.common.util.biome.BiomeUtils;
|
||||||
import com.google.common.collect.ImmutableList;
|
import biomesoplenty.common.util.config.BOPConfig.ConfigFileObj;
|
||||||
|
import biomesoplenty.common.util.config.BOPConfig.IConfigObj;
|
||||||
|
import biomesoplenty.core.BiomesOPlenty;
|
||||||
|
|
||||||
public class GenLayerBiomeBOP extends GenLayerBiome
|
public class GenLayerBiomeBOP extends GenLayerBiome
|
||||||
{
|
{
|
||||||
|
@ -37,19 +44,68 @@ public class GenLayerBiomeBOP extends GenLayerBiome
|
||||||
{
|
{
|
||||||
super(seed, parentLayer, worldType, chunkProviderSettings);
|
super(seed, parentLayer, worldType, chunkProviderSettings);
|
||||||
|
|
||||||
|
// get the vanilla biomes (and their hard-coded default weights) from the vanilla GenLayerBiome class private field 'biomes'
|
||||||
biomes = ReflectionHelper.getPrivateValue(GenLayerBiome.class, this, "biomes");
|
biomes = ReflectionHelper.getPrivateValue(GenLayerBiome.class, this, "biomes");
|
||||||
|
|
||||||
//TODO: Use vanilla biome weights
|
// get a set of all of the vanilla biomes which appear at all anywhere in the weights
|
||||||
|
Set<BiomeGenBase> vanillaBiomes = new HashSet<BiomeGenBase>();
|
||||||
|
for (BiomeManager.BiomeType type : BiomeManager.BiomeType.values()) {
|
||||||
|
if (biomes[type.ordinal()] == null) {biomes[type.ordinal()] = new ArrayList<BiomeEntry>();}
|
||||||
|
for (BiomeEntry entry : biomes[type.ordinal()]) {vanillaBiomes.add(entry.biome);}
|
||||||
|
}
|
||||||
|
|
||||||
|
// for each of the vanilla biomes, allow the default weights to be overriden by config files
|
||||||
|
for (BiomeGenBase vanillaBiome : vanillaBiomes)
|
||||||
|
{
|
||||||
|
// See if there's a config file containing a setting called "weights"
|
||||||
|
String idName = BiomeUtils.getBiomeIdentifier(vanillaBiome);
|
||||||
|
File configFile = new File(new File(BiomesOPlenty.configDirectory, "biomes"), idName + ".json");
|
||||||
|
IConfigObj conf = new ConfigFileObj(configFile);
|
||||||
|
IConfigObj confWeights = conf.getObject("weights");
|
||||||
|
|
||||||
|
// Allow weights to be overridden by values in the config file
|
||||||
|
if (confWeights != null)
|
||||||
|
{
|
||||||
|
for (BiomeType type : BiomeType.values())
|
||||||
|
{
|
||||||
|
Iterator<BiomeEntry> entries = biomes[type.ordinal()].iterator();
|
||||||
|
Integer weight = confWeights.getInt(type.name().toLowerCase(), null);
|
||||||
|
if (weight == null) {continue;}
|
||||||
|
boolean foundIt = false;
|
||||||
|
while (entries.hasNext())
|
||||||
|
{
|
||||||
|
BiomeEntry entry = entries.next();
|
||||||
|
if (entry.biome == vanillaBiome)
|
||||||
|
{
|
||||||
|
if (weight.intValue() < 1)
|
||||||
|
{
|
||||||
|
entries.remove();
|
||||||
|
} else {
|
||||||
|
entry.itemWeight = weight.intValue();
|
||||||
|
}
|
||||||
|
foundIt = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!foundIt)
|
||||||
|
{
|
||||||
|
biomes[type.ordinal()].add(new BiomeEntry(vanillaBiome, weight));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// For each biome type, add the BOP biomes (weights already configured when they were created)
|
||||||
for (BiomeManager.BiomeType type : BiomeManager.BiomeType.values())
|
for (BiomeManager.BiomeType type : BiomeManager.BiomeType.values())
|
||||||
{
|
{
|
||||||
ImmutableList<BiomeEntry> biomesToAdd = BOPBiomeManager.getBiomes(type);
|
biomes[type.ordinal()].addAll(BOPBiomeManager.getBiomes(type));
|
||||||
int idx = type.ordinal();
|
}
|
||||||
|
|
||||||
if (biomes[idx] == null) biomes[idx] = new ArrayList<BiomeEntry>();
|
// debugging:
|
||||||
if (biomesToAdd != null) biomes[idx].addAll(biomesToAdd);
|
// for (BiomeManager.BiomeType type : BiomeManager.BiomeType.values()) {for (BiomeEntry entry : biomes[type.ordinal()]) {System.out.println(type.name() + " " + BiomeUtils.getBiomeIdentifier(entry.biome) + " " + entry.itemWeight);}}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Get array of biome IDs covering the requested area
|
// Get array of biome IDs covering the requested area
|
||||||
@Override
|
@Override
|
||||||
public int[] getInts(int areaX, int areaY, int areaWidth, int areaHeight)
|
public int[] getInts(int areaX, int areaY, int areaWidth, int areaHeight)
|
||||||
|
|
Loading…
Reference in a new issue