OLEGSHA / Progressia

A GPL sandbox survival game
GNU General Public License v3.0
10 stars 4 forks source link

World generation features are bounded by loaded chunks #19

Open OLEGSHA opened 2 years ago

OLEGSHA commented 2 years ago

When a worldgen feature is generated, only a 3x3x3 cube of chunks is guaranteed to be loaded. While this is enough for most features, some structures, mostly trees at this point, may need to exceed the inherent 16-block size limit.

Currently attempts to place blocks outside the 3x3x3 cube sometimes result in a crash because the chunk isn't loaded. This is correct behaviour for most circumstances but not for worldgen features. Instead, access to unloaded or not generated chunks should result in chunkloading. The chunk should be loaded as if it were part of the 3x3x3 cube: if it doesn't exist, generate terrain only.

To test the fix, set pine tree (TestTreeFeature) height to something like 40:

//int height = (int) stretch(size, 8, 12);
int height = (int) stretch(size, 40, 40);

This should work properly.

N.B.: A similar issue exists in Minecraft (see here for example). In MC, world population (analogous to feature generation) is triggered by terrain generation directly, so there is no fix for MC. In Progressia, features are triggered separately and so this shouldn't lead to problems.