use of net.tropicraft.core.common.dimension.feature.config.FruitTreeConfig in project Tropicraft by Tropicraft.
the class FruitTreeFeature method place.
@Override
public boolean place(FeaturePlaceContext<FruitTreeConfig> context) {
WorldGenLevel world = context.level();
Random rand = context.random();
BlockPos pos = context.origin();
FruitTreeConfig config = context.config();
pos = pos.immutable();
int height = rand.nextInt(3) + 4;
if (goesBeyondWorldSize(world, pos.getY(), height)) {
return false;
}
if (!isBBAvailable(world, pos, height)) {
return false;
}
BlockState sapling = config.sapling;
if (!sapling.canSurvive(world, pos)) {
return false;
}
setDirtAt(world, pos.below());
for (int y = (pos.getY() - 3) + height; y <= pos.getY() + height; y++) {
int presizeMod = y - (pos.getY() + height);
int size = 1 - presizeMod / 2;
for (int x = pos.getX() - size; x <= pos.getX() + size; x++) {
int localX = x - pos.getX();
for (int z = pos.getZ() - size; z <= pos.getZ() + size; z++) {
int localZ = z - pos.getZ();
if ((Math.abs(localX) != size || Math.abs(localZ) != size || rand.nextInt(2) != 0 && presizeMod != 0) && TreeFeature.isAirOrLeaves(world, new BlockPos(x, y, z))) {
BlockPos leafPos = new BlockPos(x, y, z);
if (rand.nextBoolean()) {
// Set fruit-bearing leaves here
setBlock(world, leafPos, config.fruitLeaves);
} else {
// Set plain fruit tree leaves here
setBlock(world, leafPos, config.leaves);
}
}
}
}
}
// Tree stem
for (int y = 0; y < height; y++) {
BlockPos logPos = pos.above(y);
if (TreeFeature.validTreePos(world, logPos)) {
setBlock(world, logPos, config.wood);
}
}
return true;
}
Aggregations