Search in sources :

Example 1 with TreeFeatureConfig

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;
                }
            }
        }
}
Also used : FoliagePlacer(net.minecraft.world.gen.foliage.FoliagePlacer) ModifiableTestableWorld(net.minecraft.world.ModifiableTestableWorld) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Random(java.util.Random) FoliagePlacerType(net.minecraft.world.gen.foliage.FoliagePlacerType) Blocks(net.minecraft.block.Blocks) Direction(net.minecraft.util.math.Direction) Properties(net.minecraft.state.property.Properties) Products(com.mojang.datafixers.Products) Codec(com.mojang.serialization.Codec) BlockBox(net.minecraft.util.math.BlockBox) TreeFeatureConfig(net.minecraft.world.gen.feature.TreeFeatureConfig) BMBlocks(party.lemons.biomemakeover.init.BMBlocks) RandomUtil(party.lemons.biomemakeover.util.RandomUtil) TreeFeature(net.minecraft.world.gen.feature.TreeFeature) BMWorldGen(party.lemons.biomemakeover.init.BMWorldGen) RecordCodecBuilder(com.mojang.serialization.codecs.RecordCodecBuilder) BlockTags(net.minecraft.tag.BlockTags) WillowingBranchesBlock(party.lemons.biomemakeover.block.WillowingBranchesBlock) UniformIntDistribution(net.minecraft.world.gen.UniformIntDistribution) BlockBox(net.minecraft.util.math.BlockBox) BlockPos(net.minecraft.util.math.BlockPos)

Aggregations

Products (com.mojang.datafixers.Products)1 Codec (com.mojang.serialization.Codec)1 RecordCodecBuilder (com.mojang.serialization.codecs.RecordCodecBuilder)1 Random (java.util.Random)1 Set (java.util.Set)1 Blocks (net.minecraft.block.Blocks)1 Properties (net.minecraft.state.property.Properties)1 BlockTags (net.minecraft.tag.BlockTags)1 BlockBox (net.minecraft.util.math.BlockBox)1 BlockPos (net.minecraft.util.math.BlockPos)1 Direction (net.minecraft.util.math.Direction)1 ModifiableTestableWorld (net.minecraft.world.ModifiableTestableWorld)1 UniformIntDistribution (net.minecraft.world.gen.UniformIntDistribution)1 TreeFeature (net.minecraft.world.gen.feature.TreeFeature)1 TreeFeatureConfig (net.minecraft.world.gen.feature.TreeFeatureConfig)1 FoliagePlacer (net.minecraft.world.gen.foliage.FoliagePlacer)1 FoliagePlacerType (net.minecraft.world.gen.foliage.FoliagePlacerType)1 WillowingBranchesBlock (party.lemons.biomemakeover.block.WillowingBranchesBlock)1 BMBlocks (party.lemons.biomemakeover.init.BMBlocks)1 BMWorldGen (party.lemons.biomemakeover.init.BMWorldGen)1