It won't stop mobs from spawning but the second they spawn they will die. You first give yourself a command block. Then, type this command: /kill @e [type=zombie] This example will kill zombies. Set the command block to repeat and always active. You can type any mob name in place of the word zombie but you have to individually put in a command
Steps to Reproduce: Spawn a villager. Place a bed and workstation block. Wait for the villager to link up to the workstation. Break the workstation block. Turn the villager into a zombie villager. Place a minecart or boat nearby and try to get the zombie villager to enter it.
7HS2. 116 329 174 349 251 2 241 362 108