Upon leaving certain biomes after extended trips (Nether and End for both, Mushroom Fields and variants for Patrols only), Patrols and possibly wandering traders that fail the spawn probability check but not the biome check will spawn immediately as soon as the player enters a suitable biome. Note that only one patrol or trader will spawn when the player returns, however, traders will spawn regardless of if one is already present near the area.
- Place a repeating command block and a Nether portal.
- Set the command block's command to /kill @e[type=Pillager] and set it to always be active.
- Make a behavior pack and copy the vanilla spawn rules for the Patrols.
- Change it to spawn the patrols every 60 seconds for normal difficulty, instead of 600-660, and change the spawn chance to 100.
- Change the normal difficulty's world age filter to 0.
- Load the behavior pack into the world and ensure the difficulty is set to normal.
- Wait for the command block to print the kill message, then enter the portal.
- Wait 90 seconds in the Nether, then return to the Overworld.
- The command block should print that it has killed more pillagers.
As wandering trader spawns are not data-driven yet, it's much more difficult to reproduce, but still possible.
- Make sure the world you're using to test it is at least 20 minutes old.
- Repeat steps 1 and 2, but change the command's target to all wandering_trader entities.
- Wait for the command block to print the kill message, then enter the Nether portal.
- Leave the game for a couple of hours. Traders have a random chance of spawning every 20 minutes which goes up after each of the first two spawn failures, so it's best to wait as long as possible before going back to the overworld.
- Cross your fingers and hope the command block prints a message.
Patrols and traders spawn immediately once the player exits the biome/dimension.
The spawn attempts done in the Nether should completely fail, and spawning should continue as normal once the player returns to the overworld.