    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    public class WorldGeneratorBonusChest extends WorldGenerator
    006    {
    007        /**
    008         * Instance of WeightedRandomChestContent what will randomly generate items into the Bonus Chest.
    009         */
    010        private final WeightedRandomChestContent[] theBonusChestGenerator;
    011
    012        /**
    013         * Value of this int will determine how much items gonna generate in Bonus Chest.
    014         */
    015        private final int itemsToGenerateInBonusChest;
    016
    017        public WorldGeneratorBonusChest(WeightedRandomChestContent[] par1ArrayOfWeightedRandomChestContent, int par2)
    018        {
    019            this.theBonusChestGenerator = par1ArrayOfWeightedRandomChestContent;
    020            this.itemsToGenerateInBonusChest = par2;
    021        }
    022
    023        public boolean generate(World par1World, Random par2Random, int par3, int par4, int par5)
    024        {
    025            int var12;
    026
    027            for (boolean var6 = false; ((var12 = par1World.getBlockId(par3, par4, par5)) == 0 || var12 == Block.leaves.blockID) && par4 > 1; --par4)
    028            {
    029                ;
    030            }
    031
    032            if (par4 < 1)
    033            {
    034                return false;
    035            }
    036            else
    037            {
    038                ++par4;
    039
    040                for (int var7 = 0; var7 < 4; ++var7)
    041                {
    042                    int var8 = par3 + par2Random.nextInt(4) - par2Random.nextInt(4);
    043                    int var9 = par4 + par2Random.nextInt(3) - par2Random.nextInt(3);
    044                    int var10 = par5 + par2Random.nextInt(4) - par2Random.nextInt(4);
    045
    046                    if (par1World.isAirBlock(var8, var9, var10) && par1World.doesBlockHaveSolidTopSurface(var8, var9 - 1, var10))
    047                    {
    048                        par1World.setBlockWithNotify(var8, var9, var10, Block.chest.blockID);
    049                        TileEntityChest var11 = (TileEntityChest)par1World.getBlockTileEntity(var8, var9, var10);
    050
    051                        if (var11 != null && var11 != null)
    052                        {
    053                            WeightedRandomChestContent.generateChestContents(par2Random, this.theBonusChestGenerator, var11, this.itemsToGenerateInBonusChest);
    054                        }
    055
    056                        if (par1World.isAirBlock(var8 - 1, var9, var10) && par1World.doesBlockHaveSolidTopSurface(var8 - 1, var9 - 1, var10))
    057                        {
    058                            par1World.setBlockWithNotify(var8 - 1, var9, var10, Block.torchWood.blockID);
    059                        }
    060
    061                        if (par1World.isAirBlock(var8 + 1, var9, var10) && par1World.doesBlockHaveSolidTopSurface(var8 - 1, var9 - 1, var10))
    062                        {
    063                            par1World.setBlockWithNotify(var8 + 1, var9, var10, Block.torchWood.blockID);
    064                        }
    065
    066                        if (par1World.isAirBlock(var8, var9, var10 - 1) && par1World.doesBlockHaveSolidTopSurface(var8 - 1, var9 - 1, var10))
    067                        {
    068                            par1World.setBlockWithNotify(var8, var9, var10 - 1, Block.torchWood.blockID);
    069                        }
    070
    071                        if (par1World.isAirBlock(var8, var9, var10 + 1) && par1World.doesBlockHaveSolidTopSurface(var8 - 1, var9 - 1, var10))
    072                        {
    073                            par1World.setBlockWithNotify(var8, var9, var10 + 1, Block.torchWood.blockID);
    074                        }
    075
    076                        return true;
    077                    }
    078                }
    079
    080                return false;
    081            }
    082        }
    083    }