That was fast, thank you Pokechu!!
Somehow I got confused while writing my "guess" and mixed block/chunk/coords around myself. 😃 (Well, it was late at night... 😉 )
So maybe my fault you got confused too. 😃
getChunkFromChunkCoords(position.getX() >> 4, position.getZ() >> 4) should be the right way because shifting left would make it worse 😃. Also -15 / 16 gives 0 instead of -1 which is returned by -15 >> 4, so right shift should be the only way when using block position integers. (Doesn't matter as long as block coords always are x0 z0 of chunk though. But it's cleaner to do so in my eyes.)
Interesting, it also appears in deserts? Sorry for the partly wrong info if so. I probably didn't test enough after finding bunches in swamps and nothing in surrounding forest / plains / hills...
I wonder why this bug is so unpopular as a lot of people should have noticed those big-numbers region files suddenly appearing. It's pretty messy and gives me trouble with a Bukkit plugin I'm developing right now.
So what I found out is: This only happens in swamp biomes! While the chunks for the swamp are generated, some of them trigger a chunk to be generated with current block-coordinates as chunk-coordinates. Or in other words if a swamp chunk at x5 z7 is generated, x80 z112 possibly generates as well (5 << 4 and 7 << 4). My guess is that someone took the chunk coordinates as block coordinates and shifted or multiplied them to get the chunk coordinates which already were present. (That's the factor 16 or 16 * 16 = 256 already mentioned.)
This bug can easily be reproduced. The affected chunks are always the same with same seeds.
Just create a normal world with seed 9 and go to block location ~ x500 z450. The following chunks will be generated:
(normal + "stray")
x32 z26 + x512 z416
x32 z27 + x512 z432
x34 z27 + x544 z432
x33 z31 + x528 z496
x34 z31 + x544 z496
The block locations of the "stray" chunks are somewhere around ~ x8448 z7296. That's pretty far away. Not to mention that if you go there and trigger new stray chunks in a swamp around ... the new strays will be extremely far away.
It's not the same. Everything from 15 to -15 / 16 is 0. So we hava a 31x31 Chunk at 0/0? Of course not, chunks are always 16x16.
Also -17 to -31 has to be -2 and not -1 and so on.
>> 4 will simply do the trick of flooring an int instead of just omit decimal.
And by the way, because it's not the same it also can't be a compiler optimization.
Just try
System.out.println(Integer.toString(-8 / 16));
System.out.println(Integer.toString(-8 >> 4));
and you'll see.