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

import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.levelgen.structure.templatesystem.BlockRotProcessor;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.levelgen.Heightmap;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessor;
import net.minecraft.world.level.levelgen.structure.templatesystem.BlockIgnoreProcessor;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.Rotation;
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.resources.ResourceLocation;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;

public class FossilFeature extends Feature<NoneFeatureConfiguration> {
    private static final ResourceLocation SPINE_1;
    private static final ResourceLocation SPINE_2;
    private static final ResourceLocation SPINE_3;
    private static final ResourceLocation SPINE_4;
    private static final ResourceLocation SPINE_1_COAL;
    private static final ResourceLocation SPINE_2_COAL;
    private static final ResourceLocation SPINE_3_COAL;
    private static final ResourceLocation SPINE_4_COAL;
    private static final ResourceLocation SKULL_1;
    private static final ResourceLocation SKULL_2;
    private static final ResourceLocation SKULL_3;
    private static final ResourceLocation SKULL_4;
    private static final ResourceLocation SKULL_1_COAL;
    private static final ResourceLocation SKULL_2_COAL;
    private static final ResourceLocation SKULL_3_COAL;
    private static final ResourceLocation SKULL_4_COAL;
    private static final ResourceLocation[] fossils;
    private static final ResourceLocation[] fossilsCoal;
    
    public FossilFeature(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 Rotation cap8 = Rotation.getRandom(random);
        final int integer9 = random.nextInt(FossilFeature.fossils.length);
        final StructureManager cva10 = ((ServerLevel)bqu.getLevel()).getServer().getStructureManager();
        final StructureTemplate cve11 = cva10.getOrCreate(FossilFeature.fossils[integer9]);
        final StructureTemplate cve12 = cva10.getOrCreate(FossilFeature.fossilsCoal[integer9]);
        final ChunkPos bph13 = new ChunkPos(fu);
        final BoundingBox ctd14 = new BoundingBox(bph13.getMinBlockX(), 0, bph13.getMinBlockZ(), bph13.getMaxBlockX(), 256, bph13.getMaxBlockZ());
        final StructurePlaceSettings cvb15 = new StructurePlaceSettings().setRotation(cap8).setBoundingBox(ctd14).setRandom(random).addProcessor(BlockIgnoreProcessor.STRUCTURE_AND_AIR);
        final BlockPos fu2 = cve11.getSize(cap8);
        final int integer10 = random.nextInt(16 - fu2.getX());
        final int integer11 = random.nextInt(16 - fu2.getZ());
        int integer12 = 256;
        for (int integer13 = 0; integer13 < fu2.getX(); ++integer13) {
            for (int integer14 = 0; integer14 < fu2.getZ(); ++integer14) {
                integer12 = Math.min(integer12, bqu.getHeight(Heightmap.Types.OCEAN_FLOOR_WG, fu.getX() + integer13 + integer10, fu.getZ() + integer14 + integer11));
            }
        }
        int integer13 = Math.max(integer12 - 15 - random.nextInt(10), 10);
        final BlockPos fu3 = cve11.getZeroPositionWithTransform(fu.offset(integer10, integer13, integer11), Mirror.NONE, cap8);
        final BlockRotProcessor cuk22 = new BlockRotProcessor(0.9f);
        cvb15.clearProcessors().addProcessor(cuk22);
        cve11.placeInWorld(bqu, fu3, fu3, cvb15, random, 4);
        cvb15.popProcessor(cuk22);
        final BlockRotProcessor cuk23 = new BlockRotProcessor(0.1f);
        cvb15.clearProcessors().addProcessor(cuk23);
        cve12.placeInWorld(bqu, fu3, fu3, cvb15, random, 4);
        return true;
    }
    
    static {
        SPINE_1 = new ResourceLocation("fossil/spine_1");
        SPINE_2 = new ResourceLocation("fossil/spine_2");
        SPINE_3 = new ResourceLocation("fossil/spine_3");
        SPINE_4 = new ResourceLocation("fossil/spine_4");
        SPINE_1_COAL = new ResourceLocation("fossil/spine_1_coal");
        SPINE_2_COAL = new ResourceLocation("fossil/spine_2_coal");
        SPINE_3_COAL = new ResourceLocation("fossil/spine_3_coal");
        SPINE_4_COAL = new ResourceLocation("fossil/spine_4_coal");
        SKULL_1 = new ResourceLocation("fossil/skull_1");
        SKULL_2 = new ResourceLocation("fossil/skull_2");
        SKULL_3 = new ResourceLocation("fossil/skull_3");
        SKULL_4 = new ResourceLocation("fossil/skull_4");
        SKULL_1_COAL = new ResourceLocation("fossil/skull_1_coal");
        SKULL_2_COAL = new ResourceLocation("fossil/skull_2_coal");
        SKULL_3_COAL = new ResourceLocation("fossil/skull_3_coal");
        SKULL_4_COAL = new ResourceLocation("fossil/skull_4_coal");
        fossils = new ResourceLocation[] { FossilFeature.SPINE_1, FossilFeature.SPINE_2, FossilFeature.SPINE_3, FossilFeature.SPINE_4, FossilFeature.SKULL_1, FossilFeature.SKULL_2, FossilFeature.SKULL_3, FossilFeature.SKULL_4 };
        fossilsCoal = new ResourceLocation[] { FossilFeature.SPINE_1_COAL, FossilFeature.SPINE_2_COAL, FossilFeature.SPINE_3_COAL, FossilFeature.SPINE_4_COAL, FossilFeature.SKULL_1_COAL, FossilFeature.SKULL_2_COAL, FossilFeature.SKULL_3_COAL, FossilFeature.SKULL_4_COAL };
    }
}
