当前位置: 首页>>代码示例>>Java>>正文


Java ItemStackSnapshot.isEmpty方法代码示例

本文整理汇总了Java中org.spongepowered.api.item.inventory.ItemStackSnapshot.isEmpty方法的典型用法代码示例。如果您正苦于以下问题:Java ItemStackSnapshot.isEmpty方法的具体用法?Java ItemStackSnapshot.isEmpty怎么用?Java ItemStackSnapshot.isEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.spongepowered.api.item.inventory.ItemStackSnapshot的用法示例。


在下文中一共展示了ItemStackSnapshot.isEmpty方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: peekSet

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
@Override
public PeekedSetTransactionResult peekSet(@Nullable ItemStack stack) {
    if (!LanternItemStack.isEmpty(stack) && !isValidItem(stack)) {
        return new PeekedSetTransactionResult(InventoryTransactionResult.Type.FAILURE, ImmutableList.of(), stack, null);
    }
    stack = LanternItemStack.toNullable(stack);
    final List<SlotTransaction> transactions = new ArrayList<>();
    final ItemStackSnapshot oldItem = LanternItemStack.toSnapshot(this.itemStack);
    ItemStack rejectedItem = null;
    ItemStack replacedItem = oldItem.isEmpty() ? null : this.itemStack.copy();
    ItemStackSnapshot newItem = ItemStackSnapshot.NONE;
    if (stack != null) {
        final int maxStackSize = Math.min(stack.getMaxStackQuantity(), this.maxStackSize);
        final int quantity = stack.getQuantity();
        if (quantity > maxStackSize) {
            stack = stack.copy();
            stack.setQuantity(maxStackSize);
            newItem = LanternItemStack.toSnapshot(stack);
            // Create the rest stack that was rejected,
            // because the inventory doesn't allow so many items
            rejectedItem = stack.copy();
            rejectedItem.setQuantity(quantity - maxStackSize);
        } else {
            newItem = LanternItemStack.toSnapshot(stack);
        }
    }
    transactions.add(new SlotTransaction(this, oldItem, newItem));
    return new PeekedSetTransactionResult(InventoryTransactionResult.Type.SUCCESS, transactions, rejectedItem, replacedItem);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:30,代码来源:AbstractInventorySlot.java

示例2: getMatrixResult

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
/**
 * Gets the {@link MatrixResult}.
 *
 * @return The matrix result
 */
public MatrixResult getMatrixResult(int times) {
    checkArgument(times <= this.maxTimes, "times cannot exceed getMaxTimes");
    final ICraftingMatrix matrix = (ICraftingMatrix) this.matrix.copy();
    final List<ItemStackSnapshot> remaining = this.result.getRemainingItems();
    final List<ItemStack> rest = new ArrayList<>();
    final int w = matrix.width();
    for (int x = 0; x < w; x++) {
        for (int y = 0; y < matrix.height(); y++) {
            ItemStack itemStack = matrix.get(x, y);
            if (!itemStack.isEmpty()) {
                itemStack.setQuantity(itemStack.getQuantity() -
                        (this.itemQuantities == null ? 1 : this.itemQuantities[x][y]) * times);
            }
            final ItemStackSnapshot itemStackSnapshot = remaining.get(y * w + x);
            if (!itemStackSnapshot.isEmpty()) {
                int quantity;
                final boolean flag = LanternItemStack.areSimilar(itemStack, itemStackSnapshot);
                if (itemStack.isEmpty() || flag) {
                    if (!flag) {
                        itemStack = itemStackSnapshot.createStack();
                        matrix.set(x, y, itemStack);
                    }
                    final int max = itemStack.getMaxStackQuantity();
                    quantity = itemStack.getQuantity() * times;
                    if (quantity > max) {
                        itemStack.setQuantity(max);
                        itemStack = itemStack.copy();
                        itemStack.setQuantity(quantity - max);
                    } else {
                        itemStack = null;
                    }
                } else {
                    itemStack = itemStackSnapshot.createStack();
                    itemStack.setQuantity(itemStack.getQuantity() * times);
                }
                if (itemStack != null) {
                    rest.add(itemStack);
                }
            }
        }
    }
    return new MatrixResult(matrix, rest);
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:49,代码来源:ExtendedCraftingResult.java

示例3: toNullable

import org.spongepowered.api.item.inventory.ItemStackSnapshot; //导入方法依赖的package包/类
@Nullable
public static LanternItemStack toNullable(@Nullable ItemStackSnapshot itemStackSnapshot) {
    return itemStackSnapshot == null || itemStackSnapshot.isEmpty() ? null :  (LanternItemStack) itemStackSnapshot.createStack();
}
 
开发者ID:LanternPowered,项目名称:LanternServer,代码行数:5,代码来源:LanternItemStack.java


注:本文中的org.spongepowered.api.item.inventory.ItemStackSnapshot.isEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。