2012-10-28 14:38:38 +00:00
|
|
|
package net.minecraftforge.common;
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2014-08-26 08:02:09 +00:00
|
|
|
import java.util.Arrays;
|
2014-04-11 01:01:28 +00:00
|
|
|
import java.util.Collection;
|
|
|
|
import java.util.Iterator;
|
|
|
|
import java.util.List;
|
2012-10-28 14:38:38 +00:00
|
|
|
|
2014-08-26 08:02:09 +00:00
|
|
|
import com.google.common.collect.ImmutableList;
|
|
|
|
|
2014-04-11 01:01:28 +00:00
|
|
|
import net.minecraft.util.WeightedRandom;
|
|
|
|
import net.minecraft.world.WorldType;
|
2012-12-13 05:58:35 +00:00
|
|
|
import net.minecraft.world.biome.BiomeGenBase;
|
|
|
|
import net.minecraft.world.gen.structure.MapGenVillage;
|
|
|
|
import net.minecraft.world.biome.WorldChunkManager;
|
2014-08-26 08:02:09 +00:00
|
|
|
import net.minecraftforge.common.BiomeDictionary.Type;
|
|
|
|
import net.minecraftforge.common.util.EnumHelper;
|
2012-10-28 14:38:38 +00:00
|
|
|
|
|
|
|
public class BiomeManager
|
|
|
|
{
|
2014-08-26 08:02:09 +00:00
|
|
|
private static TrackedList<BiomeEntry>[] biomes = setupBiomes();
|
|
|
|
|
|
|
|
/*
|
|
|
|
* These lists should no longer be accessed directly. Instead, use the appropriate add, remove and get methods within this class.
|
|
|
|
*/
|
|
|
|
@Deprecated
|
|
|
|
public static List<BiomeEntry> desertBiomes = biomes[BiomeType.DESERT.ordinal()];
|
|
|
|
@Deprecated
|
|
|
|
public static List<BiomeEntry> warmBiomes = biomes[BiomeType.WARM.ordinal()];
|
|
|
|
@Deprecated
|
|
|
|
public static List<BiomeEntry> coolBiomes = biomes[BiomeType.COOL.ordinal()];
|
|
|
|
@Deprecated
|
|
|
|
public static List<BiomeEntry> icyBiomes = biomes[BiomeType.ICY.ordinal()];
|
|
|
|
|
|
|
|
private static boolean isModded = false;
|
2014-04-11 01:01:28 +00:00
|
|
|
|
|
|
|
public static List<BiomeGenBase> oceanBiomes = new ArrayList<BiomeGenBase>();
|
|
|
|
|
2013-12-22 23:47:51 +00:00
|
|
|
public static ArrayList<BiomeGenBase> strongHoldBiomes = new ArrayList<BiomeGenBase>();
|
|
|
|
public static ArrayList<BiomeGenBase> strongHoldBiomesBlackList = new ArrayList<BiomeGenBase>();
|
|
|
|
|
2014-04-11 01:01:28 +00:00
|
|
|
static
|
|
|
|
{
|
|
|
|
oceanBiomes.add(BiomeGenBase.ocean);
|
|
|
|
oceanBiomes.add(BiomeGenBase.deepOcean);
|
|
|
|
oceanBiomes.add(BiomeGenBase.frozenOcean);
|
|
|
|
}
|
2014-08-26 08:02:09 +00:00
|
|
|
|
|
|
|
private static TrackedList<BiomeEntry>[] setupBiomes()
|
|
|
|
{
|
|
|
|
TrackedList<BiomeEntry>[] currentBiomes = new TrackedList[BiomeType.values().length];
|
|
|
|
List list = new ArrayList();
|
|
|
|
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.forest, 10));
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.roofedForest, 10));
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.extremeHills, 10));
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.plains, 10));
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.birchForest, 10));
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.swampland, 10));
|
|
|
|
|
|
|
|
currentBiomes[BiomeType.WARM.ordinal()] = new TrackedList(list);
|
|
|
|
list.clear();
|
|
|
|
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.forest, 10));
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.extremeHills, 10));
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.taiga, 10));
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.plains, 10));
|
|
|
|
|
|
|
|
currentBiomes[BiomeType.COOL.ordinal()] = new TrackedList(list);
|
|
|
|
list.clear();
|
|
|
|
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.icePlains, 30));
|
|
|
|
list.add(new BiomeEntry(BiomeGenBase.coldTaiga, 10));
|
|
|
|
|
|
|
|
currentBiomes[BiomeType.ICY.ordinal()] = new TrackedList(list);
|
|
|
|
list.clear();
|
|
|
|
|
2014-10-10 10:22:47 +00:00
|
|
|
currentBiomes[BiomeType.DESERT.ordinal()] = new TrackedList(list);
|
|
|
|
|
2014-08-26 08:02:09 +00:00
|
|
|
return currentBiomes;
|
|
|
|
}
|
2014-04-11 01:01:28 +00:00
|
|
|
|
2014-01-18 05:55:48 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2012-10-28 14:38:38 +00:00
|
|
|
public static void addVillageBiome(BiomeGenBase biome, boolean canSpawn)
|
|
|
|
{
|
|
|
|
if (!MapGenVillage.villageSpawnBiomes.contains(biome))
|
|
|
|
{
|
|
|
|
ArrayList<BiomeGenBase> biomes = new ArrayList<BiomeGenBase>(MapGenVillage.villageSpawnBiomes);
|
|
|
|
biomes.add(biome);
|
|
|
|
MapGenVillage.villageSpawnBiomes = biomes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-01-18 05:55:48 +00:00
|
|
|
@SuppressWarnings("unchecked")
|
2012-10-28 14:38:38 +00:00
|
|
|
public static void removeVillageBiome(BiomeGenBase biome)
|
|
|
|
{
|
|
|
|
if (MapGenVillage.villageSpawnBiomes.contains(biome))
|
|
|
|
{
|
|
|
|
ArrayList<BiomeGenBase> biomes = new ArrayList<BiomeGenBase>(MapGenVillage.villageSpawnBiomes);
|
|
|
|
biomes.remove(biome);
|
|
|
|
MapGenVillage.villageSpawnBiomes = biomes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void addStrongholdBiome(BiomeGenBase biome)
|
|
|
|
{
|
2013-12-22 23:47:51 +00:00
|
|
|
if (!strongHoldBiomes.contains(biome))
|
2012-10-28 14:38:38 +00:00
|
|
|
{
|
2013-12-22 23:47:51 +00:00
|
|
|
strongHoldBiomes.add(biome);
|
2012-10-28 14:38:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeStrongholdBiome(BiomeGenBase biome)
|
|
|
|
{
|
2013-12-22 23:47:51 +00:00
|
|
|
if (!strongHoldBiomesBlackList.contains(biome))
|
2012-10-28 14:38:38 +00:00
|
|
|
{
|
2013-12-22 23:47:51 +00:00
|
|
|
strongHoldBiomesBlackList.add(biome);
|
2012-10-28 14:38:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void addSpawnBiome(BiomeGenBase biome)
|
|
|
|
{
|
|
|
|
if (!WorldChunkManager.allowedBiomes.contains(biome))
|
|
|
|
{
|
|
|
|
WorldChunkManager.allowedBiomes.add(biome);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeSpawnBiome(BiomeGenBase biome)
|
|
|
|
{
|
|
|
|
if (WorldChunkManager.allowedBiomes.contains(biome))
|
|
|
|
{
|
|
|
|
WorldChunkManager.allowedBiomes.remove(biome);
|
|
|
|
}
|
|
|
|
}
|
2014-04-11 01:01:28 +00:00
|
|
|
|
2014-08-26 08:02:09 +00:00
|
|
|
public static void addBiome(BiomeType type, BiomeEntry entry)
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
|
|
|
|
int idx = type.ordinal();
|
|
|
|
List<BiomeEntry> list = idx > biomes.length ? null : biomes[idx];
|
|
|
|
if (list != null) list.add(entry);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void removeBiome(BiomeType type, BiomeEntry entry)
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
|
|
|
|
int idx = type.ordinal();
|
|
|
|
List<BiomeEntry> list = idx > biomes.length ? null : biomes[idx];
|
|
|
|
|
|
|
|
if (list != null && list.contains(entry))
|
|
|
|
{
|
|
|
|
list.remove(entry);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public static ImmutableList<BiomeEntry> getBiomes(BiomeType type)
|
|
|
|
{
|
|
|
|
int idx = type.ordinal();
|
|
|
|
List<BiomeEntry> list = idx > biomes.length ? null : biomes[idx];
|
|
|
|
|
|
|
|
return list != null ? ImmutableList.copyOf(list) : null;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static boolean isTypeListModded(BiomeType type)
|
|
|
|
{
|
|
|
|
int idx = type.ordinal();
|
|
|
|
TrackedList<BiomeEntry> list = idx > biomes.length ? null : biomes[idx];
|
|
|
|
|
|
|
|
if (list != null) return list.isModded();
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static enum BiomeType
|
|
|
|
{
|
|
|
|
DESERT, WARM, COOL, ICY;
|
|
|
|
|
|
|
|
public static BiomeType getType(String name)
|
|
|
|
{
|
|
|
|
name = name.toUpperCase();
|
|
|
|
|
|
|
|
for (BiomeType t : values())
|
|
|
|
{
|
|
|
|
if (t.name().equals(name)) return t;
|
|
|
|
}
|
|
|
|
|
|
|
|
BiomeType ret = EnumHelper.addEnum(BiomeType.class, name, BiomeType.class);
|
|
|
|
|
|
|
|
if (ret.ordinal() >= biomes.length)
|
|
|
|
{
|
|
|
|
biomes = Arrays.copyOf(biomes, ret.ordinal());
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-04-11 01:01:28 +00:00
|
|
|
public static class BiomeEntry extends WeightedRandom.Item
|
|
|
|
{
|
|
|
|
public final BiomeGenBase biome;
|
|
|
|
|
|
|
|
public BiomeEntry(BiomeGenBase biome, int weight)
|
|
|
|
{
|
|
|
|
super(weight);
|
|
|
|
|
|
|
|
this.biome = biome;
|
|
|
|
}
|
|
|
|
}
|
2014-08-26 08:02:09 +00:00
|
|
|
|
|
|
|
private static class TrackedList<E> extends ArrayList<E>
|
|
|
|
{
|
|
|
|
private boolean isModded = false;
|
|
|
|
|
|
|
|
public TrackedList(Collection<? extends E> c)
|
|
|
|
{
|
|
|
|
super(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public E set(int index, E element)
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
return super.set(index, element);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean add(E e)
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
return super.add(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void add(int index, E element)
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
super.add(index, element);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public E remove(int index)
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
return super.remove(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean remove(Object o)
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
return super.remove(o);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void clear()
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
super.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean addAll(Collection<? extends E> c)
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
return super.addAll(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean addAll(int index, Collection<? extends E> c)
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
return super.addAll(index, c);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean removeAll(Collection<?> c)
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
return super.removeAll(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean retainAll(Collection<?> c)
|
|
|
|
{
|
|
|
|
isModded = true;
|
|
|
|
return super.retainAll(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isModded()
|
|
|
|
{
|
|
|
|
return isModded;
|
|
|
|
}
|
|
|
|
}
|
2014-10-10 10:22:47 +00:00
|
|
|
}
|