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

import net.minecraft.world.level.levelgen.structure.PillagerOutpostPieces;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.levelgen.structure.templatesystem.StructureManager;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.levelgen.structure.BeardedStructureStart;
import com.google.common.collect.Lists;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
import net.minecraft.world.level.ChunkPos;
import net.minecraft.world.level.levelgen.WorldgenRandom;
import net.minecraft.world.level.biome.BiomeSource;
import net.minecraft.world.level.chunk.ChunkGenerator;
import com.mojang.serialization.Codec;
import net.minecraft.world.level.biome.Biome;
import java.util.List;
import net.minecraft.world.level.levelgen.feature.configurations.NoneFeatureConfiguration;

public class PillagerOutpostFeature extends StructureFeature<NoneFeatureConfiguration> {
    private static final List<Biome.SpawnerData> OUTPOST_ENEMIES;
    
    public PillagerOutpostFeature(final Codec<NoneFeatureConfiguration> codec) {
        super(codec);
    }
    
    @Override
    public List<Biome.SpawnerData> getSpecialEnemies() {
        return PillagerOutpostFeature.OUTPOST_ENEMIES;
    }
    
    @Override
    protected boolean isFeatureChunk(final ChunkGenerator cha, final BiomeSource brh, final long long3, final WorldgenRandom ciy, final int integer5, final int integer6, final Biome bre, final ChunkPos bph, final NoneFeatureConfiguration coa) {
        final int integer7 = integer5 >> 4;
        final int integer8 = integer6 >> 4;
        ciy.setSeed((long)(integer7 ^ integer8 << 4) ^ long3);
        ciy.nextInt();
        if (ciy.nextInt(5) != 0) {
            return false;
        }
        for (int integer9 = integer5 - 10; integer9 <= integer5 + 10; ++integer9) {
            for (int integer10 = integer6 - 10; integer10 <= integer6 + 10; ++integer10) {
                final ChunkPos bph2 = StructureFeature.VILLAGE.getPotentialFeatureChunk(cha.getSettings().getConfig(StructureFeature.VILLAGE), long3, ciy, integer9, integer10);
                if (integer9 == bph2.x && integer10 == bph2.z) {
                    return false;
                }
            }
        }
        return true;
    }
    
    @Override
    public StructureStartFactory<NoneFeatureConfiguration> getStartFactory() {
        return FeatureStart::new;
    }
    
    static {
        OUTPOST_ENEMIES = Lists.<Biome.SpawnerData>newArrayList(new Biome.SpawnerData(EntityType.PILLAGER, 1, 1, 1));
    }
    
    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 BlockPos fu8 = new BlockPos(integer3 * 16, 0, integer4 * 16);
            PillagerOutpostPieces.addPieces(cha, cva, fu8, this.pieces, this.random);
            this.calculateBoundingBox();
        }
    }
}
