    001    package net.minecraft.src;
    002
    003    import java.util.Random;
    004
    005    import net.minecraftforge.common.ChestGenHooks;
    006
    007    public class WeightedRandomChestContent extends WeightedRandomItem
    008    {
    009        /** The Item/Block ID to generate in the Chest. */
    010        private int theItemId;
    011
    012        /** The Item damage/metadata. */
    013        private int theItemDamage;
    014
    015        /** The minimum chance of item generating. */
    016        private int theMinimumChanceToGenerateItem;
    017
    018        /** The maximum chance of item generating. */
    019        private int theMaximumChanceToGenerateItem;
    020
    021        public final ItemStack itemStack;
    022
    023        public WeightedRandomChestContent(int par1, int par2, int par3, int par4, int par5)
    024        {
    025            super(par5);
    026            this.theItemId = par1;
    027            this.theItemDamage = par2;
    028            this.theMinimumChanceToGenerateItem = par3;
    029            this.theMaximumChanceToGenerateItem = par4;
    030            itemStack = new ItemStack(par1, 1, par2);
    031        }
    032
    033        public WeightedRandomChestContent(ItemStack stack, int min, int max, int weight)
    034        {
    035            super(weight);
    036            itemStack = stack;
    037            theMinimumChanceToGenerateItem = min;
    038            theMaximumChanceToGenerateItem = max;
    039        }
    040        /**
    041         * Generates the Chest contents.
    042         */
    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                ItemStack[] stacks = ChestGenHooks.generateStacks(par0Random, var5.itemStack, var5.theMinimumChanceToGenerateItem, var5.theMinimumChanceToGenerateItem);
    049
    050                for (ItemStack item : stacks)
    051                {
    052                    par2TileEntityChest.setInventorySlotContents(par0Random.nextInt(par2TileEntityChest.getSizeInventory()), item);
    053                }
    054            }
    055        }
    056
    057        /**
    058         * Generates the Dispenser contents.
    059         */
    060        public static void generateDispenserContents(Random par0Random, WeightedRandomChestContent[] par1ArrayOfWeightedRandomChestContent, TileEntityDispenser par2TileEntityDispenser, int par3)
    061        {
    062            for (int var4 = 0; var4 < par3; ++var4)
    063            {
    064                WeightedRandomChestContent var5 = (WeightedRandomChestContent)WeightedRandom.getRandomItem(par0Random, par1ArrayOfWeightedRandomChestContent);
    065                ItemStack[] stacks = ChestGenHooks.generateStacks(par0Random, var5.itemStack, var5.theMinimumChanceToGenerateItem, var5.theMinimumChanceToGenerateItem);
    066
    067                for (ItemStack item : stacks)
    068                {
    069                    par2TileEntityDispenser.setInventorySlotContents(par0Random.nextInt(par2TileEntityDispenser.getSizeInventory()), item);
    070                }
    071            }
    072        }
    073    }