Minecraft wiki entry for Spawn, associated text: Monsters cannot spawn when the difficulty is set to Peaceful (except piglin‌[BE only] and hoglin). At any higher setting they spawn at light level 0. The player cannot sleep when a monster (other than hoglin; and in Java Edition, also include slime, magma cube and non-hostile zombified piglin) is nearby, even if the monster has no path to the player.