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

import java.util.Iterator;
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.datafixers.Dynamic;
import java.util.function.Function;

public class CoralClawFeature extends CoralFeature {
    public CoralClawFeature(final Function<Dynamic<?>, ? extends NoneFeatureConfiguration> function) {
        super(function);
    }
    
    @Override
    protected boolean placeFeature(final LevelAccessor bjx, final Random random, final BlockPos fk, final BlockState byj) {
        if (!this.placeCoralBlock(bjx, random, fk, byj)) {
            return false;
        }
        final Direction fp6 = Direction.Plane.HORIZONTAL.getRandomDirection(random);
        final int integer7 = random.nextInt(2) + 2;
        final List<Direction> list8 = Lists.<Direction>newArrayList(fp6, fp6.getClockWise(), fp6.getCounterClockWise());
        Collections.shuffle(list8, random);
        final List<Direction> list9 = list8.subList(0, integer7);
        for (final Direction fp7 : list9) {
            final BlockPos.MutableBlockPos a12 = new BlockPos.MutableBlockPos(fk);
            final int integer8 = random.nextInt(2) + 1;
            a12.move(fp7);
            Direction fp8;
            int integer9;
            if (fp7 == fp6) {
                fp8 = fp6;
                integer9 = random.nextInt(3) + 2;
            }
            else {
                a12.move(Direction.UP);
                final Direction[] arr16 = { fp7, Direction.UP };
                fp8 = arr16[random.nextInt(arr16.length)];
                integer9 = random.nextInt(3) + 3;
            }
            for (int integer10 = 0; integer10 < integer8 && this.placeCoralBlock(bjx, random, a12, byj); ++integer10) {
                a12.move(fp8);
            }
            a12.move(fp8.getOpposite());
            a12.move(Direction.UP);
            for (int integer10 = 0; integer10 < integer9; ++integer10) {
                a12.move(fp6);
                if (!this.placeCoralBlock(bjx, random, a12, byj)) {
                    break;
                }
                if (random.nextFloat() < 0.25f) {
                    a12.move(Direction.UP);
                }
            }
        }
        return true;
    }
}
