I like the /gamerule command, but how would I make it so only zombies or ghasts don't spawn? Ghasts are really annoying... I'm sure you understand.
3 Answers
There is no vanilla game rule that can disable zombie and ghast spawning, but you can achieve something similar with a custom game rule and a killing clock.
The kill clock
First, set up a fast clock that triggers the following commands to teleport all Zombies and Ghasts into the void, killing them without them dropping any loot (This will prevent you from ever making Regeneration Potions).
/tp @e[type=Zombie] ~ ~-600 ~ /tp @e[type=Ghast] ~ ~-600 ~ Setting up a custom gamerule
Now, if you want to be able to toggle this, we need to create a custom gamerule, by running
/gamerule noZombieOrGhast 1 As of now, this does absolutely nothing. Let's get ourselves a dummy armorstand called #handle (replace however you like) and a dummy objective:
/summon ArmorStand ~ ~ ~ {CustomName:#handle,Invulnerable:1,NoGravity:1,Marker:1,Invisible:1} /scoreboard objectives add noZombieOrGhast dummy Now create another clock to query the value of the custom GameRule noZombieOrGhast
/gamerule noZombieOrGhast Make the command block output the queried result to the armor stand (x y z is the coordinates for the last command block:
/stats block x y z set QueryResult @e[name=#handle] noZombieOrGhast Finally, place a third command block into this clock to test for the armor stand with the score of 0:
/testfor @e[name=#handle,score_noZombieOrGhast=0] Put a comparator on this last command block, and make the output disable the killing clock.
Set the custom gamerule to 0 or 1 to allow or disallow Zombie and Ghast spawning, respectively.
/gamerule noZombieOrGhast 0 /gamerule noZombieOrGhast 1 0You can set up a simple redstone timer, and use the command block (obtained by /give @p command_block) and use the command /kill @e [type=undesiredMobNameHere] if set on a timer, the mob will die instantly after spawning.
The easiest and best way to do this is get a command block and set it to repeat, then do /tp @e[MobName] ~ ~-600 ~ so you don't have to build a redstone clock and don't have to see mob drops all around! Hope this helped! Oh and make sure to do /gamerule commandBlockOutput false so you don't get text all over your chat! :-)