001package net.minecraft.world.gen.feature;
002
003import java.util.Random;
004import net.minecraft.block.Block;
005import net.minecraft.tileentity.TileEntityChest;
006import net.minecraft.util.WeightedRandomChestContent;
007import net.minecraft.world.World;
008
009public 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 l;
030
031        for (boolean flag = false; ((l = par1World.getBlockId(par3, par4, par5)) == 0 || l == 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 i1 = 0; i1 < 4; ++i1)
045            {
046                int j1 = par3 + par2Random.nextInt(4) - par2Random.nextInt(4);
047                int k1 = par4 + par2Random.nextInt(3) - par2Random.nextInt(3);
048                int l1 = par5 + par2Random.nextInt(4) - par2Random.nextInt(4);
049
050                if (par1World.isAirBlock(j1, k1, l1) && par1World.doesBlockHaveSolidTopSurface(j1, k1 - 1, l1))
051                {
052                    par1World.setBlock(j1, k1, l1, Block.chest.blockID, 0, 2);
053                    TileEntityChest tileentitychest = (TileEntityChest)par1World.getBlockTileEntity(j1, k1, l1);
054
055                    if (tileentitychest != null && tileentitychest != null)
056                    {
057                        WeightedRandomChestContent.generateChestContents(par2Random, this.theBonusChestGenerator, tileentitychest, this.itemsToGenerateInBonusChest);
058                    }
059
060                    if (par1World.isAirBlock(j1 - 1, k1, l1) && par1World.doesBlockHaveSolidTopSurface(j1 - 1, k1 - 1, l1))
061                    {
062                        par1World.setBlock(j1 - 1, k1, l1, Block.torchWood.blockID, 0, 2);
063                    }
064
065                    if (par1World.isAirBlock(j1 + 1, k1, l1) && par1World.doesBlockHaveSolidTopSurface(j1 - 1, k1 - 1, l1))
066                    {
067                        par1World.setBlock(j1 + 1, k1, l1, Block.torchWood.blockID, 0, 2);
068                    }
069
070                    if (par1World.isAirBlock(j1, k1, l1 - 1) && par1World.doesBlockHaveSolidTopSurface(j1 - 1, k1 - 1, l1))
071                    {
072                        par1World.setBlock(j1, k1, l1 - 1, Block.torchWood.blockID, 0, 2);
073                    }
074
075                    if (par1World.isAirBlock(j1, k1, l1 + 1) && par1World.doesBlockHaveSolidTopSurface(j1 - 1, k1 - 1, l1))
076                    {
077                        par1World.setBlock(j1, k1, l1 + 1, Block.torchWood.blockID, 0, 2);
078                    }
079
080                    return true;
081                }
082            }
083
084            return false;
085        }
086    }
087}