package net.minecraft.world.level.levelgen.feature;

import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.LevelReader;
import net.minecraft.core.BlockPos;
import java.util.Random;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import com.mojang.serialization.Codec;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;

public abstract class AbstractFlowerFeature<U extends FeatureConfiguration> extends Feature<U> {
    public AbstractFlowerFeature(final Codec<U> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final U cnr) {
        final BlockState cfj8 = this.getRandomFlower(random, fu, cnr);
        int integer9 = 0;
        for (int integer10 = 0; integer10 < this.getCount(cnr); ++integer10) {
            final BlockPos fu2 = this.getPos(random, fu, cnr);
            if (bqu.isEmptyBlock(fu2) && fu2.getY() < 255 && cfj8.canSurvive(bqu, fu2) && this.isValid(bqu, fu2, cnr)) {
                bqu.setBlock(fu2, cfj8, 2);
                ++integer9;
            }
        }
        return integer9 > 0;
    }
    
    public abstract boolean isValid(final LevelAccessor bqc, final BlockPos fu, final U cnr);
    
    public abstract int getCount(final U cnr);
    
    public abstract BlockPos getPos(final Random random, final BlockPos fu, final U cnr);
    
    public abstract BlockState getRandomFlower(final Random random, final BlockPos fu, final U cnr);
}
