public interface Populator
A populator has access to some nearby chunks, so it can more easily place objects that cross chunk boundaries.
Instead of directly implementing this interface, it may be easier to
implement PopulatorObject
instead, and use the
PopulatorObjects
class to get a populator that spawns that
object.
PopulatorObjects
,
PopulatorObject
Modifier and Type | Method and Description |
---|---|
void |
populate(Chunk chunk,
Random random)
Applies the populator to the given chunk.
|
void populate(Chunk chunk, Random random)
(chunkX + 1, chunkZ)
, (chunkX, chunkZ + 1)
and
(chunkX + 1, chunkZ + 1)
will at least have been generated
(although they do not have to be populated) to allow
PopulatorObject
s to overlap across chunk boundaries.
This means that there are only four chunks guaranteed to be loaded. Other chunks in the world may or may not be loaded. Avoid touching those chunks, trying to get/set a block there may cause the chunk to be loaded, which is a bad thing during terrain population.
Those four chunks form an area of 32x32 columns that you can populate,
from (block x, block z) (chunkX * 16, chunkZ * 16)
to
(chunkX * 16 + 31, chunkZ * 16 + 31)
. See Figure 1. To
effectively use this area, it is recommend to make sure the centers of
all objects are placed from
(block x, block z) (chunkX * 16 + 8, chunkZ * 16 + 8)
to
(chunkX * 16 + 23, chunkZ * 16 + 23)
. This ensures both that
each object can extend 8 blocks on the x and z axis from its center and
that every area in the world is populated exactly once.
+----------+----------+ . . The chunk provided as a parameter | | | . . to this method. | | | | #####|##### | ### The area you should populate. | #####|##### | ### +----------+----------+ | . . #####|##### | | . . #####|##### | | . . . . .| | | . . . . .| | +----------+----------+
Figure 1 The four chunks guanteed to be loaded, along with the area you are allowed to populate.
The following code guantantees that the center of your object is placed with its center in the recommend area:
Vector3i
chunkStartBlockPos = chunk.getPosition().mul(16);
Vector3i populationAreaStartBlockPos = chunkStartBlockPos.add(8, 0, 8);
Vector3i objectCenterBlockPos = populationAreaStart.add(
random.nextInt(16), justSomeValueForY, random.nextInt(16));
chunk
- The provided chunk.random
- A random number generator. This random number generator is
based on the world seed and the chunk position. It is shared with
with other populators.