本文整理汇总了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);
}
示例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);
}
示例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();
}