    001    package net.minecraft.util;
    002
    003    import java.util.Random;
    004
    005    import cpw.mods.fml.common.FMLLog;
    006    import net.minecraft.item.ItemStack;
    007    import net.minecraft.tileentity.TileEntityChest;
    008    import net.minecraft.tileentity.TileEntityDispenser;
    009    import net.minecraftforge.common.ChestGenHooks;
    010    import net.minecraftforge.common.DungeonHooks;
    011
    012    public class WeightedRandomChestContent extends WeightedRandomItem
    013    {
    014        /** The Item/Block ID to generate in the Chest. */
    015        public ItemStack theItemId = null;
    016
    017        /** The minimum chance of item generating. */
    018        public int theMinimumChanceToGenerateItem;
    019
    020        /** The maximum chance of item generating. */
    021        public int theMaximumChanceToGenerateItem;
    022
    023        public WeightedRandomChestContent(int par1, int par2, int par3, int par4, int par5)
    024        {
    025            super(par5);
    026            this.theItemId = new ItemStack(par1, 1, par2);
    027            this.theMinimumChanceToGenerateItem = par3;
    028            this.theMaximumChanceToGenerateItem = par4;
    029        }
    030
    031        public WeightedRandomChestContent(ItemStack par1ItemStack, int par2, int par3, int par4)
    032        {
    033            super(par4);
    034            this.theItemId = par1ItemStack;
    035            this.theMinimumChanceToGenerateItem = par2;
    036            this.theMaximumChanceToGenerateItem = par3;
    037        }
    038
    039        /**
    040         * Generates the Chest contents.
    041         */
    042        @SuppressWarnings("deprecation")
    043        public static void generateChestContents(Random par0Random, WeightedRandomChestContent[] par1ArrayOfWeightedRandomChestContent, TileEntityChest par2TileEntityChest, int par3)
    044        {
    045            for (int var4 = 0; var4 < par3; ++var4)
    046            {
    047                WeightedRandomChestContent var5 = (WeightedRandomChestContent)WeightedRandom.getRandomItem(par0Random, par1ArrayOfWeightedRandomChestContent);
    048
    049                if (var5 instanceof DungeonHooks.DungeonLoot)
    050                {
    051                    DungeonHooks.DungeonLoot loot = (DungeonHooks.DungeonLoot)var5;
    052                    par2TileEntityChest.setInventorySlotContents(par0Random.nextInt(par2TileEntityChest.getSizeInventory()), loot.generateStack(par0Random));
    053                    FMLLog.warning("Some mod is still using DungeonHooks.DungonLoot, tell them to stop! %s", loot);
    054                    continue;
    055                }
    056
    057                ItemStack[] stacks = ChestGenHooks.generateStacks(par0Random, var5.theItemId, var5.theMinimumChanceToGenerateItem, var5.theMaximumChanceToGenerateItem);
    058
    059                for (ItemStack item : stacks)
    060                {
    061                    par2TileEntityChest.setInventorySlotContents(par0Random.nextInt(par2TileEntityChest.getSizeInventory()), item);
    062                }
    063            }
    064        }
    065
    066        /**
    067         * Generates the Dispenser contents.
    068         */
    069        public static void generateDispenserContents(Random par0Random, WeightedRandomChestContent[] par1ArrayOfWeightedRandomChestContent, TileEntityDispenser par2TileEntityDispenser, int par3)
    070        {
    071            for (int var4 = 0; var4 < par3; ++var4)
    072            {
    073                WeightedRandomChestContent var5 = (WeightedRandomChestContent)WeightedRandom.getRandomItem(par0Random, par1ArrayOfWeightedRandomChestContent);
    074                ItemStack[] stacks = ChestGenHooks.generateStacks(par0Random, var5.theItemId, var5.theMinimumChanceToGenerateItem, var5.theMaximumChanceToGenerateItem);
    075
    076                for (ItemStack item : stacks)
    077                {
    078                    par2TileEntityDispenser.setInventorySlotContents(par0Random.nextInt(par2TileEntityDispenser.getSizeInventory()), item);
    079                }
    080            }
    081        }
    082
    083        public static WeightedRandomChestContent[] func_92029_a(WeightedRandomChestContent[] par0ArrayOfWeightedRandomChestContent, WeightedRandomChestContent ... par1ArrayOfWeightedRandomChestContent)
    084        {
    085            WeightedRandomChestContent[] var2 = new WeightedRandomChestContent[par0ArrayOfWeightedRandomChestContent.length + par1ArrayOfWeightedRandomChestContent.length];
    086            int var3 = 0;
    087
    088            for (int var4 = 0; var4 < par0ArrayOfWeightedRandomChestContent.length; ++var4)
    089            {
    090                var2[var3++] = par0ArrayOfWeightedRandomChestContent[var4];
    091            }
    092
    093            WeightedRandomChestContent[] var8 = par1ArrayOfWeightedRandomChestContent;
    094            int var5 = par1ArrayOfWeightedRandomChestContent.length;
    095
    096            for (int var6 = 0; var6 < var5; ++var6)
    097            {
    098                WeightedRandomChestContent var7 = var8[var6];
    099                var2[var3++] = var7;
    100            }
    101
    102            return var2;
    103        }
    104    }