Hostile mobs will spawn in and around your builds if there is not a high enough light level or if it is night time. Mobs such as creepers have the potential to destroy your creations while others may attack you. There are many ways of preventing hostile creatures from spawning.
- Light blocks
- One of the most basic ways to prevent mob spawning is by placing torches. These will 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.
- Mobs cannot spawn on blocks that are less than a full block in height. Areas covered in slabs will be unable to spawn mobs, no matter the light level. The same rules apply to transparent blocks such as glass.:Carpet
- Mobs cannot spawn if you place carpet.
- Pressure Plate
- Mobs cannot spawn where there are pressure plates.
- Mob switches
- In the Java Edition, there is a mob cap in every world, meaning there can only be a certain amount of mobs within a 289 chunk range of the spawn chunks. The cap for hostiles is 70, which can be changed using commands. That means if you pack 70 mobs into minecarts and send them in and out of the spawn chunks, you can stop all mob spawning within this area. This is what's known as a mob switch. Contraptions like these require a lot of time and effort. You can find many tutorials on this on YouTube.