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