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

import net.minecraft.world.level.levelgen.structure.PillagerOutpostPieces;
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.ChunkPos;
import net.minecraft.core.BlockPos;
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 PillagerOutpostFeature extends RandomScatteredFeature<NoneFeatureConfiguration> {
    private static final List<Biome.SpawnerData> OUTPOST_ENEMIES;
    
    public PillagerOutpostFeature(final Function<Dynamic<?>, ? extends NoneFeatureConfiguration> function) {
        super(function);
    }
    
    @Override
    public String getFeatureName() {
        return "Pillager_Outpost";
    }
    
    @Override
    public int getLookupRange() {
        return 3;
    }
    
    @Override
    public List<Biome.SpawnerData> getSpecialEnemies() {
        return PillagerOutpostFeature.OUTPOST_ENEMIES;
    }
    
    @Override
    public boolean isFeatureChunk(final BiomeManager bkv, final ChunkGenerator<?> caa, final Random random, final int integer4, final int integer5, final Biome bkt) {
        final ChunkPos bjh8 = this.getPotentialFeatureChunkFromLocationWithOffset(caa, random, integer4, integer5, 0, 0);
        if (integer4 == bjh8.x && integer5 == bjh8.z) {
            final int integer6 = integer4 >> 4;
            final int integer7 = integer5 >> 4;
            random.setSeed((long)(integer6 ^ integer7 << 4) ^ caa.getSeed());
            random.nextInt();
            if (random.nextInt(5) != 0) {
                return false;
            }
            if (caa.isBiomeValidStartForStructure(bkt, this)) {
                for (int integer8 = integer4 - 10; integer8 <= integer4 + 10; ++integer8) {
                    for (int integer9 = integer5 - 10; integer9 <= integer5 + 10; ++integer9) {
                        if (Feature.VILLAGE.isFeatureChunk(bkv, caa, random, integer8, integer9, bkv.getBiome(new BlockPos((integer8 << 4) + 9, 0, (integer9 << 4) + 9)))) {
                            return false;
                        }
                    }
                }
                return true;
            }
        }
        return false;
    }
    
    @Override
    public StructureStartFactory getStartFactory() {
        return FeatureStart::new;
    }
    
    @Override
    protected int getRandomSalt() {
        return 165745296;
    }
    
    static {
        OUTPOST_ENEMIES = Lists.<Biome.SpawnerData>newArrayList(new Biome.SpawnerData(EntityType.PILLAGER, 1, 1, 1));
    }
    
    public static class FeatureStart extends BeardedStructureStart {
        public FeatureStart(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 BlockPos fk7 = new BlockPos(integer3 * 16, 90, integer4 * 16);
            PillagerOutpostPieces.addPieces(caa, cmo, fk7, this.pieces, this.random);
            this.calculateBoundingBox();
        }
    }
}
