001package net.minecraft.world.gen.feature;
002
003import java.util.Random;
004import net.minecraft.block.Block;
005import net.minecraft.entity.item.EntityEnderCrystal;
006import net.minecraft.world.World;
007
008public class WorldGenSpikes extends WorldGenerator
009{
010    /**
011     * The Block ID that the generator is allowed to replace while generating the terrain.
012     */
013    private int replaceID;
014
015    public WorldGenSpikes(int par1)
016    {
017        this.replaceID = par1;
018    }
019
020    public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
021    {
022        if (par1World.isAirBlock(par3, par4, par5) && par1World.getBlockId(par3, par4 - 1, par5) == this.replaceID)
023        {
024            int l = par2Random.nextInt(32) + 6;
025            int i1 = par2Random.nextInt(4) + 1;
026            int j1;
027            int k1;
028            int l1;
029            int i2;
030
031            for (j1 = par3 - i1; j1 <= par3 + i1; ++j1)
032            {
033                for (k1 = par5 - i1; k1 <= par5 + i1; ++k1)
034                {
035                    l1 = j1 - par3;
036                    i2 = k1 - par5;
037
038                    if (l1 * l1 + i2 * i2 <= i1 * i1 + 1 && par1World.getBlockId(j1, par4 - 1, k1) != this.replaceID)
039                    {
040                        return false;
041                    }
042                }
043            }
044
045            for (j1 = par4; j1 < par4 + l && j1 < 128; ++j1)
046            {
047                for (k1 = par3 - i1; k1 <= par3 + i1; ++k1)
048                {
049                    for (l1 = par5 - i1; l1 <= par5 + i1; ++l1)
050                    {
051                        i2 = k1 - par3;
052                        int j2 = l1 - par5;
053
054                        if (i2 * i2 + j2 * j2 <= i1 * i1 + 1)
055                        {
056                            par1World.setBlockAndMetadataWithNotify(k1, j1, l1, Block.obsidian.blockID, 0, 2);
057                        }
058                    }
059                }
060            }
061
062            EntityEnderCrystal entityendercrystal = new EntityEnderCrystal(par1World);
063            entityendercrystal.setLocationAndAngles((double)((float)par3 + 0.5F), (double)(par4 + l), (double)((float)par5 + 0.5F), par2Random.nextFloat() * 360.0F, 0.0F);
064            par1World.spawnEntityInWorld(entityendercrystal);
065            par1World.setBlockAndMetadataWithNotify(par3, par4 + l, par5, Block.bedrock.blockID, 0, 2);
066            return true;
067        }
068        else
069        {
070            return false;
071        }
072    }
073}