use of forestry.api.storage.BackpackStowEvent in project ForestryMC by ForestryMC.
the class ItemBackpack method tryStowing.
public static void tryStowing(EntityPlayer player, ItemStack backpackStack, ItemStack stack) {
if (getMode(backpackStack) == BackpackMode.LOCKED) {
return;
}
ItemBackpack backpack = (ItemBackpack) backpackStack.getItem();
ItemInventory inventory = new ItemInventoryBackpack(player, backpack.getBackpackSize(), backpackStack);
if (MinecraftForge.EVENT_BUS.post(new BackpackStowEvent(player, backpack.getDefinition(), inventory, stack))) {
return;
}
if (stack.isEmpty()) {
return;
}
IItemHandler itemHandler = inventory.getItemHandler();
ItemHandlerInventoryManipulator manipulator = new ItemHandlerInventoryManipulator(itemHandler);
ItemStack remainder = manipulator.addStack(stack);
stack.setCount(remainder == null ? 0 : remainder.getCount());
}
Aggregations