public void populate(Chunk chunk, Random random) {
if (chunk.getY() != 4) {
return;
}
final World world = chunk.getWorld();
final SugarCaneStackObject canes = new SugarCaneStackObject();
canes.setRandom(random);
byte successfulClusterCount = 0;
for (byte count = 0; count < clusterPlaceAttempts; count++) {
final int x = chunk.getBlockX(random);
final int z = chunk.getBlockZ(random);
final int y = getHighestWorkableBlock(world, x, z);
if (y == -1 || !canes.canPlaceObject(world, x, y, z)) {
continue;
}
successfulClusterCount++;
canes.randomize();
canes.placeObject(world, x, y, z);
for (byte placed = 1; placed < maxClusterSize; placed++) {
final int xx = x - 3 + random.nextInt(7);
final int zz = z - 3 + random.nextInt(7);
canes.randomize();
if (canes.canPlaceObject(world, xx, y, zz)) {
canes.placeObject(world, xx, y, zz);
}
}
if (successfulClusterCount >= numberOfClusters) {
return;
}