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