Ok guys here is some (Pseudo) Minecraft Code for ya
The game saves something called 'Local Difficulty'
TLDR The longer you stay in a specific area, the more mobs spawn. You can view this in F3. IE when you first come to an area, not much will spawn. After more than 50 hours in one area, the difficulty will suddenly begin to rise quickly.
To quote the Minecraft Wiki:
The “inhabited time" of a chunk increases for each tick a player spends with the chunk loaded. This is a cumulative measure of time—if 50 players spend a single hour in a chunk, it counts the same as if one player spent 50 hours there. The effect of inhabited time on regional difficulty is capped at 50 hours.
Total play time in the world also contributes to regional difficulty. This effect doesn't begin until after the first hour of play time and is capped at 21 hours.
TotalTimeFactor, ChunkFactor, and RegionalDifficulty are floating-point variables
MoonPhase is as in the table above.
if ( TotalPlayTime > 21 hours )
TotalTimeFactor = 0.25
else if ( TotalPlayTime < 1 hour )
TotalTimeFactor = 0
else
TotalTimeFactor = ( TotalPlayTimeInTicks - 72,000 ) / 5,760,000
if ( ChunkInhabitedTime > 50 hours )
ChunkFactor = 1
else
ChunkFactor = ChunkInhabitedTimeInTicks / 3,600,000
if (difficulty is not Hard)
multiply ChunkFactor by 3/4
if ( MoonPhase / 4 > TotalTimeFactor )
add TotalTimeFactor to ChunkFactor
else
add MoonPhase / 4 to ChunkFactor
if ( difficulty is Easy )
divide ChunkFactor by 2
RegionalDifficulty = 0.75 + TotalTimeFactor + ChunkFactor
if (difficulty is Normal)
multiply RegionalDifficulty by 2
if (difficulty is Hard)
multiply RegionalDifficulty by 3
return RegionalDifficulty