Minecraft – How to Keep Cows from Running Away

minecraft-java-edition

I've built a fenced area in Minecraft in which cows, pigs and over wildlife I intend to congregate. Only problem, how can I make them happy? In that they quite often bounce by the fence, wanting to get out. Any recommendations?
enter image description here

Best Answer

Cows (along with all passive mobs) have no AI other than "wander". They will blissfully stumble head-first into lava if given the chance.

As of Beta 1.6.6, there is no way to encourage Passive Mobs to stick around; even "happy" cows will disappear into the ether if you wander far enough away that the chunk gets unloaded from Memory.

On the other hand, fence-escaping can simply be halted by making the fence taller.

Edit:

As of Beta 1.8, passive mobs no longer despawn. If you fence a cow, sheep, or pig, and keep them safe from wolves / aggressive mobs, they should stay fenced-in indefinitely.