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

import net.minecraft.world.level.levelgen.structure.StructurePiece;
import net.minecraft.world.level.levelgen.structure.NetherBridgePieces;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.StructureStart;
import com.google.common.collect.Lists;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import java.util.Random;
import net.minecraft.world.level.chunk.ChunkGenerator;
import net.minecraft.world.level.biome.BiomeManager;
import com.mojang.datafixers.Dynamic;
import java.util.function.Function;
import net.minecraft.world.level.biome.Biome;
import java.util.List;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;

public class NetherFortressFeature extends StructureFeature<NoneFeatureConfiguration> {
    private static final List<Biome.SpawnerData> FORTRESS_ENEMIES;
    
    public NetherFortressFeature(final Function<Dynamic<?>, ? extends NoneFeatureConfiguration> function) {
        super(function);
    }
    
    @Override
    public boolean isFeatureChunk(final BiomeManager bkv, final ChunkGenerator<?> caa, final Random random, final int integer4, final int integer5, final Biome bkt) {
        final int integer6 = integer4 >> 4;
        final int integer7 = integer5 >> 4;
        random.setSeed((long)(integer6 ^ integer7 << 4) ^ caa.getSeed());
        random.nextInt();
        return random.nextInt(3) == 0 && integer4 == (integer6 << 4) + 4 + random.nextInt(8) && integer5 == (integer7 << 4) + 4 + random.nextInt(8) && caa.isBiomeValidStartForStructure(bkt, this);
    }
    
    @Override
    public StructureStartFactory getStartFactory() {
        return NetherBridgeStart::new;
    }
    
    @Override
    public String getFeatureName() {
        return "Fortress";
    }
    
    @Override
    public int getLookupRange() {
        return 8;
    }
    
    @Override
    public List<Biome.SpawnerData> getSpecialEnemies() {
        return NetherFortressFeature.FORTRESS_ENEMIES;
    }
    
    static {
        FORTRESS_ENEMIES = Lists.<Biome.SpawnerData>newArrayList(new Biome.SpawnerData(EntityType.BLAZE, 10, 2, 3), new Biome.SpawnerData(EntityType.ZOMBIE_PIGMAN, 5, 4, 4), new Biome.SpawnerData(EntityType.WITHER_SKELETON, 8, 5, 5), new Biome.SpawnerData(EntityType.SKELETON, 2, 5, 5), new Biome.SpawnerData(EntityType.MAGMA_CUBE, 3, 4, 4));
    }
    
    public static class NetherBridgeStart extends StructureStart {
        public NetherBridgeStart(final StructureFeature<?> cfl, final int integer2, final int integer3, final BoundingBox clb, final int integer5, final long long6) {
            super(cfl, integer2, integer3, clb, integer5, long6);
        }
        
        @Override
        public void generatePieces(final ChunkGenerator<?> caa, final StructureManager cmo, final int integer3, final int integer4, final Biome bkt) {
            final NetherBridgePieces.StartPiece q7 = new NetherBridgePieces.StartPiece(this.random, (integer3 << 4) + 2, (integer4 << 4) + 2);
            this.pieces.add(q7);
            q7.addChildren(q7, this.pieces, this.random);
            final List<StructurePiece> list8 = q7.pendingChildren;
            while (!list8.isEmpty()) {
                final int integer5 = this.random.nextInt(list8.size());
                final StructurePiece clu10 = list8.remove(integer5);
                clu10.addChildren(q7, this.pieces, this.random);
            }
            this.calculateBoundingBox();
            this.moveInsideHeights(this.random, 48, 70);
        }
    }
}
