    001    package net.minecraft.world.gen.feature;
    002
    003    import java.util.ArrayList;
    004    import java.util.Arrays;
    005    import java.util.Iterator;
    006    import java.util.List;
    007    import java.util.Map;
    008    import java.util.Random;
    009    import java.util.Map.Entry;
    010    import net.minecraft.entity.monster.EntityWitch;
    011    import net.minecraft.util.MathHelper;
    012    import net.minecraft.world.biome.BiomeGenBase;
    013    import net.minecraft.world.biome.SpawnListEntry;
    014    import net.minecraft.world.gen.structure.MapGenStructure;
    015    import net.minecraft.world.gen.structure.StructureScatteredFeatureStart;
    016    import net.minecraft.world.gen.structure.StructureStart;
    017
    018    public 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 var2 = par1Map.entrySet().iterator();
    043
    044            while (var2.hasNext())
    045            {
    046                Entry var3 = (Entry)var2.next();
    047
    048                if (((String)var3.getKey()).equals("distance"))
    049                {
    050                    this.maxDistanceBetweenScatteredFeatures = MathHelper.parseIntWithDefaultAndMax((String)var3.getValue(), this.maxDistanceBetweenScatteredFeatures, this.minDistanceBetweenScatteredFeatures + 1);
    051                }
    052            }
    053        }
    054
    055        protected boolean canSpawnStructureAtCoords(int par1, int par2)
    056        {
    057            int var3 = par1;
    058            int var4 = 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 var5 = par1 / this.maxDistanceBetweenScatteredFeatures;
    071            int var6 = par2 / this.maxDistanceBetweenScatteredFeatures;
    072            Random var7 = this.worldObj.setRandomSeed(var5, var6, 14357617);
    073            var5 *= this.maxDistanceBetweenScatteredFeatures;
    074            var6 *= this.maxDistanceBetweenScatteredFeatures;
    075            var5 += var7.nextInt(this.maxDistanceBetweenScatteredFeatures - this.minDistanceBetweenScatteredFeatures);
    076            var6 += var7.nextInt(this.maxDistanceBetweenScatteredFeatures - this.minDistanceBetweenScatteredFeatures);
    077
    078            if (var3 == var5 && var4 == var6)
    079            {
    080                BiomeGenBase var8 = this.worldObj.getWorldChunkManager().getBiomeGenAt(var3 * 16 + 8, var4 * 16 + 8);
    081                Iterator var9 = biomelist.iterator();
    082
    083                while (var9.hasNext())
    084                {
    085                    BiomeGenBase var10 = (BiomeGenBase)var9.next();
    086
    087                    if (var8 == var10)
    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    }