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

import net.minecraft.world.level.block.state.StateHolder;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import java.util.Iterator;
import net.minecraft.world.level.block.BaseCoralWallFanBlock;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.SeaPickleBlock;
import net.minecraft.tags.Tag;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.tags.BlockTags;
import net.minecraft.world.level.block.Block;
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.NoneFeatureConfiguration;

public abstract class CoralFeature extends Feature<NoneFeatureConfiguration> {
    public CoralFeature(final Codec<NoneFeatureConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public boolean place(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BlockPos fu, final NoneFeatureConfiguration coa) {
        final BlockState cfj8 = BlockTags.CORAL_BLOCKS.getRandomElement(random).defaultBlockState();
        return this.placeFeature(bqu, random, fu, cfj8);
    }
    
    protected abstract boolean placeFeature(final LevelAccessor bqc, final Random random, final BlockPos fu, final BlockState cfj);
    
    protected boolean placeCoralBlock(final LevelAccessor bqc, final Random random, final BlockPos fu, final BlockState cfj) {
        final BlockPos fu2 = fu.above();
        final BlockState cfj2 = bqc.getBlockState(fu);
        if ((!cfj2.is(Blocks.WATER) && !cfj2.is(BlockTags.CORALS)) || !bqc.getBlockState(fu2).is(Blocks.WATER)) {
            return false;
        }
        bqc.setBlock(fu, cfj, 3);
        if (random.nextFloat() < 0.25f) {
            bqc.setBlock(fu2, BlockTags.CORALS.getRandomElement(random).defaultBlockState(), 2);
        }
        else if (random.nextFloat() < 0.05f) {
            bqc.setBlock(fu2, ((StateHolder<O, BlockState>)Blocks.SEA_PICKLE.defaultBlockState()).<Comparable, Integer>setValue((Property<Comparable>)SeaPickleBlock.PICKLES, random.nextInt(4) + 1), 2);
        }
        for (final Direction fz9 : Direction.Plane.HORIZONTAL) {
            if (random.nextFloat() < 0.2f) {
                final BlockPos fu3 = fu.relative(fz9);
                if (!bqc.getBlockState(fu3).is(Blocks.WATER)) {
                    continue;
                }
                final BlockState cfj3 = ((StateHolder<O, BlockState>)BlockTags.WALL_CORALS.getRandomElement(random).defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)BaseCoralWallFanBlock.FACING, fz9);
                bqc.setBlock(fu3, cfj3, 2);
            }
        }
        return true;
    }
}
