Java源码示例:codechicken.lib.util.ItemUtils

示例1
@Override
public ItemStack slotClick(ContainerExtended container, EntityPlayer player, int button, ClickType clickType) {
    ItemStack held = player.inventory.getItemStack();
    if (button == 0 && clickType == ClickType.QUICK_MOVE) {
        NEIClientUtils.cheatItem(getStack(), button, -1);
    } else if (button == 1) {
        putStack(ItemStack.EMPTY);
    } else if (!held.isEmpty()) {
        if (isItemValid(held)) {
            putStack(ItemUtils.copyStack(held, 1));
            player.inventory.setItemStack(ItemStack.EMPTY);
        }
    } else if (getHasStack()) {
        player.inventory.setItemStack(getStack());
    }

    return ItemStack.EMPTY;
}
 
示例2
@Override
public void putStack(@Nonnull ItemStack stack) {
    if (!stack.isEmpty() && stack.getCount() > stackLimit) {
        stack = ItemUtils.copyStack(stack, stackLimit);
    }
    super.putStack(stack);
}
 
示例3
/**
 * Gets the maximum quantity of an item that can be inserted into inv
 */
public static int getInsertibleQuantity(InventoryRange inv, @Nonnull ItemStack stack) {
    int quantity = 0;
    stack = ItemUtils.copyStack(stack, Integer.MAX_VALUE);
    for (int slot : inv.slots) {
        quantity += fitStackInSlot(inv, slot, stack);
    }

    return quantity;
}
 
示例4
/**
 * @param simulate If set to true, no items will actually be inserted
 * @return The number of items unable to be inserted
 */
public static int insertItem(InventoryRange inv, @Nonnull ItemStack stack, boolean simulate) {
    stack = stack.copy();
    for (int pass = 0; pass < 2; pass++) {
        for (int slot : inv.slots) {
            ItemStack base = inv.inv.getStackInSlot(slot);
            if ((pass == 0) == (base.isEmpty())) {
                continue;
            }
            int fit = fitStackInSlot(inv, slot, stack);
            if (fit == 0) {
                continue;
            }

            if (!base.isEmpty()) {
                stack.shrink(fit);
                if (!simulate) {
                    base.grow(fit);
                    inv.inv.setInventorySlotContents(slot, base);
                }
            } else {
                if (!simulate) {
                    inv.inv.setInventorySlotContents(slot, ItemUtils.copyStack(stack, fit));
                }
                stack.shrink(fit);
            }
            if (stack.getCount() == 0) {
                return 0;
            }
        }
    }
    return stack.getCount();
}
 
示例5
/**
 * Counts the matching stacks.
 * Checks for insertion or extraction.
 *
 * @param handler The inventory.
 * @param filter  What we are checking for.
 * @param insert  If we are checking for insertion or extraction.
 * @return The total number of items of the specified filter type.
 */
public static int countMatchingStacks(IItemHandler handler, ItemStack filter, boolean insert) {

    int c = 0;
    for (int slot = 0; slot < handler.getSlots(); slot++) {
        ItemStack stack = handler.getStackInSlot(slot);
        if (!stack.isEmpty() && ItemUtils.areStacksSameType(filter, stack) && (insert ? canInsertStack(handler, slot, stack) : canExtractStack(handler, slot))) {
            c += stack.getCount();
        }
    }
    return c;
}
 
示例6
public static int getInsertableQuantity(IItemHandler handler, ItemStack stack) {
    ItemStack copy = ItemUtils.copyStack(stack, Integer.MAX_VALUE);
    int quantity = 0;
    for (int slot = 0; slot < handler.getSlots(); slot++) {
        if (canInsertStack(handler, slot, copy)) {
            ItemStack left = handler.insertItem(slot, copy, true);
            if (left.isEmpty()) {
                quantity += copy.getCount();
            } else {
                quantity += copy.getCount() - left.getCount();
            }
        }
    }
    return quantity;
}
 
示例7
@Override
public ItemStack getInfiniteItem(ItemStack typeStack) {
    return ItemUtils.copyStack(typeStack, -1);
}
 
示例8
public DistributedIngred(ItemStack item) {
    stack = ItemUtils.copyStack(item, 1);
}