mirror of
https://github.com/MinecraftForge/MinecraftForge.git
synced 2026-11-18 03:25:18 +00:00
Fix Biome#getSpawnableList returning an empty list for non-vanilla EnumCreatureTypes (#3611)
This commit is contained in:
1 parent
a41288644d
commit
d53397111b
2 files changed
+94
-4
No files matched your search
@@ -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<Biome.SpawnListEntry> field_76762_K = Lists.<Biome.SpawnListEntry>newArrayList();
|
||||
protected List<Biome.SpawnListEntry> field_76755_L = Lists.<Biome.SpawnListEntry>newArrayList();
|
||||
protected List<Biome.SpawnListEntry> field_82914_M = Lists.<Biome.SpawnListEntry>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<EnumCreatureType, List<Biome.SpawnListEntry>> 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.<Biome.SpawnListEntry>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.<Biome.SpawnListEntry>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 <? extends Biome > func_150562_l()
|
||||
@@ -393,6 +394,83 @@
|
||||
@@ -393,6 +398,83 @@
|
||||
return this.field_76766_R;
|
||||
}
|
||||
|
||||
|
||||
@@ -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<? extends EntityLiving> 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<EntityHorse> 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);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user