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

import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.block.state.BlockState;
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.SpringConfiguration;

public class SpringFeature extends Feature<SpringConfiguration> {
    public SpringFeature(final Codec<SpringConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final SpringConfiguration cor) {
        if (!cor.validBlocks.contains(bqu.getBlockState(fu.above()).getBlock())) {
            return false;
        }
        if (cor.requiresBlockBelow && !cor.validBlocks.contains(bqu.getBlockState(fu.below()).getBlock())) {
            return false;
        }
        final BlockState cfj8 = bqu.getBlockState(fu);
        if (!cfj8.isAir() && !cor.validBlocks.contains(cfj8.getBlock())) {
            return false;
        }
        int integer9 = 0;
        int integer10 = 0;
        if (cor.validBlocks.contains(bqu.getBlockState(fu.west()).getBlock())) {
            ++integer10;
        }
        if (cor.validBlocks.contains(bqu.getBlockState(fu.east()).getBlock())) {
            ++integer10;
        }
        if (cor.validBlocks.contains(bqu.getBlockState(fu.north()).getBlock())) {
            ++integer10;
        }
        if (cor.validBlocks.contains(bqu.getBlockState(fu.south()).getBlock())) {
            ++integer10;
        }
        if (cor.validBlocks.contains(bqu.getBlockState(fu.below()).getBlock())) {
            ++integer10;
        }
        int integer11 = 0;
        if (bqu.isEmptyBlock(fu.west())) {
            ++integer11;
        }
        if (bqu.isEmptyBlock(fu.east())) {
            ++integer11;
        }
        if (bqu.isEmptyBlock(fu.north())) {
            ++integer11;
        }
        if (bqu.isEmptyBlock(fu.south())) {
            ++integer11;
        }
        if (bqu.isEmptyBlock(fu.below())) {
            ++integer11;
        }
        if (integer10 == cor.rockCount && integer11 == cor.holeCount) {
            bqu.setBlock(fu, cor.state.createLegacyBlock(), 2);
            bqu.getLiquidTicks().scheduleTick(fu, cor.state.getType(), 0);
            ++integer9;
        }
        return integer9 > 0;
    }
}
