Java Code Examples for net.minecraft.item.Item#getContainerItem()

The following examples show how to use net.minecraft.item.Item#getContainerItem() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: InventoryUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Consumes one item from slot in inv with support for containers.
 */
public static void consumeItem(IInventory inv, int slot) {
    ItemStack stack = inv.getStackInSlot(slot);
    Item item = stack.getItem();
    if (item.hasContainerItem(stack)) {
        ItemStack container = item.getContainerItem(stack);
        inv.setInventorySlotContents(slot, container);
    } else {
        inv.decrStackSize(slot, 1);
    }
}
 
Example 2
Source File: InventoryUtils.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Consumes one item from slot in inv with support for containers.
 */
public static void consumeItem(IInventory inv, int slot) {
    ItemStack stack = inv.getStackInSlot(slot);
    Item item = stack.getItem();
    if (item.hasContainerItem(stack)) {
        ItemStack container = item.getContainerItem(stack);
        inv.setInventorySlotContents(slot, container);
    } else {
        inv.decrStackSize(slot, 1);
    }
}
 
Example 3
Source File: ItemUtils.java    From OpenModsLib with MIT License 5 votes vote down vote up
@Nonnull
public static ItemStack consumeItem(@Nonnull ItemStack stack) {
	if (stack.getCount() == 1) {
		final Item item = stack.getItem();
		if (item.hasContainerItem(stack)) return item.getContainerItem(stack);
		return ItemStack.EMPTY;
	}
	stack.splitStack(1);

	return stack;
}