How do you prevent certain mobs from spawning in vanilla minecraft?

How do you prevent certain mobs from spawning in vanilla minecraft? - Set of gratitude message for doctors with stethoscope and hearts

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.



Best Answer

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



Pictures about "How do you prevent certain mobs from spawning in vanilla minecraft?"

How do you prevent certain mobs from spawning in vanilla minecraft? - From above arrangement of red heart shapes placed on blue background with THANK YOU NURSES inscription
How do you prevent certain mobs from spawning in vanilla minecraft? - From above of vintage light box with THANK YOU DOCTORS gratitude message placed on green surface
How do you prevent certain mobs from spawning in vanilla minecraft? - From above of vintage light box with THANK YOU DOCTORS inscription placed on green surface



What is the best way to stop mobs from spawning?

One of the most basic ways to prevent mob spawning is by placing torches. These increase the light level around them, stopping hostiles from spawning. Other blocks such as glowstone or shroomlight emit higher light levels, but are harder to come by.

How do I stop mobs from spawning in a certain area?

Ways of preventing mobs from spawning in Minecraft To prevent this, players can use blocks that emit light, such as torches and glowstone, in areas where they want to prevent these mobs from spawning. Torches are one of the easiest light-emitting items to craft as they only require sticks and coal.

How do you stop mobs from spawning in a certain area without light?

The command /gamerule doMobSpawning false will prevent mobs from spawning without player help. Use /gamerule doMobSpawning true to turn it back on.



Minecraft| How to get rid specific Mobs?




More answers regarding how do you prevent certain mobs from spawning in vanilla minecraft?

Answer 2

You 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.

Answer 3

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! :-)

Sources: Stack Exchange - This article follows the attribution requirements of Stack Exchange and is licensed under CC BY-SA 3.0.

Images: Karolina Grabowska, Karolina Grabowska, Karolina Grabowska, Karolina Grabowska