本文整理匯總了Java中org.spongepowered.api.item.inventory.ItemStack.getMaxStackQuantity方法的典型用法代碼示例。如果您正苦於以下問題:Java ItemStack.getMaxStackQuantity方法的具體用法?Java ItemStack.getMaxStackQuantity怎麽用?Java ItemStack.getMaxStackQuantity使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.spongepowered.api.item.inventory.ItemStack
的用法示例。
在下文中一共展示了ItemStack.getMaxStackQuantity方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: addItem
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public static int addItem(PlayerInventory inventory, ItemStack itemStack, int amount) {
int overflow = 0;
int total = amount;
int availableSpace = getAvailableSpace(inventory, itemStack);
if (amount > availableSpace) {
overflow = amount - availableSpace;
total = availableSpace;
}
int maxStackQuantity = itemStack.getMaxStackQuantity();
ItemStack copy = itemStack.copy();
while (total > 0) {
if (total > maxStackQuantity) {
copy.setQuantity(maxStackQuantity);
total -= maxStackQuantity;
} else {
copy.setQuantity(total);
total = 0;
}
inventory.offer(copy);
}
return overflow;
}
示例2: removeItem
import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public static int removeItem(PlayerInventory inventory, ItemStack itemStack, int amount) {
int underflow = 0;
int total = amount;
int availableItems = getItemCount(inventory, itemStack);
if (amount > availableItems) {
underflow = amount - availableItems;
total = availableItems;
}
ItemStack copy = itemStack.copy();
while (total > 0) {
if (total > copy.getMaxStackQuantity()) {
inventory.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy)).poll(copy.getMaxStackQuantity());
total -= copy.getMaxStackQuantity();
} else {
inventory.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy)).poll(total);
total = 0;
}
}
return underflow;
}