Fixed biome weights not working with non multiples of 10

This commit is contained in:
Adubbz 2014-08-26 18:02:09 +10:00
parent fa7ff7c6e7
commit 0d93bec5e7
2 changed files with 244 additions and 44 deletions

View file

@ -1,6 +1,6 @@
--- ../src-base/minecraft/net/minecraft/world/gen/layer/GenLayerBiome.java --- ../src-base/minecraft/net/minecraft/world/gen/layer/GenLayerBiome.java
+++ ../src-work/minecraft/net/minecraft/world/gen/layer/GenLayerBiome.java +++ ../src-work/minecraft/net/minecraft/world/gen/layer/GenLayerBiome.java
@@ -1,29 +1,49 @@ @@ -1,29 +1,52 @@
package net.minecraft.world.gen.layer; package net.minecraft.world.gen.layer;
+import java.util.ArrayList; +import java.util.ArrayList;
@ -18,10 +18,7 @@
- private BiomeGenBase[] field_151621_d; - private BiomeGenBase[] field_151621_d;
- private BiomeGenBase[] field_151622_e; - private BiomeGenBase[] field_151622_e;
- private BiomeGenBase[] field_151620_f; - private BiomeGenBase[] field_151620_f;
+ private List<BiomeEntry> desertBiomes = new ArrayList<BiomeEntry>(); + private List<BiomeEntry>[] biomes = new ArrayList[BiomeManager.BiomeType.values().length];
+ private List<BiomeEntry> warmBiomes = new ArrayList<BiomeEntry>();
+ private List<BiomeEntry> coolBiomes = new ArrayList<BiomeEntry>();
+ private List<BiomeEntry> icyBiomes = new ArrayList<BiomeEntry>();
+ +
private static final String __OBFID = "CL_00000555"; private static final String __OBFID = "CL_00000555";
@ -36,60 +33,81 @@
this.field_75909_a = p_i2122_3_; this.field_75909_a = p_i2122_3_;
- -
+ +
+ this.desertBiomes.addAll(BiomeManager.desertBiomes); + for (BiomeManager.BiomeType type : BiomeManager.BiomeType.values())
+ this.warmBiomes.addAll(BiomeManager.warmBiomes); + {
+ this.coolBiomes.addAll(BiomeManager.coolBiomes); + com.google.common.collect.ImmutableList<BiomeEntry> biomesToAdd = BiomeManager.getBiomes(type);
+ this.icyBiomes.addAll(BiomeManager.icyBiomes); + int idx = type.ordinal();
+
+ if (biomes[idx] == null) biomes[idx] = new ArrayList<BiomeEntry>();
+ if (biomesToAdd != null) biomes[idx].addAll(biomesToAdd);
+ }
+
+ int desertIdx = BiomeManager.BiomeType.DESERT.ordinal();
+ +
if (p_i2122_4_ == WorldType.field_77136_e) if (p_i2122_4_ == WorldType.field_77136_e)
{ {
- this.field_151623_c = new BiomeGenBase[] {BiomeGenBase.field_76769_d, BiomeGenBase.field_76767_f, BiomeGenBase.field_76770_e, BiomeGenBase.field_76780_h, BiomeGenBase.field_76772_c, BiomeGenBase.field_76768_g}; - this.field_151623_c = new BiomeGenBase[] {BiomeGenBase.field_76769_d, BiomeGenBase.field_76767_f, BiomeGenBase.field_76770_e, BiomeGenBase.field_76780_h, BiomeGenBase.field_76772_c, BiomeGenBase.field_76768_g};
+ desertBiomes.add(new BiomeEntry(BiomeGenBase.field_76769_d, 10)); + biomes[desertIdx].add(new BiomeEntry(BiomeGenBase.field_76769_d, 10));
+ desertBiomes.add(new BiomeEntry(BiomeGenBase.field_76767_f, 10)); + biomes[desertIdx].add(new BiomeEntry(BiomeGenBase.field_76767_f, 10));
+ desertBiomes.add(new BiomeEntry(BiomeGenBase.field_76770_e, 10)); + biomes[desertIdx].add(new BiomeEntry(BiomeGenBase.field_76770_e, 10));
+ desertBiomes.add(new BiomeEntry(BiomeGenBase.field_76780_h, 10)); + biomes[desertIdx].add(new BiomeEntry(BiomeGenBase.field_76780_h, 10));
+ desertBiomes.add(new BiomeEntry(BiomeGenBase.field_76772_c, 10)); + biomes[desertIdx].add(new BiomeEntry(BiomeGenBase.field_76772_c, 10));
+ desertBiomes.add(new BiomeEntry(BiomeGenBase.field_76768_g, 10)); + biomes[desertIdx].add(new BiomeEntry(BiomeGenBase.field_76768_g, 10));
} }
+ else + else
+ { + {
+ desertBiomes.add(new BiomeEntry(BiomeGenBase.field_76769_d, 30)); + biomes[desertIdx].add(new BiomeEntry(BiomeGenBase.field_76769_d, 30));
+ desertBiomes.add(new BiomeEntry(BiomeGenBase.field_150588_X, 20)); + biomes[desertIdx].add(new BiomeEntry(BiomeGenBase.field_150588_X, 20));
+ desertBiomes.add(new BiomeEntry(BiomeGenBase.field_76772_c, 10)); + biomes[desertIdx].add(new BiomeEntry(BiomeGenBase.field_76772_c, 10));
+ } + }
} }
public int[] func_75904_a(int p_75904_1_, int p_75904_2_, int p_75904_3_, int p_75904_4_) public int[] func_75904_a(int p_75904_1_, int p_75904_2_, int p_75904_3_, int p_75904_4_)
@@ -63,7 +83,7 @@ @@ -63,7 +86,7 @@
} }
else else
{ {
- aint1[j1 + i1 * p_75904_3_] = this.field_151623_c[this.func_75902_a(this.field_151623_c.length)].field_76756_M; - aint1[j1 + i1 * p_75904_3_] = this.field_151623_c[this.func_75902_a(this.field_151623_c.length)].field_76756_M;
+ aint1[j1 + i1 * p_75904_3_] = ((BiomeEntry)WeightedRandom.getItem(this.desertBiomes, (int)(this.nextLong(WeightedRandom.func_76272_a(this.desertBiomes) / 10) * 10))).biome.field_76756_M; + aint1[j1 + i1 * p_75904_3_] = getWeightedBiomeEntry(BiomeManager.BiomeType.DESERT).biome.field_76756_M;
} }
} }
else if (k1 == 2) else if (k1 == 2)
@@ -74,7 +94,7 @@ @@ -74,7 +97,7 @@
} }
else else
{ {
- aint1[j1 + i1 * p_75904_3_] = this.field_151621_d[this.func_75902_a(this.field_151621_d.length)].field_76756_M; - aint1[j1 + i1 * p_75904_3_] = this.field_151621_d[this.func_75902_a(this.field_151621_d.length)].field_76756_M;
+ aint1[j1 + i1 * p_75904_3_] = ((BiomeEntry)WeightedRandom.getItem(this.warmBiomes, (int)(this.nextLong(WeightedRandom.func_76272_a(this.warmBiomes) / 10) * 10))).biome.field_76756_M; + aint1[j1 + i1 * p_75904_3_] = getWeightedBiomeEntry(BiomeManager.BiomeType.WARM).biome.field_76756_M;
} }
} }
else if (k1 == 3) else if (k1 == 3)
@@ -85,12 +105,12 @@ @@ -85,12 +108,12 @@
} }
else else
{ {
- aint1[j1 + i1 * p_75904_3_] = this.field_151622_e[this.func_75902_a(this.field_151622_e.length)].field_76756_M; - aint1[j1 + i1 * p_75904_3_] = this.field_151622_e[this.func_75902_a(this.field_151622_e.length)].field_76756_M;
+ aint1[j1 + i1 * p_75904_3_] = ((BiomeEntry)WeightedRandom.getItem(this.coolBiomes, (int)(this.nextLong(WeightedRandom.func_76272_a(this.coolBiomes) / 10) * 10))).biome.field_76756_M; + aint1[j1 + i1 * p_75904_3_] = getWeightedBiomeEntry(BiomeManager.BiomeType.COOL).biome.field_76756_M;
} }
} }
else if (k1 == 4) else if (k1 == 4)
{ {
- aint1[j1 + i1 * p_75904_3_] = this.field_151620_f[this.func_75902_a(this.field_151620_f.length)].field_76756_M; - aint1[j1 + i1 * p_75904_3_] = this.field_151620_f[this.func_75902_a(this.field_151620_f.length)].field_76756_M;
+ aint1[j1 + i1 * p_75904_3_] = ((BiomeEntry)WeightedRandom.getItem(this.icyBiomes, (int)(this.nextLong(WeightedRandom.func_76272_a(this.icyBiomes) / 10) * 10))).biome.field_76756_M; + aint1[j1 + i1 * p_75904_3_] = getWeightedBiomeEntry(BiomeManager.BiomeType.ICY).biome.field_76756_M;
} }
else else
{ {
@@ -101,4 +124,14 @@
return aint1;
}
+
+ protected BiomeEntry getWeightedBiomeEntry(BiomeManager.BiomeType type)
+ {
+ List<BiomeEntry> biomeList = biomes[type.ordinal()];
+ int totalWeight = WeightedRandom.func_76272_a(biomeList);
+ int rand = func_75902_a(totalWeight / 10) * 10;
+ int weight = rand + (BiomeManager.isTypeListModded(type) ? func_75902_a(Math.min(10, totalWeight - rand)) : 0);
+
+ return (BiomeEntry)WeightedRandom.getItem(biomeList, weight);
+ }
}

