Search in sources :

Example 1 with ICrateWatcher

use of net.mcft.copy.betterstorage.api.crate.ICrateWatcher in project BetterStorage by copygirl.

the class CratePileData method removeItems.

// Removing items
/** Removes and returns a specific amount of items. <br>
	 *  Returns less than the requested amount when there's
	 *  not enough, or null if there's none at all. */
public ItemStack removeItems(ItemIdentifier item, int amount) {
    int currentAmount = getContents().get(item);
    amount = Math.min(amount, currentAmount);
    if (amount <= 0)
        return null;
    getContents().set(item, currentAmount - amount);
    ItemStack removedStack = item.createStack(-amount);
    for (ICrateWatcher watcher : watchers) watcher.onCrateItemsModified(removedStack);
    markDirty();
    return item.createStack(amount);
}
Also used : ICrateWatcher(net.mcft.copy.betterstorage.api.crate.ICrateWatcher) ItemStack(net.minecraft.item.ItemStack)

Example 2 with ICrateWatcher

use of net.mcft.copy.betterstorage.api.crate.ICrateWatcher in project BetterStorage by copygirl.

the class CratePileData method addItems.

// Adding items
/** Tries to add a stack to the contents. <br>
	 *  Returns what could not be added, null if there was no overflow. */
public ItemStack addItems(ItemStack stack) {
    if (stack == null)
        return null;
    ItemStack overflow = null;
    int space = getSpaceForItem(stack);
    if (space > 0) {
        if (space < stack.stackSize)
            overflow = stack.splitStack(stack.stackSize - space);
        ItemIdentifier item = new ItemIdentifier(stack);
        getContents().set(item, getContents().get(item) + stack.stackSize);
        for (ICrateWatcher watcher : watchers) watcher.onCrateItemsModified(stack);
    } else
        overflow = stack;
    markDirty();
    return overflow;
}
Also used : ItemIdentifier(net.mcft.copy.betterstorage.misc.ItemIdentifier) ICrateWatcher(net.mcft.copy.betterstorage.api.crate.ICrateWatcher) ItemStack(net.minecraft.item.ItemStack)

Aggregations

ICrateWatcher (net.mcft.copy.betterstorage.api.crate.ICrateWatcher)2 ItemStack (net.minecraft.item.ItemStack)2 ItemIdentifier (net.mcft.copy.betterstorage.misc.ItemIdentifier)1