Search in sources :

Example 6 with ItemIdentifier

use of net.mcft.copy.betterstorage.misc.ItemIdentifier in project BetterStorage by copygirl.

the class InventoryCratePlayerView method setInventorySlotContents.

@Override
public void setInventorySlotContents(int slot, ItemStack stack) {
    if ((slot < 0) || (slot >= getSizeInventory()))
        return;
    ItemStack oldStack = getStackInSlot(slot);
    ignoreModifiedItems = true;
    if (oldStack != null) {
        ItemIdentifier item = new ItemIdentifier(oldStack);
        getMapData(item).itemCount -= oldStack.stackSize;
        data.removeItems(item, oldStack.stackSize);
    }
    if (stack != null) {
        int amount = Math.min(stack.stackSize, Math.min(data.getSpaceForItem(stack), stack.getMaxStackSize()));
        if (amount <= 0)
            return;
        stack = StackUtils.copyStack(stack.copy(), amount);
        getMapData(stack).itemCount += amount;
        data.addItems(stack);
    }
    ignoreModifiedItems = false;
    tempContents[slot] = stack;
    if (stack == null)
        onSlotEmptied(slot);
}
Also used : ItemIdentifier(net.mcft.copy.betterstorage.misc.ItemIdentifier) ItemStack(net.minecraft.item.ItemStack)

Example 7 with ItemIdentifier

use of net.mcft.copy.betterstorage.misc.ItemIdentifier in project BetterStorage by copygirl.

the class InventoryCratePlayerView method onCrateItemsModified.

// ICrateWatcher implementation
@Override
public void onCrateItemsModified(ItemStack changed) {
    if (ignoreModifiedItems)
        return;
    ItemIdentifier item = new ItemIdentifier(changed);
    int amount = changed.stackSize;
    MapData itemData = getMapData(item);
    Queue<Integer> emptySlots = new LinkedList<Integer>();
    for (int slot = 0; slot < tempContents.length; slot++) {
        ItemStack stack = tempContents[slot];
        if (stack == null) {
            emptySlots.add(slot);
            continue;
        }
        if (!item.matches(stack))
            continue;
        amount -= modifyItemsInSlot(slot, stack, itemData, amount);
        if (amount == 0)
            return;
    }
    while ((amount > 0) && (emptySlots.size() > 0)) amount -= setItemsInSlot(emptySlots.poll(), item, itemData, amount);
}
Also used : ItemIdentifier(net.mcft.copy.betterstorage.misc.ItemIdentifier) ItemStack(net.minecraft.item.ItemStack) LinkedList(java.util.LinkedList)

Aggregations

ItemIdentifier (net.mcft.copy.betterstorage.misc.ItemIdentifier)7 ItemStack (net.minecraft.item.ItemStack)7 LinkedList (java.util.LinkedList)1 ICrateWatcher (net.mcft.copy.betterstorage.api.crate.ICrateWatcher)1 Item (net.minecraft.item.Item)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 NBTTagList (net.minecraft.nbt.NBTTagList)1