package net.minecraft.world.gen.structure;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.Map.Entry;
import net.minecraft.entity.monster.EntityWitch;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraft.world.biome.BiomeGenBase;

public class MapGenScatteredFeature extends MapGenStructure
{
	private static List biomelist = Arrays.asList(new BiomeGenBase[] {BiomeGenBase.desert, BiomeGenBase.desertHills, BiomeGenBase.jungle, BiomeGenBase.jungleHills, BiomeGenBase.swampland});
	private List scatteredFeatureSpawnList;
	private int maxDistanceBetweenScatteredFeatures;
	private int minDistanceBetweenScatteredFeatures;
	private static final String __OBFID = "CL_00000471";

	public MapGenScatteredFeature()
	{
		this.scatteredFeatureSpawnList = new ArrayList();
		this.maxDistanceBetweenScatteredFeatures = 32;
		this.minDistanceBetweenScatteredFeatures = 8;
		this.scatteredFeatureSpawnList.add(new BiomeGenBase.SpawnListEntry(EntityWitch.class, 1, 1, 1));
	}

	public MapGenScatteredFeature(Map par1Map)
	{
		this();
		Iterator iterator = par1Map.entrySet().iterator();

		while (iterator.hasNext())
		{
			Entry entry = (Entry)iterator.next();

			if (((String)entry.getKey()).equals("distance"))
			{
				this.maxDistanceBetweenScatteredFeatures = MathHelper.parseIntWithDefaultAndMax((String)entry.getValue(), this.maxDistanceBetweenScatteredFeatures, this.minDistanceBetweenScatteredFeatures + 1);
			}
		}
	}

	public String func_143025_a()
	{
		return "Temple";
	}

	protected boolean canSpawnStructureAtCoords(int par1, int par2)
	{
		int k = par1;
		int l = par2;

		if (par1 < 0)
		{
			par1 -= this.maxDistanceBetweenScatteredFeatures - 1;
		}

		if (par2 < 0)
		{
			par2 -= this.maxDistanceBetweenScatteredFeatures - 1;
		}

		int i1 = par1 / this.maxDistanceBetweenScatteredFeatures;
		int j1 = par2 / this.maxDistanceBetweenScatteredFeatures;
		Random random = this.worldObj.setRandomSeed(i1, j1, 14357617);
		i1 *= this.maxDistanceBetweenScatteredFeatures;
		j1 *= this.maxDistanceBetweenScatteredFeatures;
		i1 += random.nextInt(this.maxDistanceBetweenScatteredFeatures - this.minDistanceBetweenScatteredFeatures);
		j1 += random.nextInt(this.maxDistanceBetweenScatteredFeatures - this.minDistanceBetweenScatteredFeatures);

		if (k == i1 && l == j1)
		{
			BiomeGenBase biomegenbase = this.worldObj.getWorldChunkManager().getBiomeGenAt(k * 16 + 8, l * 16 + 8);
			Iterator iterator = biomelist.iterator();

			while (iterator.hasNext())
			{
				BiomeGenBase biomegenbase1 = (BiomeGenBase)iterator.next();

				if (biomegenbase == biomegenbase1)
				{
					return true;
				}
			}
		}

		return false;
	}

	protected StructureStart getStructureStart(int par1, int par2)
	{
		return new MapGenScatteredFeature.Start(this.worldObj, this.rand, par1, par2);
	}

	public boolean func_143030_a(int par1, int par2, int par3)
	{
		StructureStart structurestart = this.func_143028_c(par1, par2, par3);

		if (structurestart != null && structurestart instanceof MapGenScatteredFeature.Start && !structurestart.components.isEmpty())
		{
			StructureComponent structurecomponent = (StructureComponent)structurestart.components.getFirst();
			return structurecomponent instanceof ComponentScatteredFeaturePieces.SwampHut;
		}
		else
		{
			return false;
		}
	}

	public List getScatteredFeatureSpawnList()
	{
		return this.scatteredFeatureSpawnList;
	}

	public static class Start extends StructureStart
		{
			private static final String __OBFID = "CL_00000472";

			public Start() {}

			public Start(World par1World, Random par2Random, int par3, int par4)
			{
				super(par3, par4);
				BiomeGenBase biomegenbase = par1World.getBiomeGenForCoords(par3 * 16 + 8, par4 * 16 + 8);

				if (biomegenbase != BiomeGenBase.jungle && biomegenbase != BiomeGenBase.jungleHills)
				{
					if (biomegenbase == BiomeGenBase.swampland)
					{
						ComponentScatteredFeaturePieces.SwampHut swamphut = new ComponentScatteredFeaturePieces.SwampHut(par2Random, par3 * 16, par4 * 16);
						this.components.add(swamphut);
					}
					else
					{
						ComponentScatteredFeaturePieces.DesertPyramid desertpyramid = new ComponentScatteredFeaturePieces.DesertPyramid(par2Random, par3 * 16, par4 * 16);
						this.components.add(desertpyramid);
					}
				}
				else
				{
					ComponentScatteredFeaturePieces.JunglePyramid junglepyramid = new ComponentScatteredFeaturePieces.JunglePyramid(par2Random, par3 * 16, par4 * 16);
					this.components.add(junglepyramid);
				}

				this.updateBoundingBox();
			}
		}
}