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

import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.LevelReader;
import net.minecraft.core.BlockPos;
import java.util.Random;
import net.minecraft.world.level.levelgen.ChunkGeneratorSettings;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.LevelAccessor;
import com.mojang.datafixers.Dynamic;
import java.util.function.Function;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;

public abstract class AbstractFlowerFeature<U extends FeatureConfiguration> extends Feature<U> {
    public AbstractFlowerFeature(final Function<Dynamic<?>, ? extends U> function) {
        super(function);
    }
    
    @Override
    public boolean place(final LevelAccessor bjx, final ChunkGenerator<? extends ChunkGeneratorSettings> caa, final Random random, final BlockPos fk, final U cgn) {
        final BlockState byj7 = this.getRandomFlower(random, fk, cgn);
        int integer8 = 0;
        for (int integer9 = 0; integer9 < this.getCount(cgn); ++integer9) {
            final BlockPos fk2 = this.getPos(random, fk, cgn);
            if (bjx.isEmptyBlock(fk2) && fk2.getY() < 255 && byj7.canSurvive(bjx, fk2) && this.isValid(bjx, fk2, cgn)) {
                bjx.setBlock(fk2, byj7, 2);
                ++integer8;
            }
        }
        return integer8 > 0;
    }
    
    public abstract boolean isValid(final LevelAccessor bjx, final BlockPos fk, final U cgn);
    
    public abstract int getCount(final U cgn);
    
    public abstract BlockPos getPos(final Random random, final BlockPos fk, final U cgn);
    
    public abstract BlockState getRandomFlower(final Random random, final BlockPos fk, final U cgn);
}
