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

The following examples show how to use net.minecraft.item.Item#getContainerItem() . These examples are extracted from open source projects. 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 want to check out the right sidebar which shows the related API usage.
Example 1
/**
 * 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
/**
 * 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 Project: OpenModsLib   File: ItemUtils.java    License: 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;
}