In each chunk, the InhabitedTime variable is supposed to be equal to the length of time a player has been present in that location. This is used to calculate local difficulty.
I have found chunks within 3 chunks of the player being set to impossible high values after the player has loaded the game. It is also possible that this occurs at other times, such as entering a dimension.
Example of impossible values: Chunk at 21,26 has InhabitedTime equal to 1033258413. Time (world age) from level.dat is 1032934308. This implies that the chunk is older than the world which is impossible. A neighbouring chunk at 20,26 that is unaffected has InhabitedTime equal to 387484.
Steps to reproduce:
Use an old world, such as one with several hours of play time or longer. This allows the issue to be demonstrated easily. A world that is over 50 hours is best because that is when local difficulty is maximised. These steps assume a world over 50 hours old is used.
Make sure the world is set to Hard difficulty. (Easy or Normal can also work but the local difficulty values will be different.)
Configure the debug screen to show local difficulty and coordinates.
Go to a location that has fairly new chunks. Teleporting is good for this.
Record the local difficulty and coordinates (including chunk coordinates). → Local difficulty will have a value between 3 and 4 (fresh chunks).
Save the game.
Use an external NBT tool such as NBTExplorer to inspect the chunk where the player saved the game. Take note of InhabitedTime. → It will have a low value.
Reload the world.
Record the local difficulty → Local difficulty will have a value between 6.00 and 6.75 (maximised).
Quit.
Use an external NBT tool such as NBTExplorer to inspect the chunk where the player saved the game. Take note of InhabitedTime. → It will have a high value.
I can confirm that this has happened multiple times; this would result in me having to manually fix these chunks with an NBTEditor and manual copy/paste from a previous backup.
This started when I noticed a lot of bad areas the first time I backed up my server world file and did some fixes in singleplayer; my base had many chunks at 20+mil InhabitedTime and one of my islands in particular were completely caked in these. I’d fix them (It would take like 30 minutes of my time be it manual so it was not fun) and I don’t worry about it. This was around late October.
Today I noticed when I had to do some repairs on my base (multiple areas were off by 1 block) that it would do these areas in a smaller square around the player. I have a copy of my world file when I was just at the beginning of fixing my base; I see one rectangle of 20mil+ InhabitedTime. Then I have a copy of the finished process with the fixes and I see multiple of these uber high InhabitedTime rectangles; one for each time I reloaded the world file it seemed. Some chunks had InhabitedTime so high that it causes an integer underflow (at 2147483647 the 32 bit limit) and rolls down to negative InhabitedTime. This could cause unintended behaviour through Local Difficulty if there is negative InhabitedTime chunks being used for calculation (though I haven’t tested this; it’s still bad).
I’m not sure if mods have had this fixed (be it intentional or not) but this does NOT happen in multiplayer servers as the server only loads once and the concept of spawn chunks no longer exist which probably confirms that nothing simulates when the server is just starting up at the general spawn area.
Given the fact that chunks InhabitedTime experience an integer overflow given enough reloads, I think this can be a serious issue down the line. I could test this more on my end later but I believe enough information is gathered at this point outside of examining the code itself.