mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-12 16:27:47 +00:00
Fixed biome weights not working with non multiples of 10
This commit is contained in:
1 parent
fa7ff7c6e7
commit
0d93bec5e7
2 files changed
+244
-44
No files matched your search
@@ -1,22 +1,38 @@
|
||||
package net.minecraftforge.common;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.ImmutableList;
|
||||
|
||||
import net.minecraft.util.WeightedRandom;
|
||||
import net.minecraft.world.WorldType;
|
||||
import net.minecraft.world.biome.BiomeGenBase;
|
||||
import net.minecraft.world.gen.structure.MapGenVillage;
|
||||
import net.minecraft.world.biome.WorldChunkManager;
|
||||
import net.minecraftforge.common.BiomeDictionary.Type;
|
||||
import net.minecraftforge.common.util.EnumHelper;
|
||||
|
||||
public class BiomeManager
|
||||
{
|
||||
public static List<BiomeEntry> desertBiomes = new ArrayList<BiomeEntry>();
|
||||
public static List<BiomeEntry> warmBiomes = new ArrayList<BiomeEntry>();
|
||||
public static List<BiomeEntry> coolBiomes = new ArrayList<BiomeEntry>();
|
||||
public static List<BiomeEntry> icyBiomes = new ArrayList<BiomeEntry>();
|
||||
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;
|
||||
|
||||
public static List<BiomeGenBase> oceanBiomes = new ArrayList<BiomeGenBase>();
|
||||
|
||||
@@ -25,25 +41,42 @@ public class BiomeManager
|
||||
|
||||
static
|
||||
{
|
||||
warmBiomes.add(new BiomeEntry(BiomeGenBase.forest, 10));
|
||||
warmBiomes.add(new BiomeEntry(BiomeGenBase.roofedForest, 10));
|
||||
warmBiomes.add(new BiomeEntry(BiomeGenBase.extremeHills, 10));
|
||||
warmBiomes.add(new BiomeEntry(BiomeGenBase.plains, 10));
|
||||
warmBiomes.add(new BiomeEntry(BiomeGenBase.birchForest, 10));
|
||||
warmBiomes.add(new BiomeEntry(BiomeGenBase.swampland, 10));
|
||||
|
||||
coolBiomes.add(new BiomeEntry(BiomeGenBase.forest, 10));
|
||||
coolBiomes.add(new BiomeEntry(BiomeGenBase.extremeHills, 10));
|
||||
coolBiomes.add(new BiomeEntry(BiomeGenBase.taiga, 10));
|
||||
coolBiomes.add(new BiomeEntry(BiomeGenBase.plains, 10));
|
||||
|
||||
icyBiomes.add(new BiomeEntry(BiomeGenBase.icePlains, 30));
|
||||
icyBiomes.add(new BiomeEntry(BiomeGenBase.coldTaiga, 10));
|
||||
|
||||
oceanBiomes.add(BiomeGenBase.ocean);
|
||||
oceanBiomes.add(BiomeGenBase.deepOcean);
|
||||
oceanBiomes.add(BiomeGenBase.frozenOcean);
|
||||
}
|
||||
|
||||
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();
|
||||
|
||||
return currentBiomes;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static void addVillageBiome(BiomeGenBase biome, boolean canSpawn)
|
||||
@@ -99,6 +132,70 @@ public class BiomeManager
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
public static class BiomeEntry extends WeightedRandom.Item
|
||||
{
|
||||
public final BiomeGenBase biome;
|
||||
@@ -110,4 +207,89 @@ public class BiomeManager
|
||||
this.biome = biome;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user