View file

@ -1,22 +1,38 @@
package net.minecraftforge.common; package net.minecraftforge.common;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import com.google.common.collect.ImmutableList;
import net.minecraft.util.WeightedRandom; import net.minecraft.util.WeightedRandom;
import net.minecraft.world.WorldType; import net.minecraft.world.WorldType;
import net.minecraft.world.biome.BiomeGenBase; import net.minecraft.world.biome.BiomeGenBase;
import net.minecraft.world.gen.structure.MapGenVillage; import net.minecraft.world.gen.structure.MapGenVillage;
import net.minecraft.world.biome.WorldChunkManager; import net.minecraft.world.biome.WorldChunkManager;
import net.minecraftforge.common.BiomeDictionary.Type;
import net.minecraftforge.common.util.EnumHelper;
public class BiomeManager public class BiomeManager
{ {
public static List<BiomeEntry> desertBiomes = new ArrayList<BiomeEntry>(); private static TrackedList<BiomeEntry>[] biomes = setupBiomes();
public static List<BiomeEntry> warmBiomes = new ArrayList<BiomeEntry>();
public static List<BiomeEntry> coolBiomes = new ArrayList<BiomeEntry>(); /*
public static List<BiomeEntry> icyBiomes = new ArrayList<BiomeEntry>(); * 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>(); public static List<BiomeGenBase> oceanBiomes = new ArrayList<BiomeGenBase>();
@ -25,26 +41,43 @@ public class BiomeManager
static 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.ocean);
oceanBiomes.add(BiomeGenBase.deepOcean); oceanBiomes.add(BiomeGenBase.deepOcean);
oceanBiomes.add(BiomeGenBase.frozenOcean); 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") @SuppressWarnings("unchecked")
public static void addVillageBiome(BiomeGenBase biome, boolean canSpawn) 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 static class BiomeEntry extends WeightedRandom.Item
{ {
public final BiomeGenBase biome; public final BiomeGenBase biome;
@ -110,4 +207,89 @@ public class BiomeManager
this.biome = biome; 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;
}
}
} }