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

import java.util.Iterator;
import net.minecraft.Util;
import java.util.List;
import java.util.Collections;
import com.google.common.collect.Lists;
import net.minecraft.core.Direction;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import java.util.Random;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import com.mojang.serialization.Codec;

public class CoralClawFeature extends CoralFeature {
    public CoralClawFeature(final Codec<NoneFeatureConfiguration> codec) {
        super(codec);
    }
    
    @Override
    protected boolean placeFeature(final LevelAccessor bqc, final Random random, final BlockPos fu, final BlockState cfj) {
        if (!this.placeCoralBlock(bqc, random, fu, cfj)) {
            return false;
        }
        final Direction fz6 = Direction.Plane.HORIZONTAL.getRandomDirection(random);
        final int integer7 = random.nextInt(2) + 2;
        final List<Direction> list8 = Lists.<Direction>newArrayList(fz6, fz6.getClockWise(), fz6.getCounterClockWise());
        Collections.shuffle(list8, random);
        final List<Direction> list9 = list8.subList(0, integer7);
        for (final Direction fz7 : list9) {
            final BlockPos.MutableBlockPos a12 = fu.mutable();
            final int integer8 = random.nextInt(2) + 1;
            a12.move(fz7);
            Direction fz8;
            int integer9;
            if (fz7 == fz6) {
                fz8 = fz6;
                integer9 = random.nextInt(3) + 2;
            }
            else {
                a12.move(Direction.UP);
                final Direction[] arr16 = { fz7, Direction.UP };
                fz8 = Util.<Direction>getRandom(arr16, random);
                integer9 = random.nextInt(3) + 3;
            }
            for (int integer10 = 0; integer10 < integer8 && this.placeCoralBlock(bqc, random, a12, cfj); ++integer10) {
                a12.move(fz8);
            }
            a12.move(fz8.getOpposite());
            a12.move(Direction.UP);
            for (int integer10 = 0; integer10 < integer9; ++integer10) {
                a12.move(fz6);
                if (!this.placeCoralBlock(bqc, random, a12, cfj)) {
                    break;
                }
                if (random.nextFloat() < 0.25f) {
                    a12.move(Direction.UP);
                }
            }
        }
        return true;
    }
}
