    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 var6 = par2Random.nextInt(32) + 6;
    025            int var7 = par2Random.nextInt(4) + 1;
    026            int var8;
    027            int var9;
    028            int var10;
    029            int var11;
    030
    031            for (var8 = par3 - var7; var8 <= par3 + var7; ++var8)
    032            {
    033                for (var9 = par5 - var7; var9 <= par5 + var7; ++var9)
    034                {
    035                    var10 = var8 - par3;
    036                    var11 = var9 - par5;
    037
    038                    if (var10 * var10 + var11 * var11 <= var7 * var7 + 1 && par1World.getBlockId(var8, par4 - 1, var9) != this.replaceID)
    039                    {
    040                        return false;
    041                    }
    042                }
    043            }
    044
    045            for (var8 = par4; var8 < par4 + var6 && var8 < 128; ++var8)
    046            {
    047                for (var9 = par3 - var7; var9 <= par3 + var7; ++var9)
    048                {
    049                    for (var10 = par5 - var7; var10 <= par5 + var7; ++var10)
    050                    {
    051                        var11 = var9 - par3;
    052                        int var12 = var10 - par5;
    053
    054                        if (var11 * var11 + var12 * var12 <= var7 * var7 + 1)
    055                        {
    056                            par1World.setBlockWithNotify(var9, var8, var10, Block.obsidian.blockID);
    057                        }
    058                    }
    059                }
    060            }
    061
    062            EntityEnderCrystal var13 = new EntityEnderCrystal(par1World);
    063            var13.setLocationAndAngles((double)((float)par3 + 0.5F), (double)(par4 + var6), (double)((float)par5 + 0.5F), par2Random.nextFloat() * 360.0F, 0.0F);
    064            par1World.spawnEntityInWorld(var13);
    065            par1World.setBlockWithNotify(par3, par4 + var6, par5, Block.bedrock.blockID);
    066            return true;
    067        }
    068        else
    069        {
    070            return false;
    071        }
    072    }
    073}