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