The animals are trapped in pastures to spawn...in survival and creative
http://www.youtube.com/watch?v=l3wLq5VnM5E
Related issues
is duplicated by
relates to
Attachments
Comments


Please provide a description of your issue, and not just pictures.

This has been around since before 1.4, Basically animals spawn on the grass, in the leaf blocks.

Duplicate of MC-1998

The fix is quite simple I think. The spawning Algo currently checks if the the block to spawn on is translucent, but instead it should check if the block has a bounding box where entities collide on.

@Tyron That And It Also Spawn The Jungle Over The Mobs A Lot Of Times During World Generation

arthur stop starting every word of your sentence with a capital!!!!

Yes, its especially annoing in jungle biomes

happens very often when I play! NOT ONLY in jungles. every tree leafs! Shouldn't be that difficult to fix I guess

You can't die in leaves. And unless you stand right next to a sapling and bone meal it, it won't happen again.
It's a one-time thing.

But the animal AI doesn't try to get out of leaves, and so the animal is stuck there until the block it is in is destroyed.

Seen this issue many, mnay times.

its not a bug its a feature.

Confirmed. This happens to me all the time.

Confirmed as well, and just cause: http://home.turt2live.com/sheep.png
It seems to only happen to sheep, and only in specific spots. I've noticed that after I free the sheep very often there is another sheep there a couple hours later

I have seen this happen with cows, pigs, and chickens too. You were probably just unlucky.

There are two ways the game gets animals inside leaves.
One is when an animal has already been created and the terrain generator creates a bush (in jungle) without checking where it puts its leaves. This is somewhat rare (like 2-3 cases when generating new world and starting near a jungle).
The other is when an animal is being spawned and the leaves are already there. The spawning routine asks the world object for the top solid or liquid block (i.e. ground or water surface). However, this indeed returns the ground level; The method has specific check to ignore leaves. It then checks the creature type if it is ok to spawn in the block, but this check only considers things like water animal into water. This mistake of ignoring leaves and using blindly the ground level causes most of trouble; like 33 cases with the same jungle as those 2-3 other cases. (Edit: note, some of those 33 may get themselves out of the leaves by themselves.)

Fix
Original code:
SpawnerAnimals.performWorldGenSpawning()
...
if (canCreatureTypeSpawnAtLocation(EnumCreatureType.creature, par0World, var10, var17, var11)) {
float var18 = (float)var10 + 0.5F;
float var19 = (float)var17;
float var20 = (float)var11 + 0.5F;
EntityLiving var21;
try {
var21 = (EntityLiving)var8.entityClass.getConstructor(new Class[] {World.class}).newInstance(new Object[] {par0World});
} catch (Exception var23) {
var23.printStackTrace();
continue;
}
var21.setLocationAndAngles((double)var18, (double)var19, (double)var20, par6Random.nextFloat() * 360.0F, 0.0F);
par0World.spawnEntityInWorld(var21);
creatureSpecificInit(var21, par0World, var18, var19, var20);
var15 = true;
}
...
Fixed, with MCP naming and my own additional variable name interpretations:
SpawnerAnimals.performWorldGenSpawning()
...
if (canCreatureTypeSpawnAtLocation(EnumCreatureType.creature, world, spawnX, spawnVerY, spawnHorZ)) {
float var18 = (float) spawnX + 0.5F;
float var19 = (float) spawnVerY;
float var20 = (float) spawnHorZ + 0.5F;
EntityLiving var21;
try {
var21 = (EntityLiving) var8.entityClass.getConstructor(new Class[] { World.class }).newInstance(new Object[] { world });
} catch (Exception var23) {
var23.printStackTrace();
continue;
}
// FIX:
boolean doSpawn = true;
int blockId = world.getBlockId(spawnX, spawnVerY, spawnHorZ);
if (blockId != 0 && Block.blocksList[blockId].blockMaterial == Material.leaves) {
doSpawn = false;
for (int climbLeaves = 1; climbLeaves <= 3; climbLeaves++) {
blockId = world.getBlockId(spawnX, spawnVerY+climbLeaves, spawnHorZ);
if (blockId == 0) {
var19 += climbLeaves;
doSpawn = true;
break;
}
}
}
// Continue as before if the block is considered suitable:
if (doSpawn) {
var21.setLocationAndAngles((double) var18, (double) var19, (double) var20, chunkProvidersRandom.nextFloat() * 360.0F, 0.0F);
world.spawnEntityInWorld(var21);
creatureSpecificInit(var21, world, var18, var19, var20);
spawned = true;
}
}
...
The fixed code above may have some oopsies as I had to slightly clean it up without checking (the real version has plenty of debugging nonsense in it), but the idea is clear.
Also, a better fix would be to provide another method in world class that already seeks for the place above leaves, so that the method can be used by other spawning routines, too. For example, (by MCP naming) WorldGenShrub would also benefit from the same/similar fix, and there is another similar spawner method in the same SpawnerAnimals class.
I've attached a console log file 'jungle-console-results.txt' showing a little bit of what is happening when the fix is applied (and also with a check, but no fix, in the WorldGenShrub class).
A good seed to check the results could be 4541576050680254111; it has several animals blocked in the leaves quite near the spawn. (Also, as an additional benefit, that is a good seed to test the problem of player spawned inside leaves, as it seems to do so very frequently, including a case where I spawned standing on a branch of a "big tree", inside leaves.)

