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

import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.StructureFeatureManager;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureTemplate;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureProcessor;
import net.minecraft.world.level.levelgen.structure.templatesystem.BlockIgnoreProcessor;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructurePlaceSettings;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.levelgen.feature.StructurePieceType;
import net.minecraft.Util;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.core.BlockPos;
import java.util.Random;
import java.util.List;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.resources.ResourceLocation;

public class NetherFossilPieces {
    private static final ResourceLocation[] FOSSILS;
    
    public static void addPieces(final StructureManager cva, final List<StructurePiece> list, final Random random, final BlockPos fu) {
        final Rotation cap5 = Rotation.getRandom(random);
        list.add(new NetherFossilPiece(cva, Util.<ResourceLocation>getRandom(NetherFossilPieces.FOSSILS, random), fu, cap5));
    }
    
    static {
        FOSSILS = new ResourceLocation[] { new ResourceLocation("nether_fossils/fossil_1"), new ResourceLocation("nether_fossils/fossil_2"), new ResourceLocation("nether_fossils/fossil_3"), new ResourceLocation("nether_fossils/fossil_4"), new ResourceLocation("nether_fossils/fossil_5"), new ResourceLocation("nether_fossils/fossil_6"), new ResourceLocation("nether_fossils/fossil_7"), new ResourceLocation("nether_fossils/fossil_8"), new ResourceLocation("nether_fossils/fossil_9"), new ResourceLocation("nether_fossils/fossil_10"), new ResourceLocation("nether_fossils/fossil_11"), new ResourceLocation("nether_fossils/fossil_12"), new ResourceLocation("nether_fossils/fossil_13"), new ResourceLocation("nether_fossils/fossil_14") };
    }
    
    public static class NetherFossilPiece extends TemplateStructurePiece {
        private final ResourceLocation templateLocation;
        private final Rotation rotation;
        
        public NetherFossilPiece(final StructureManager cva, final ResourceLocation uh, final BlockPos fu, final Rotation cap) {
            super(StructurePieceType.NETHER_FOSSIL, 0);
            this.templateLocation = uh;
            this.templatePosition = fu;
            this.rotation = cap;
            this.loadTemplate(cva);
        }
        
        public NetherFossilPiece(final StructureManager cva, final CompoundTag le) {
            super(StructurePieceType.NETHER_FOSSIL, le);
            this.templateLocation = new ResourceLocation(le.getString("Template"));
            this.rotation = Rotation.valueOf(le.getString("Rot"));
            this.loadTemplate(cva);
        }
        
        private void loadTemplate(final StructureManager cva) {
            final StructureTemplate cve3 = cva.getOrCreate(this.templateLocation);
            final StructurePlaceSettings cvb4 = new StructurePlaceSettings().setRotation(this.rotation).setMirror(Mirror.NONE).addProcessor(BlockIgnoreProcessor.STRUCTURE_AND_AIR);
            this.setup(cve3, this.templatePosition, cvb4);
        }
        
        @Override
        protected void addAdditionalSaveData(final CompoundTag le) {
            super.addAdditionalSaveData(le);
            le.putString("Template", this.templateLocation.toString());
            le.putString("Rot", this.rotation.name());
        }
        
        @Override
        protected void handleDataMarker(final String string, final BlockPos fu, final LevelAccessor bqc, final Random random, final BoundingBox ctd) {
        }
        
        @Override
        public boolean postProcess(final WorldGenLevel bqu, final StructureFeatureManager bqq, final ChunkGenerator cha, final Random random, final BoundingBox ctd, final ChunkPos bph, final BlockPos fu) {
            ctd.expand(this.template.getBoundingBox(this.placeSettings, this.templatePosition));
            return super.postProcess(bqu, bqq, cha, random, ctd, bph, fu);
        }
    }
}
