use of net.minecraft.world.gen.feature.TreeFeatureConfig in project Biome-Makeover by Lemonszz.
the class WillowFoliagePlacer method generate.
protected void generate(ModifiableTestableWorld world, Random random, TreeFeatureConfig config, int trunkHeight, FoliagePlacer.TreeNode treeNode, int foliageHeight, int radius, Set<BlockPos> leaves, int offset, BlockBox box) {
for (int placeOffset = offset; placeOffset >= offset - foliageHeight; --placeOffset) {
int baseHeight;
if (treeNode.getFoliageRadius() > 0)
baseHeight = Math.max(radius + treeNode.getFoliageRadius() - 1 - placeOffset / 2, 0);
else
baseHeight = Math.max(radius + treeNode.getFoliageRadius() - placeOffset / 2, 0);
this.generateSquare(world, random, config, treeNode.getCenter(), baseHeight, leaves, placeOffset, treeNode.isGiantTrunk(), box);
}
BlockBox leafBox = BlockBox.empty();
for (BlockPos leafPos : leaves) {
leafBox.encompass(new BlockBox(leafPos, leafPos));
}
for (int i = 0; i < 4 + random.nextInt(8); i++) {
BlockPos.Mutable downPos = new BlockPos.Mutable(RandomUtil.randomRange(box.minX, box.maxX), leafBox.minY - 1, RandomUtil.randomRange(box.minZ, box.maxZ));
if (TreeFeature.canReplace(world, downPos) && world.testBlockState(downPos.up(), (state) -> state.isIn(BlockTags.LEAVES))) {
world.setBlockState(downPos, config.leavesProvider.getBlockState(random, downPos), 19);
box.encompass(new BlockBox(downPos, downPos));
leaves.add(downPos.toImmutable());
}
}
if (// TODO: this should be a tree decorator
doWillows)
for (int i = 0; i < 10; i++) {
BlockPos.Mutable pos = new BlockPos.Mutable(RandomUtil.randomRange(box.minX, box.maxX), leafBox.minY, RandomUtil.randomRange(box.minZ, box.maxZ));
for (int j = 0; j < 3; j++) {
if ((world.testBlockState(pos, (s) -> s.isAir()) || world.testBlockState(pos, (s) -> s == Blocks.WATER.getDefaultState())) && world.testBlockState(pos.up(), (s) -> s.isIn(BlockTags.LEAVES) || (s.isOf(BMBlocks.WILLOWING_BRANCHES) && s.get(WillowingBranchesBlock.STAGE) < 2))) {
boolean water = world.testBlockState(pos, (s) -> s == Blocks.WATER.getDefaultState());
if (water || world.testBlockState(pos, (s) -> s.isAir())) {
world.setBlockState(pos, BMBlocks.WILLOWING_BRANCHES.getDefaultState().with(WillowingBranchesBlock.STAGE, j).with(Properties.WATERLOGGED, water), 19);
pos.move(Direction.DOWN);
} else
break;
} else {
break;
}
}
}
}
Aggregations