| 1 | package net.minecraft.util;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.Collections;
|
| 5 | import java.util.List;
|
| 6 | import java.util.Random;
|
| 7 | import net.minecraft.inventory.IInventory;
|
| 8 | import net.minecraft.item.Item;
|
| 9 | import net.minecraft.item.ItemStack;
|
| 10 | import net.minecraft.tileentity.TileEntityDispenser;
|
| 11 |
|
| 12 | public class WeightedRandomChestContent extends WeightedRandom.Item
|
| 13 | {
|
| 14 | /** The Item/Block ID to generate in the Chest. */
|
| 15 | private ItemStack theItemId;
|
| 16 |
|
| 17 | /** The minimum stack size of generated item. */
|
| 18 | private int minStackSize;
|
| 19 |
|
| 20 | /** The maximum stack size of generated item. */
|
| 21 | private int maxStackSize;
|
| 22 |
|
| 23 | public WeightedRandomChestContent(Item p_i45311_1_, int p_i45311_2_, int minimumChance, int maximumChance, int itemWeightIn)
|
| 24 | {
|
| 25 | super(itemWeightIn);
|
| 26 | this.theItemId = new ItemStack(p_i45311_1_, 1, p_i45311_2_);
|
| 27 | this.minStackSize = minimumChance;
|
| 28 | this.maxStackSize = maximumChance;
|
| 29 | }
|
| 30 |
|
| 31 | public WeightedRandomChestContent(ItemStack stack, int minimumChance, int maximumChance, int itemWeightIn)
|
| 32 | {
|
| 33 | super(itemWeightIn);
|
| 34 | this.theItemId = stack;
|
| 35 | this.minStackSize = minimumChance;
|
| 36 | this.maxStackSize = maximumChance;
|
| 37 | }
|
| 38 |
|
| 39 | public static void generateChestContents(Random random, List<WeightedRandomChestContent> listIn, IInventory inv, int max)
|
| 40 | {
|
| 41 | for (int i = 0; i < max; ++i)
|
| 42 | {
|
| 43 | WeightedRandomChestContent weightedrandomchestcontent = (WeightedRandomChestContent)WeightedRandom.getRandomItem(random, listIn);
|
| 44 | int j = weightedrandomchestcontent.minStackSize + random.nextInt(weightedrandomchestcontent.maxStackSize - weightedrandomchestcontent.minStackSize + 1);
|
| 45 |
|
| 46 | if (weightedrandomchestcontent.theItemId.getMaxStackSize() >= j)
|
| 47 | {
|
| 48 | ItemStack itemstack1 = weightedrandomchestcontent.theItemId.copy();
|
| 49 | itemstack1.stackSize = j;
|
| 50 | inv.setInventorySlotContents(random.nextInt(inv.getSizeInventory()), itemstack1);
|
| 51 | }
|
| 52 | else
|
| 53 | {
|
| 54 | for (int k = 0; k < j; ++k)
|
| 55 | {
|
| 56 | ItemStack itemstack = weightedrandomchestcontent.theItemId.copy();
|
| 57 | itemstack.stackSize = 1;
|
| 58 | inv.setInventorySlotContents(random.nextInt(inv.getSizeInventory()), itemstack);
|
| 59 | }
|
| 60 | }
|
| 61 | }
|
| 62 | }
|
| 63 |
|
| 64 | public static void generateDispenserContents(Random random, List<WeightedRandomChestContent> listIn, TileEntityDispenser dispenser, int max)
|
| 65 | {
|
| 66 | for (int i = 0; i < max; ++i)
|
| 67 | {
|
| 68 | WeightedRandomChestContent weightedrandomchestcontent = (WeightedRandomChestContent)WeightedRandom.getRandomItem(random, listIn);
|
| 69 | int j = weightedrandomchestcontent.minStackSize + random.nextInt(weightedrandomchestcontent.maxStackSize - weightedrandomchestcontent.minStackSize + 1);
|
| 70 |
|
| 71 | if (weightedrandomchestcontent.theItemId.getMaxStackSize() >= j)
|
| 72 | {
|
| 73 | ItemStack itemstack1 = weightedrandomchestcontent.theItemId.copy();
|
| 74 | itemstack1.stackSize = j;
|
| 75 | dispenser.setInventorySlotContents(random.nextInt(dispenser.getSizeInventory()), itemstack1);
|
| 76 | }
|
| 77 | else
|
| 78 | {
|
| 79 | for (int k = 0; k < j; ++k)
|
| 80 | {
|
| 81 | ItemStack itemstack = weightedrandomchestcontent.theItemId.copy();
|
| 82 | itemstack.stackSize = 1;
|
| 83 | dispenser.setInventorySlotContents(random.nextInt(dispenser.getSizeInventory()), itemstack);
|
| 84 | }
|
| 85 | }
|
| 86 | }
|
| 87 | }
|
| 88 |
|
| 89 | public static List<WeightedRandomChestContent> func_177629_a(List<WeightedRandomChestContent> p_177629_0_, WeightedRandomChestContent... p_177629_1_)
|
| 90 | {
|
| 91 | List<WeightedRandomChestContent> list = Lists.newArrayList(p_177629_0_);
|
| 92 | Collections.addAll(list, p_177629_1_);
|
| 93 | return list;
|
| 94 | }
|
| 95 | }
|
| 96 |
|