package net.minecraft.world.level.block.grower;

import java.util.Iterator;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.levelgen.ChunkGeneratorSettings;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.LevelAccessor;
import javax.annotation.Nullable;
import net.minecraft.world.level.levelgen.feature.configurations.SmallTreeConfiguration;
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
import java.util.Random;

public abstract class AbstractTreeGrower {
    @Nullable
    protected abstract ConfiguredFeature<SmallTreeConfiguration, ?> getConfiguredFeature(final Random random, final boolean boolean2);
    
    public boolean growTree(final LevelAccessor bjx, final ChunkGenerator<?> caa, final BlockPos fk, final BlockState byj, final Random random) {
        final ConfiguredFeature<SmallTreeConfiguration, ?> cdc7 = this.getConfiguredFeature(random, this.hasFlowers(bjx, fk));
        if (cdc7 == null) {
            return false;
        }
        bjx.setBlock(fk, Blocks.AIR.defaultBlockState(), 4);
        cdc7.config.setFromSapling();
        if (cdc7.place(bjx, caa, random, fk)) {
            return true;
        }
        bjx.setBlock(fk, byj, 4);
        return false;
    }
    
    private boolean hasFlowers(final LevelAccessor bjx, final BlockPos fk) {
        for (final BlockPos fk2 : BlockPos.betweenClosed(fk.below().north(2).west(2), fk.above().south(2).east(2))) {
            if (bjx.getBlockState(fk2).is(BlockTags.FLOWERS)) {
                return true;
            }
        }
        return false;
    }
}
