    001package net.minecraft.world.gen.feature;
    002
    003import java.util.ArrayList;
    004import java.util.Arrays;
    005import java.util.Iterator;
    006import java.util.List;
    007import java.util.Map;
    008import java.util.Random;
    009import java.util.Map.Entry;
    010import net.minecraft.entity.monster.EntityWitch;
    011import net.minecraft.util.MathHelper;
    012import net.minecraft.world.biome.BiomeGenBase;
    013import net.minecraft.world.biome.SpawnListEntry;
    014import net.minecraft.world.gen.structure.MapGenStructure;
    015import net.minecraft.world.gen.structure.StructureScatteredFeatureStart;
    016import net.minecraft.world.gen.structure.StructureStart;
    017
    018public class MapGenScatteredFeature extends MapGenStructure
    019{
    020    private static List biomelist = Arrays.asList(new BiomeGenBase[] {BiomeGenBase.desert, BiomeGenBase.desertHills, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.swampland});
    021
    022    /** contains possible spawns for scattered features */
    023    private List scatteredFeatureSpawnList;
    024
    025    /** the maximum distance between scattered features */
    026    private int maxDistanceBetweenScatteredFeatures;
    027
    028    /** the minimum distance between scattered features */
    029    private int minDistanceBetweenScatteredFeatures;
    030
    031    public MapGenScatteredFeature()
    032    {
    033        this.scatteredFeatureSpawnList = new ArrayList();
    034        this.maxDistanceBetweenScatteredFeatures = 32;
    035        this.minDistanceBetweenScatteredFeatures = 8;
    036        this.scatteredFeatureSpawnList.add(new SpawnListEntry(EntityWitch.class, 1, 1, 1));
    037    }
    038
    039    public MapGenScatteredFeature(Map par1Map)
    040    {
    041        this();
    042        Iterator iterator = par1Map.entrySet().iterator();
    043
    044        while (iterator.hasNext())
    045        {
    046            Entry entry = (Entry)iterator.next();
    047
    048            if (((String)entry.getKey()).equals("distance"))
    049            {
    050                this.maxDistanceBetweenScatteredFeatures = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.maxDistanceBetweenScatteredFeatures, this.minDistanceBetweenScatteredFeatures + 1);
    051            }
    052        }
    053    }
    054
    055    protected boolean canSpawnStructureAtCoords(int par1, int par2)
    056    {
    057        int k = par1;
    058        int l = par2;
    059
    060        if (par1 < 0)
    061        {
    062            par1 -= this.maxDistanceBetweenScatteredFeatures - 1;
    063        }
    064
    065        if (par2 < 0)
    066        {
    067            par2 -= this.maxDistanceBetweenScatteredFeatures - 1;
    068        }
    069
    070        int i1 = par1 / this.maxDistanceBetweenScatteredFeatures;
    071        int j1 = par2 / this.maxDistanceBetweenScatteredFeatures;
    072        Random random = this.worldObj.setRandomSeed(i1, j1, 14357617);
    073        i1 *= this.maxDistanceBetweenScatteredFeatures;
    074        j1 *= this.maxDistanceBetweenScatteredFeatures;
    075        i1 += random.nextInt(this.maxDistanceBetweenScatteredFeatures - this.minDistanceBetweenScatteredFeatures);
    076        j1 += random.nextInt(this.maxDistanceBetweenScatteredFeatures - this.minDistanceBetweenScatteredFeatures);
    077
    078        if (k == i1 && l == j1)
    079        {
    080            BiomeGenBase biomegenbase = this.worldObj.getWorldChunkManager().getBiomeGenAt(k * 16 + 8, l * 16 + 8);
    081            Iterator iterator = biomelist.iterator();
    082
    083            while (iterator.hasNext())
    084            {
    085                BiomeGenBase biomegenbase1 = (BiomeGenBase)iterator.next();
    086
    087                if (biomegenbase == biomegenbase1)
    088                {
    089                    return true;
    090                }
    091            }
    092        }
    093
    094        return false;
    095    }
    096
    097    protected StructureStart getStructureStart(int par1, int par2)
    098    {
    099        return new StructureScatteredFeatureStart(this.worldObj, this.rand, par1, par2);
    100    }
    101
    102    /**
    103     * returns possible spawns for scattered features
    104     */
    105    public List getScatteredFeatureSpawnList()
    106    {
    107        return this.scatteredFeatureSpawnList;
    108    }
    109}