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);
}
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);
}
Aggregations