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

import net.minecraft.world.level.block.state.AbstractStateHolder;
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.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
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.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.NoneFeatureConfiguration;

public abstract class CoralFeature extends Feature<NoneFeatureConfiguration> {
    public CoralFeature(final Function<Dynamic<?>, ? extends NoneFeatureConfiguration> function) {
        super(function);
    }
    
    @Override
    public boolean place(final LevelAccessor bjx, final ChunkGenerator<? extends ChunkGeneratorSettings> caa, final Random random, final BlockPos fk, final NoneFeatureConfiguration cgv) {
        final BlockState byj7 = BlockTags.CORAL_BLOCKS.getRandomElement(random).defaultBlockState();
        return this.placeFeature(bjx, random, fk, byj7);
    }
    
    protected abstract boolean placeFeature(final LevelAccessor bjx, final Random random, final BlockPos fk, final BlockState byj);
    
    protected boolean placeCoralBlock(final LevelAccessor bjx, final Random random, final BlockPos fk, final BlockState byj) {
        final BlockPos fk2 = fk.above();
        final BlockState byj2 = bjx.getBlockState(fk);
        if ((byj2.getBlock() != Blocks.WATER && !byj2.is(BlockTags.CORALS)) || bjx.getBlockState(fk2).getBlock() != Blocks.WATER) {
            return false;
        }
        bjx.setBlock(fk, byj, 3);
        if (random.nextFloat() < 0.25f) {
            bjx.setBlock(fk2, BlockTags.CORALS.getRandomElement(random).defaultBlockState(), 2);
        }
        else if (random.nextFloat() < 0.05f) {
            bjx.setBlock(fk2, ((AbstractStateHolder<O, BlockState>)Blocks.SEA_PICKLE.defaultBlockState()).<Comparable, Integer>setValue((Property<Comparable>)SeaPickleBlock.PICKLES, random.nextInt(4) + 1), 2);
        }
        for (final Direction fp9 : Direction.Plane.HORIZONTAL) {
            if (random.nextFloat() < 0.2f) {
                final BlockPos fk3 = fk.relative(fp9);
                if (bjx.getBlockState(fk3).getBlock() != Blocks.WATER) {
                    continue;
                }
                final BlockState byj3 = ((AbstractStateHolder<O, BlockState>)BlockTags.WALL_CORALS.getRandomElement(random).defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)BaseCoralWallFanBlock.FACING, fp9);
                bjx.setBlock(fk3, byj3, 2);
            }
        }
        return true;
    }
}
