How can I protect my pigs so they don't become pigmen?

My pig has just turned into a zombie pigman. I have tried putting them inside, but they still turn into the pigmen!


Solution 1:

Lightning only strikes straight down, but can transform a pig within 3-4 blocks of the lightning strike. Therefore, to keep your pigs safe from lightning storms, their shed has to be built so that it keeps them at least 5 blocks away from the outside sky. Building a 5 block wide overhang around the shed roof should do it. Alternatively, make your barn so that the pigs are in an inner chamber, with less "volatile" livestock like chickens and cows in the chambers near the walls.

Solution 2:

Dig a 5 by 5 hole 10 blocks deep, and build stairs with a door at the top so the pigs wont get out. Put torches so no mobs can spawn, and build a roof out of any material except wood.