What are the rules of spawning zombie pigmen from nether portals?

Solution 1:

Exactly nothing changes whether Zombie Pigman spawn from Nether portals.

(Well, apart from turning on Peaceful, of course.)

Looking at the code for 1.6.2 in MCP, the code for spawning Zombie Pigmen in portals is dead simple, being only 6 lines of code. If the portal block receives a tick, it checks the difficulty against a random number and if successful, tries to spawn a Zombie Pigman with its feet inside the portal block. It does a check to make sure there is headroom and a solid block under the Pigman's feet, which is why they only spawn with their feet inside the two lower portal blocks inside the frame.

That's it. Light level, player location, and the number of Zombie Pigmen nearby aren't consulted at all.

That means that, so long as the portal is active and in a loaded chunk, it will spawn Zombie Pigmen. By implication, the only way to stop them from spawning is to to deactivate the portal so there are no portal blocks to receive ticks, or to go far away from the portal so the game unloads the chunk it's in.

Further implications:

  • Lowering the difficulty level will decrease Zombie Pigmen spawns from portals. The chance of spawning in a given tick is proportional to the difficulty level d: d/2000, or 1/2000 on Easy, 1/1000 on Normal, and 1/666.6 (repeating) on Hard.
  • Since they always spawn within the portal blocks you can easily fence them in.

One method of Zombie Pigmen control that leverages the limited spawning area would be to put doors or fence gates flush against one side of the portal where you normally enter it, and a waterfall at the level of the bottom frame on the other side. This will transport Zombie Pigmen into a holding area where you can dispose of them at your leisure, leaving your portal free for use. If there are any Zombie Pigmen standing in the portal when you want to use it because they haven't gone for a swim yet, you can just gently nudge them into the water flow as you pass through.

Solution 2:

Look at the Farming topic of the Zombie Pigman article at the Minecraft Wiki.

Farming

A Zombie Pigman farm attached to a mob grinder. Since Zombie Pigmen spawn in the Nether and in Nether Portals in the Overworld, you can build a Zombie Pigman farm in either dimension which provides a steady stream of Gold Nuggets. Additionally, you can obtain Gold Ingots and Gold Swords as rare drops. To construct a farm in the Nether, build platforms for Zombie Pigmen to spawn on, with trapdoors on the edge, and place Slabs on the floors of all surrounding areas (or just fill them in) so Pigmen only spawn on your platforms. You can then use Lava flows to collect the Zombie Pigmen into a central area. To build a farm in the Overworld, construct a rectangular prism of interlocking Nether Portals (to save Obsidian) and put open Trapdoors on the edges of the two bottom Obsidian blocks so that the Zombie Pigmen walk off. From here, you can use Water to collect the Zombie Pigmen into a fall or suffocation trap. Using a fall trap has the benefit of automation, but with a suffocation trap, you are able to use pistons to control the amount of damage to the Pigmen. This way, you can obtain rare drops by killing the Pigmen yourself, perhaps with a Looting III enchantment.

Spawn rate

When ticked the block generates a number between 0 and 2000 inclusive, if that value is less than the difficulty setting, a pigman is generated. This means more pigmen will spawn the higher the level of difficulty.