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.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.SpringConfiguration;

public class SpringFeature extends Feature<SpringConfiguration> {
    public SpringFeature(final Function<Dynamic<?>, ? extends SpringConfiguration> function) {
        super(function);
    }
    
    @Override
    public boolean place(final LevelAccessor bjx, final ChunkGenerator<? extends ChunkGeneratorSettings> caa, final Random random, final BlockPos fk, final SpringConfiguration chk) {
        if (!chk.validBlocks.contains(bjx.getBlockState(fk.above()).getBlock())) {
            return false;
        }
        if (chk.requiresBlockBelow && !chk.validBlocks.contains(bjx.getBlockState(fk.below()).getBlock())) {
            return false;
        }
        final BlockState byj7 = bjx.getBlockState(fk);
        if (!byj7.isAir() && !chk.validBlocks.contains(byj7.getBlock())) {
            return false;
        }
        int integer8 = 0;
        int integer9 = 0;
        if (chk.validBlocks.contains(bjx.getBlockState(fk.west()).getBlock())) {
            ++integer9;
        }
        if (chk.validBlocks.contains(bjx.getBlockState(fk.east()).getBlock())) {
            ++integer9;
        }
        if (chk.validBlocks.contains(bjx.getBlockState(fk.north()).getBlock())) {
            ++integer9;
        }
        if (chk.validBlocks.contains(bjx.getBlockState(fk.south()).getBlock())) {
            ++integer9;
        }
        if (chk.validBlocks.contains(bjx.getBlockState(fk.below()).getBlock())) {
            ++integer9;
        }
        int integer10 = 0;
        if (bjx.isEmptyBlock(fk.west())) {
            ++integer10;
        }
        if (bjx.isEmptyBlock(fk.east())) {
            ++integer10;
        }
        if (bjx.isEmptyBlock(fk.north())) {
            ++integer10;
        }
        if (bjx.isEmptyBlock(fk.south())) {
            ++integer10;
        }
        if (bjx.isEmptyBlock(fk.below())) {
            ++integer10;
        }
        if (integer9 == chk.rockCount && integer10 == chk.holeCount) {
            bjx.setBlock(fk, chk.state.createLegacyBlock(), 2);
            bjx.getLiquidTicks().scheduleTick(fk, chk.state.getType(), 0);
            ++integer8;
        }
        return integer8 > 0;
    }
}