Affects 13w09b. Interesting though, I could only find chickens in the test-jungle. Nevertheless, both me and many of the chickens were spawned inside leaves.

Affects 13w10a. Found cows in another world's jungle, one of them stuck in leaves.

I've seen sheep spawning inside of trees & jungle bushes ever since we got the jungle biomes. Used to be pigs too.

Affects 1.6.2 (situation same as couple comments ago, my test seed now produces only chickens near the spawn, but some of them are inside leaves).

Confirmed.

Confirmed: affects 13w38c. It even seems that the number of mobs trapped in leaves has grown (more mobs spawn in leaves than before).

Confirmed for 13w48b. I saw a few chickens inside one of those miniature one-log-block jungle trees.

Is this still a concern in the latest Minecraft version 14w03b? If so, please update the affected versions in order to best aid Mojang ensuring bugs are still valid in the latest releases/pre-releases.

They are! I was playing in a 14w04a survival world, and I found a sheep inside a leaf block! And I also have a question: How do I upload screenshots on comments?

While you can't include screenshots in a comment (other than providing a link to one), you can attach one to an issue by clicking the "Attach Files" button at the top of the page.
Actually, you can include images in comments. If it's already attached to the ticket, you can just surround its filename with exclamation points. If it's uploaded elsewhere, you can use the full URL of the file.

I've the feeling that mobs appear less often in the leaves in 06b but this is still the case. Some mobs suffocate while others do not.

That is probably because they suffocate due to another bug.

Suffocation in leaves: MC-46765
The animals that are only 1 block tall or shorter have their head in the leaves, and so, suffocate. The animals that are 1.5 blocks tall or more don't have their heads in a leaf block, so they don't suffocate.

Affects 14w10c. Used creative mode and seed -4542366974610774625, fly, /tp ... 1200 120 800, let the area generate, fly lower and around. At least 3 groups of sheeps with at least one sheep inside leaves initially. They do seem to get out eventually, jumping on top of the leaves they spawn in, so if taking too long looking for them, they will be free already.

So, because of MC-46765 animals spawned in leaves suffocate. Why is that, can chickens somehow exploit this to grief? Can sheep use it to find ores? Can pigs use it to gain an advantage in SMP?
Come on, something to manage player balance should only affect players. Mobs don't spawn normally as it is, so having a big chunk of them die in leaves because of an X-ray issue is a big problem and frankly stupid.

Animals are spawning inside leaves in 14w32b.

Confirmed in the 1.8 -Pre1.

Still in 1.8

In 1.8 I saw an animal on the top of a tree... I think this is related to this bug.

1.8.4 17 sheep spawned in a leaf block, jungle, and suffocated\ Creative

Confirmed for
1.8.7 I assume the game treats the leaves as non-solid blocks when spawning the animals

Still present in 1.9 snapshots (as of 15w35a). The sheep I saw didn't seem to be suffocating, though.

Was this fixed as a result of MC-64492 being fixed?

Certainly seems fixed; I flew around for a while in the jungle that Markku provided and all the animals seemed to have spawned correctly.