Implement system for sub biomes and mutated biomes
This commit is contained in:
parent
bd19fd2ae6
commit
44dd5dfa83
3 changed files with 130 additions and 125 deletions
|
@ -34,4 +34,8 @@ public class BOPBiomes
|
|||
public static Optional<BiomeGenBase> thicket = Optional.absent();
|
||||
public static Optional<BiomeGenBase> tundra = Optional.absent();
|
||||
public static Optional<BiomeGenBase> woodland = Optional.absent();
|
||||
|
||||
|
||||
// sub biomes
|
||||
public static Optional<BiomeGenBase> glacier = Optional.absent();
|
||||
}
|
||||
|
|
|
@ -11,8 +11,10 @@ package biomesoplenty.common.init;
|
|||
import static biomesoplenty.api.biome.BOPBiomes.*;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
|
@ -41,6 +43,8 @@ public class ModBiomes
|
|||
private static BOPConfig.IConfigObj biomeIdMapConf;
|
||||
private static Map<String, Integer> biomeIdMap;
|
||||
private static Set<Integer> idsReservedInConfig;
|
||||
public static Map<Integer, List<Integer>> subBiomesMap;
|
||||
public static Map<Integer, List<Integer>> mutatedBiomesMap;
|
||||
|
||||
public static void init()
|
||||
{
|
||||
|
@ -62,6 +66,9 @@ public class ModBiomes
|
|||
}
|
||||
}
|
||||
|
||||
initSubBiomes();
|
||||
initMutatedBiomes();
|
||||
|
||||
registerBiomes();
|
||||
|
||||
// save the biome ids to the config file (creating it if it doesn't exist)
|
||||
|
@ -69,6 +76,65 @@ public class ModBiomes
|
|||
|
||||
}
|
||||
|
||||
public static void initSubBiomes()
|
||||
{
|
||||
subBiomesMap = new HashMap<Integer, List<Integer>>();
|
||||
|
||||
// Add vanilla sub biomes
|
||||
|
||||
setSubBiome(BiomeGenBase.desert, BiomeGenBase.desertHills);
|
||||
setSubBiome(BiomeGenBase.forest, BiomeGenBase.forestHills);
|
||||
setSubBiome(BiomeGenBase.birchForest, BiomeGenBase.birchForestHills);
|
||||
setSubBiome(BiomeGenBase.roofedForest, BiomeGenBase.plains);
|
||||
setSubBiome(BiomeGenBase.taiga, BiomeGenBase.taigaHills);
|
||||
setSubBiome(BiomeGenBase.megaTaiga, BiomeGenBase.megaTaigaHills);
|
||||
setSubBiome(BiomeGenBase.coldTaiga, BiomeGenBase.coldTaigaHills);
|
||||
setSubBiome(BiomeGenBase.plains, BiomeGenBase.forestHills, BiomeGenBase.forest);
|
||||
setSubBiome(BiomeGenBase.icePlains, BiomeGenBase.iceMountains);
|
||||
setSubBiome(BiomeGenBase.jungle, BiomeGenBase.jungleHills);
|
||||
setSubBiome(BiomeGenBase.ocean, BiomeGenBase.deepOcean);
|
||||
setSubBiome(BiomeGenBase.extremeHills, BiomeGenBase.extremeHillsPlus);
|
||||
setSubBiome(BiomeGenBase.savanna, BiomeGenBase.savannaPlateau);
|
||||
setSubBiome(BiomeGenBase.mesaPlateau_F, BiomeGenBase.mesa);
|
||||
setSubBiome(BiomeGenBase.deepOcean, BiomeGenBase.deepOcean, BiomeGenBase.deepOcean, BiomeGenBase.plains, BiomeGenBase.forest); // occasional islands within the oceans
|
||||
|
||||
}
|
||||
|
||||
public static void initMutatedBiomes()
|
||||
{
|
||||
mutatedBiomesMap = new HashMap<Integer, List<Integer>>();
|
||||
|
||||
// Add vanilla mutated biomes
|
||||
|
||||
// the mutated versions of vanilla biomes aren't actually saved to static variables in BiomeGenBase
|
||||
// instead, they just manually create mutated versions of many of their biomes via a hard coded list in BiomeGenBase
|
||||
// and by default assume a biome id which is the old one + 128
|
||||
// this severely limits the number of new biomes we can add (we'd have to keep the number below 128 to avoid clashes)
|
||||
// we hard code the list of vanilla biomes with mutated versions below, which enables other biomes to use the biome ids which are not taken
|
||||
|
||||
setSubBiome(BiomeGenBase.plains, BiomeGenBase.getBiome(BiomeGenBase.plains.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.desert, BiomeGenBase.getBiome(BiomeGenBase.desert.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.forest, BiomeGenBase.getBiome(BiomeGenBase.forest.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.taiga, BiomeGenBase.getBiome(BiomeGenBase.taiga.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.swampland, BiomeGenBase.getBiome(BiomeGenBase.swampland.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.icePlains, BiomeGenBase.getBiome(BiomeGenBase.icePlains.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.jungle, BiomeGenBase.getBiome(BiomeGenBase.jungle.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.jungleEdge, BiomeGenBase.getBiome(BiomeGenBase.jungleEdge.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.coldTaiga, BiomeGenBase.getBiome(BiomeGenBase.coldTaiga.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.savanna, BiomeGenBase.getBiome(BiomeGenBase.savanna.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.savannaPlateau, BiomeGenBase.getBiome(BiomeGenBase.savannaPlateau.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.mesa, BiomeGenBase.getBiome(BiomeGenBase.mesa.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.mesaPlateau, BiomeGenBase.getBiome(BiomeGenBase.mesaPlateau.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.mesaPlateau_F, BiomeGenBase.getBiome(BiomeGenBase.mesaPlateau_F.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.birchForest, BiomeGenBase.getBiome(BiomeGenBase.birchForest.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.birchForestHills, BiomeGenBase.getBiome(BiomeGenBase.birchForestHills.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.roofedForest, BiomeGenBase.getBiome(BiomeGenBase.roofedForest.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.megaTaiga, BiomeGenBase.getBiome(BiomeGenBase.megaTaiga.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.extremeHills, BiomeGenBase.getBiome(BiomeGenBase.extremeHills.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.extremeHillsPlus, BiomeGenBase.getBiome(BiomeGenBase.extremeHillsPlus.biomeID + 128));
|
||||
setSubBiome(BiomeGenBase.megaTaigaHills, BiomeGenBase.getBiome(BiomeGenBase.megaTaigaHills.biomeID + 128));
|
||||
}
|
||||
|
||||
|
||||
private static void registerBiomes()
|
||||
{
|
||||
|
@ -91,7 +157,54 @@ public class ModBiomes
|
|||
steppe = registerBOPBiome(new BiomeGenSteppe(), "Steppe");
|
||||
thicket = registerBOPBiome(new BiomeGenThicket(), "Thicket");
|
||||
tundra = registerBOPBiome(new BiomeGenTundra(), "Tundra");
|
||||
woodland = registerBOPBiome(new BiomeGenWoodland(), "Woodland");
|
||||
woodland = registerBOPBiome(new BiomeGenWoodland(), "Woodland");
|
||||
|
||||
// sub biomes
|
||||
|
||||
glacier = registerBOPBiome(new BiomeGenCrag(), "Glacier"); // TODO: implement glacier
|
||||
|
||||
setSubBiome(Optional.of(BiomeGenBase.frozenOcean), arctic); // add some arctic regions in frozen oceans
|
||||
setSubBiome(arctic, glacier);
|
||||
|
||||
}
|
||||
|
||||
|
||||
private static void setSubBiome(Optional<BiomeGenBase> parent, Optional<BiomeGenBase>... subBiomes)
|
||||
{
|
||||
setSubBiome(parent, false, subBiomes);
|
||||
}
|
||||
|
||||
private static void setSubBiome(Optional<BiomeGenBase> parent, boolean mutated, Optional<BiomeGenBase>... subBiomes)
|
||||
{
|
||||
if (parent.isPresent())
|
||||
{
|
||||
for (Optional<BiomeGenBase> subBiome : subBiomes)
|
||||
{
|
||||
if (subBiome.isPresent())
|
||||
{
|
||||
setSubBiome(parent.get(), mutated, subBiome.get());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void setSubBiome(BiomeGenBase parent, BiomeGenBase... subBiomes)
|
||||
{
|
||||
setSubBiome(parent, false, subBiomes);
|
||||
}
|
||||
|
||||
private static void setSubBiome(BiomeGenBase parent, boolean mutated, BiomeGenBase... subBiomes)
|
||||
{
|
||||
Map<Integer, List<Integer>> map = mutated ? mutatedBiomesMap : subBiomesMap;
|
||||
int parentId = parent.biomeID;
|
||||
if (!map.containsKey(parentId))
|
||||
{
|
||||
map.put(parentId, new ArrayList<Integer>());
|
||||
}
|
||||
for (BiomeGenBase subBiome : subBiomes)
|
||||
{
|
||||
map.get(parentId).add(subBiome.biomeID);
|
||||
}
|
||||
}
|
||||
|
||||
private static Optional<BiomeGenBase> registerBOPBiome(BOPBiome biome, String name)
|
||||
|
|
|
@ -8,8 +8,9 @@
|
|||
|
||||
package biomesoplenty.common.world.layer;
|
||||
|
||||
import biomesoplenty.api.biome.BOPBiomes;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import java.util.List;
|
||||
|
||||
import biomesoplenty.common.init.ModBiomes;
|
||||
import net.minecraft.world.gen.layer.GenLayer;
|
||||
import net.minecraft.world.gen.layer.IntCache;
|
||||
|
||||
|
@ -110,136 +111,23 @@ public class GenLayerSubBiomesBOP extends GenLayer
|
|||
public int getRareSubBiome(int biomeId)
|
||||
{
|
||||
|
||||
// the mutated versions of vanilla biomes aren't actually saved to static variables in BiomeGenBase
|
||||
// instead, they just manually create mutated versions of many of their biomes via a hard coded list in BiomeGenBase
|
||||
// and by default assume a biome id which is the old one + 128
|
||||
// this severely limits the number of new biomes we can add (we'd have to keep the number below 128 to avoid clashes)
|
||||
// we hard code the list of vanilla biomes with mutated versions below, which enables other biomes to use the biome ids which are not taken
|
||||
|
||||
if (
|
||||
biomeId == BiomeGenBase.plains.biomeID ||
|
||||
biomeId == BiomeGenBase.desert.biomeID ||
|
||||
biomeId == BiomeGenBase.forest.biomeID ||
|
||||
biomeId == BiomeGenBase.taiga.biomeID ||
|
||||
biomeId == BiomeGenBase.swampland.biomeID ||
|
||||
biomeId == BiomeGenBase.icePlains.biomeID ||
|
||||
biomeId == BiomeGenBase.jungle.biomeID ||
|
||||
biomeId == BiomeGenBase.jungleEdge.biomeID ||
|
||||
biomeId == BiomeGenBase.coldTaiga.biomeID ||
|
||||
biomeId == BiomeGenBase.savanna.biomeID ||
|
||||
biomeId == BiomeGenBase.savannaPlateau.biomeID ||
|
||||
biomeId == BiomeGenBase.mesa.biomeID ||
|
||||
biomeId == BiomeGenBase.mesaPlateau.biomeID ||
|
||||
biomeId == BiomeGenBase.mesaPlateau_F.biomeID ||
|
||||
biomeId == BiomeGenBase.birchForest.biomeID ||
|
||||
biomeId == BiomeGenBase.birchForestHills.biomeID ||
|
||||
biomeId == BiomeGenBase.roofedForest.biomeID ||
|
||||
biomeId == BiomeGenBase.megaTaiga.biomeID ||
|
||||
biomeId == BiomeGenBase.extremeHills.biomeID ||
|
||||
biomeId == BiomeGenBase.extremeHillsPlus.biomeID ||
|
||||
biomeId == BiomeGenBase.megaTaigaHills.biomeID
|
||||
)
|
||||
{
|
||||
if (BiomeGenBase.getBiome(biomeId + 128) != null)
|
||||
{
|
||||
return biomeId + 128;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: add BOP rare sub biomes here
|
||||
|
||||
return biomeId;
|
||||
List<Integer> subBiomeIds = ModBiomes.mutatedBiomesMap.get(biomeId);
|
||||
if (subBiomeIds == null) {return biomeId;}
|
||||
int n = subBiomeIds.size();
|
||||
return (n == 0 ? biomeId : (n == 1 ? subBiomeIds.get(0).intValue() : subBiomeIds.get(this.nextInt(n)).intValue()));
|
||||
|
||||
}
|
||||
|
||||
// Given a biomeId, return the biomeId of a reasonably common alternative biome which you might expect to find a patch of within the outer biome
|
||||
// For many biomes, this is the 'hills' version
|
||||
public int getCommonSubBiome(int biomeId)
|
||||
{
|
||||
if (biomeId == BiomeGenBase.desert.biomeID)
|
||||
{
|
||||
return BiomeGenBase.desertHills.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.forest.biomeID)
|
||||
{
|
||||
return BiomeGenBase.forestHills.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.birchForest.biomeID)
|
||||
{
|
||||
return BiomeGenBase.birchForestHills.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.roofedForest.biomeID)
|
||||
{
|
||||
return BiomeGenBase.plains.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.taiga.biomeID)
|
||||
{
|
||||
return BiomeGenBase.taigaHills.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.megaTaiga.biomeID)
|
||||
{
|
||||
return BiomeGenBase.megaTaigaHills.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.coldTaiga.biomeID)
|
||||
{
|
||||
return BiomeGenBase.coldTaigaHills.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.plains.biomeID)
|
||||
{
|
||||
if (this.nextInt(3) == 0)
|
||||
{
|
||||
return BiomeGenBase.forestHills.biomeID;
|
||||
}
|
||||
else
|
||||
{
|
||||
return BiomeGenBase.forest.biomeID;
|
||||
}
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.icePlains.biomeID)
|
||||
{
|
||||
return BiomeGenBase.iceMountains.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.jungle.biomeID)
|
||||
{
|
||||
return BiomeGenBase.jungleHills.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.ocean.biomeID)
|
||||
{
|
||||
return BiomeGenBase.deepOcean.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.extremeHills.biomeID)
|
||||
{
|
||||
return BiomeGenBase.extremeHillsPlus.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.savanna.biomeID)
|
||||
{
|
||||
return BiomeGenBase.savannaPlateau.biomeID;
|
||||
}
|
||||
else if (biomesEqualOrMesaPlateau(biomeId, BiomeGenBase.mesaPlateau_F.biomeID))
|
||||
{
|
||||
return BiomeGenBase.mesa.biomeID;
|
||||
}
|
||||
else if (biomeId == BiomeGenBase.deepOcean.biomeID && this.nextInt(3) == 0)
|
||||
{
|
||||
// occasional islands within the oceans
|
||||
if (this.nextInt(2) == 0)
|
||||
{
|
||||
return BiomeGenBase.plains.biomeID;
|
||||
}
|
||||
else
|
||||
{
|
||||
return BiomeGenBase.forest.biomeID;
|
||||
}
|
||||
}
|
||||
|
||||
// BOP sub biomes from here on
|
||||
List<Integer> subBiomeIds = ModBiomes.subBiomesMap.get(biomeId);
|
||||
if (subBiomeIds == null) {return biomeId;}
|
||||
int n = subBiomeIds.size();
|
||||
return (n == 0 ? biomeId : (n == 1 ? subBiomeIds.get(0).intValue() : subBiomeIds.get(this.nextInt(n)).intValue()));
|
||||
|
||||
if (biomeId == BiomeGenBase.frozenOcean.biomeID && BOPBiomes.arctic.isPresent())
|
||||
{
|
||||
biomeId = BOPBiomes.arctic.get().biomeID;
|
||||
}
|
||||
|
||||
|
||||
return biomeId;
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue