diff --git a/patches/minecraft/net/minecraft/world/biome/Biome.java.patch b/patches/minecraft/net/minecraft/world/biome/Biome.java.patch index 1f0ed44f2f..b852758c51 100644 --- a/patches/minecraft/net/minecraft/world/biome/Biome.java.patch +++ b/patches/minecraft/net/minecraft/world/biome/Biome.java.patch @@ -18,7 +18,16 @@ private final String field_76791_y; private final float field_76748_D; private final float field_76749_E; -@@ -134,11 +134,12 @@ +@@ -90,6 +90,8 @@ + protected List field_76762_K = Lists.newArrayList(); + protected List field_76755_L = Lists.newArrayList(); + protected List field_82914_M = Lists.newArrayList(); ++ // Forge: Stores the spawnable lists for non-vanilla EnumCreatureTypes. Can't be an EnumMap as that doesn't handle new enum values being added after it's created. ++ protected java.util.Map> modSpawnableLists = com.google.common.collect.Maps.newHashMap(); + + public static int func_185362_a(Biome p_185362_0_) + { +@@ -134,11 +136,12 @@ this.field_76761_J.add(new Biome.SpawnListEntry(EntityWitch.class, 5, 1, 1)); this.field_76755_L.add(new Biome.SpawnListEntry(EntitySquid.class, 10, 4, 4)); this.field_82914_M.add(new Biome.SpawnListEntry(EntityBat.class, 10, 8, 8)); @@ -32,7 +41,18 @@ } public boolean func_185363_b() -@@ -234,7 +235,7 @@ +@@ -182,7 +185,9 @@ + case AMBIENT: + return this.field_82914_M; + default: +- return Collections.emptyList(); ++ // Forge: Return a non-empty list for non-vanilla EnumCreatureTypes ++ if (!this.modSpawnableLists.containsKey(p_76747_1_)) this.modSpawnableLists.put(p_76747_1_, Lists.newArrayList()); ++ return this.modSpawnableLists.get(p_76747_1_); + } + } + +@@ -234,7 +239,7 @@ { double d0 = (double)MathHelper.func_76131_a(this.func_180626_a(p_180627_1_), 0.0F, 1.0F); double d1 = (double)MathHelper.func_76131_a(this.func_76727_i(), 0.0F, 1.0F); @@ -41,7 +61,7 @@ } public final void func_180628_b(World p_180628_1_, Random p_180628_2_, ChunkPrimer p_180628_3_, int p_180628_4_, int p_180628_5_, double p_180628_6_) -@@ -327,7 +328,7 @@ +@@ -327,7 +332,7 @@ { double d0 = (double)MathHelper.func_76131_a(this.func_180626_a(p_180625_1_), 0.0F, 1.0F); double d1 = (double)MathHelper.func_76131_a(this.func_76727_i(), 0.0F, 1.0F); @@ -50,7 +70,7 @@ } public Class func_150562_l() -@@ -393,6 +394,83 @@ +@@ -393,6 +398,83 @@ return this.field_76766_R; } diff --git a/src/test/java/net/minecraftforge/test/BiomeSpawnableListTest.java b/src/test/java/net/minecraftforge/test/BiomeSpawnableListTest.java new file mode 100644 index 0000000000..3f44ea244d --- /dev/null +++ b/src/test/java/net/minecraftforge/test/BiomeSpawnableListTest.java @@ -0,0 +1,70 @@ +package net.minecraftforge.test; + +import net.minecraft.block.material.Material; +import net.minecraft.entity.EntityLiving; +import net.minecraft.entity.EnumCreatureType; +import net.minecraft.entity.passive.AbstractHorse; +import net.minecraft.entity.passive.EntityHorse; +import net.minecraft.init.Biomes; +import net.minecraft.init.Bootstrap; +import net.minecraft.world.biome.Biome; +import net.minecraftforge.common.util.EnumHelper; +import net.minecraftforge.fml.common.registry.EntityRegistry; +import net.minecraftforge.fml.common.registry.ForgeTestRunner; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +@RunWith(ForgeTestRunner.class) +public class BiomeSpawnableListTest +{ + private static EnumCreatureType creatureTypeHorse; + + @BeforeClass + public static void setUp() throws Exception + { + Bootstrap.register(); + creatureTypeHorse = EnumHelper.addCreatureType("biomespawnablelisttest:horse", AbstractHorse.class, 20, Material.AIR, true, true); + } + + private boolean spawnableListContainsEntry(Class entityClass, int weightedProb, int minGroupCount, int maxGroupCount, + EnumCreatureType creatureType, Biome biome) + { + boolean found = false; + + for (Biome.SpawnListEntry spawnListEntry : biome.getSpawnableList(creatureType)) + { + if (spawnListEntry.entityClass == entityClass && spawnListEntry.itemWeight == weightedProb && spawnListEntry.minGroupCount == minGroupCount + && spawnListEntry.maxGroupCount == maxGroupCount) + { + found = true; + break; + } + } + + return found; + } + + @Test + public void testAddAndRemoveSpawn() throws Exception + { + final Class entityClass = EntityHorse.class; + final int weightedProb = 1; + final int minGroupCount = 1; + final int maxGroupCount = 20; + final Biome biome = Biomes.PLAINS; + + // Test 1: We can add a spawn for the non-vanilla EnumCreatureType + EntityRegistry.addSpawn(entityClass, weightedProb, minGroupCount, maxGroupCount, creatureTypeHorse, biome); + final boolean containsEntryAfterAdd = spawnableListContainsEntry(entityClass, weightedProb, minGroupCount, maxGroupCount, creatureTypeHorse, biome); + assertTrue("The SpawnListEntry wasn't added", containsEntryAfterAdd); + + // Test 2: We can remove a spawn for the non-vanilla EnumCreatureType + EntityRegistry.removeSpawn(entityClass, creatureTypeHorse, biome); + final boolean containsEntryAfterRemove = spawnableListContainsEntry(entityClass, weightedProb, minGroupCount, maxGroupCount, creatureTypeHorse, biome); + assertFalse("The SpawnListEntry wasn't removed", containsEntryAfterRemove); + } +}