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

import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.BlockGetter;
import java.util.Random;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.core.Direction;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.biome.Biome;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.chunk.ChunkGenerator;
import com.mojang.serialization.Codec;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;
import net.minecraft.world.level.levelgen.feature.StructureFeature;

public class NetherFossilFeature extends StructureFeature<NoneFeatureConfiguration> {
    public NetherFossilFeature(final Codec<NoneFeatureConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
        return FeatureStart::new;
    }
    
    public static class FeatureStart extends BeardedStructureStart<NoneFeatureConfiguration> {
        public FeatureStart(final StructureFeature<NoneFeatureConfiguration> cml, final int integer2, final int integer3, final BoundingBox ctd, final int integer5, final long long6) {
            super(cml, integer2, integer3, ctd, integer5, long6);
        }
        
        @Override
        public void generatePieces(final ChunkGenerator cha, final StructureManager cva, final int integer3, final int integer4, final Biome bre, final NoneFeatureConfiguration coa) {
            final ChunkPos bph8 = new ChunkPos(integer3, integer4);
            final int integer5 = bph8.getMinBlockX() + this.random.nextInt(16);
            final int integer6 = bph8.getMinBlockZ() + this.random.nextInt(16);
            final int integer7 = cha.getSeaLevel();
            int integer8 = integer7 + this.random.nextInt(cha.getGenDepth() - 2 - integer7);
            final BlockGetter bpg13 = cha.getBaseColumn(integer5, integer6);
            final BlockPos.MutableBlockPos a14 = new BlockPos.MutableBlockPos(integer5, integer8, integer6);
            while (integer8 > integer7) {
                final BlockState cfj15 = bpg13.getBlockState(a14);
                a14.move(Direction.DOWN);
                final BlockState cfj16 = bpg13.getBlockState(a14);
                if (cfj15.isAir()) {
                    if (cfj16.is(Blocks.SOUL_SAND)) {
                        break;
                    }
                    if (cfj16.isFaceSturdy(bpg13, a14, Direction.UP)) {
                        break;
                    }
                }
                --integer8;
            }
            if (integer8 <= integer7) {
                return;
            }
            NetherFossilPieces.addPieces(cva, this.pieces, this.random, new BlockPos(integer5, integer8, integer6));
            this.calculateBoundingBox();
        }
    }
}
