Can passive mobs spawn underground?
There's a rumour that passive mobs (pigs, cows, sheep) can only spawn on the highest solid block. In other words, they won't spawn on grass with a solid block roof over it, such as in an underground cave, a player-built barn, or a glass dome.
Is this true, as of Minecraft 1.0?
Solution 1:
I'm no expert at Java, so this isn't a decisive answer, but I figure it can't hurt to post the code here anyway for others to decipher. From SpawnerAnimals.java
:
(Comments mine)
private static boolean canCreatureTypeSpawnAtLocation(EnumCreatureType enumcreaturetype, World world, int i, int j, int k)
{
if(enumcreaturetype.getCreatureMaterial() == Material.water)
// If it's a water creature...
{
return world.getBlockMaterial(i, j, k).getIsLiquid() && !world.isBlockNormalCube(i, j + 1, k);
// Make sure it spawns in water
} else
{
return world.isBlockNormalCube(i, j - 1, k) && !world.isBlockNormalCube(i, j, k) && !world.getBlockMaterial(i, j, k).getIsLiquid() && !world.isBlockNormalCube(i, j + 1, k);
// Makes sure the block it's spawning on is opaque, that it's not water, and that there are at least 2 blocks of air overhead.
}
}
It does not appear that it checks whether the mob is spawning underground or not.
Anecdotally, wandering around for a while with an Xray texture pack produced only surface mobs, so I'm not sure what other guards might be put in place to prevent underground spawns.
Solution 2:
Passive mobs will spawn if the following conditions are met:
- There is a grass block
- There is 2x2x2 empty space
- There is a light level above 7
Solution 3:
No, they can definitely spawn underground. I had a world where I had dug out a massive cavern, encasing all the lava in glass, then placed grass on top of the lava to create big underground islands. I had animals spawning on the grass, at level 13.
Edit: This was, however, in an older version of minecraft. I won't be able to check to see if that's still true until I get home.