use of forestry.core.inventory.ItemInventory 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());
}
use of forestry.core.inventory.ItemInventory in project ForestryMC by ForestryMC.
the class ResupplyHandler method resupply.
@Override
public void resupply(EntityPlayer player) {
// Do not attempt resupplying if this backpack is already opened.
if (!(player.openContainer instanceof ContainerPlayer)) {
return;
}
for (ItemStack backpack : getBackpacks(player.inventory)) {
if (ItemBackpack.getMode(backpack) == BackpackMode.RESUPPLY) {
// Load their inventory
ItemBackpack backpackItem = (ItemBackpack) backpack.getItem();
ItemInventory backpackInventory = new ItemInventoryBackpack(player, backpackItem.getBackpackSize(), backpack);
Event event = new BackpackResupplyEvent(player, backpackItem.getDefinition(), backpackInventory);
if (!MinecraftForge.EVENT_BUS.post(event)) {
for (int i = 0; i < backpackInventory.getSizeInventory(); i++) {
ItemStack itemStack = backpackInventory.getStackInSlot(i);
if (topOffPlayerInventory(player, itemStack)) {
backpackInventory.setInventorySlotContents(i, itemStack);
break;
}
}
}
}
}
}
Aggregations