Search in sources :

Example 1 with WeightedItemCollection

use of ivorius.reccomplex.world.storage.loot.WeightedItemCollection in project RecurrentComplex by Ivorforce.

the class ItemInventoryGenMultiTag method generateInInventory.

@Override
public void generateInInventory(WorldServer server, IInventory inventory, Random random, ItemStack stack, int fromSlot) {
    WeightedItemCollection weightedItemCollection = inventoryGenerator(stack);
    inventory.setInventorySlotContents(fromSlot, ItemStack.EMPTY);
    if (weightedItemCollection != null) {
        IntegerRange range = getGenerationCount(stack);
        int amount = range.getMin() < range.getMax() ? random.nextInt(range.getMax() - range.getMin() + 1) + range.getMin() : 0;
        TIntList emptySlots = emptySlots(inventory);
        for (int i = 0; i < amount; i++) {
            int slot = emptySlots.isEmpty() ? random.nextInt(inventory.getSizeInventory()) : emptySlots.removeAt(random.nextInt(emptySlots.size()));
            ItemStack generated = weightedItemCollection.getRandomItemStack(server, random);
            if (generated != null)
                inventory.setInventorySlotContents(slot, generated);
        }
    }
}
Also used : IntegerRange(ivorius.ivtoolkit.gui.IntegerRange) WeightedItemCollection(ivorius.reccomplex.world.storage.loot.WeightedItemCollection) TIntList(gnu.trove.list.TIntList) GuiEditItemStack(ivorius.reccomplex.gui.inventorygen.GuiEditItemStack) ItemStack(net.minecraft.item.ItemStack)

Aggregations

TIntList (gnu.trove.list.TIntList)1 IntegerRange (ivorius.ivtoolkit.gui.IntegerRange)1 GuiEditItemStack (ivorius.reccomplex.gui.inventorygen.GuiEditItemStack)1 WeightedItemCollection (ivorius.reccomplex.world.storage.loot.WeightedItemCollection)1 ItemStack (net.minecraft.item.ItemStack)1