use of net.tropicraft.core.common.dimension.feature.config.RainforestVinesConfig in project Tropicraft by Tropicraft.
the class RainforestVinesFeature method place.
@Override
public boolean place(FeaturePlaceContext<RainforestVinesConfig> context) {
WorldGenLevel world = context.level();
Random rand = context.random();
BlockPos pos = context.origin();
RainforestVinesConfig config = context.config();
BlockPos.MutableBlockPos mutablePos = pos.mutable();
int maxY = Math.min(pos.getY() + config.height, world.getHeight());
for (int y = pos.getY(); y < maxY; ++y) {
for (int i = 0; i < config.rollsPerY; i++) {
mutablePos.set(pos);
mutablePos.move(rand.nextInt(config.xzSpread * 2) - config.xzSpread, 0, rand.nextInt(config.xzSpread * 2) - config.xzSpread);
mutablePos.setY(y);
if (world.isEmptyBlock(mutablePos)) {
for (Direction direction : DIRECTIONS) {
mutablePos.move(direction);
BlockState attaching = world.getBlockState(mutablePos);
if ((attaching.getBlock() == Blocks.GRASS_BLOCK && rand.nextInt(4) == 0) || attaching.is(BlockTags.LEAVES)) {
if (direction != Direction.DOWN && VineBlock.isAcceptableNeighbour(world, mutablePos, direction)) {
mutablePos.move(direction.getOpposite());
int len = rand.nextInt(3) + 2;
for (int j = 0; j < len && world.isEmptyBlock(mutablePos); j++) {
world.setBlock(mutablePos, Blocks.VINE.defaultBlockState().setValue(VineBlock.getPropertyForFace(direction), true), Block.UPDATE_CLIENTS);
mutablePos.move(Direction.DOWN);
}
break;
}
}
}
}
}
}
return true;
}
Aggregations