當前位置: 首頁>>代碼示例>>Java>>正文


Java ItemStack.copy方法代碼示例

本文整理匯總了Java中org.spongepowered.api.item.inventory.ItemStack.copy方法的典型用法代碼示例。如果您正苦於以下問題:Java ItemStack.copy方法的具體用法?Java ItemStack.copy怎麽用?Java ItemStack.copy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.spongepowered.api.item.inventory.ItemStack的用法示例。


在下文中一共展示了ItemStack.copy方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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;
    }
 
開發者ID:Zerthick,項目名稱:PlayerShopsRPG,代碼行數:27,代碼來源:InventoryUtils.java

示例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;
    }
 
開發者ID:Zerthick,項目名稱:PlayerShopsRPG,代碼行數:24,代碼來源:InventoryUtils.java

示例3: createItem

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public ShopTransactionResult createItem(Player player, ItemStack itemStack) {

        //If the player is not the owner of the shop return a message to the player
        if (!hasRenterPermissions(player)) {
            return new ShopTransactionResult(Messages.YOU_ARE_NOT_THE_OWNER_OF_THIS_SHOP);
        }

        //If the item already exists return a message to the player
        for (ShopItem item : items.values()) {
            if (InventoryUtils.itemStackEqualsIgnoreSize(item.getItemStack(), itemStack)) {
                return new ShopTransactionResult(Messages.THE_SPECIFIED_ITEM_IS_ALREADY_IN_THIS_SHOP);
            }
        }

        //The item is not already in the shop, we need to add it
        ItemStack itemToAdd = itemStack.copy();
        itemToAdd.setQuantity(1);
        ShopItem newShopItem = new ShopItem(itemToAdd.createSnapshot(), 0, -1, -1, -1);
        items.put(newShopItem.getShopItemUUID(), newShopItem);
        return ShopTransactionResult.SUCCESS;
    }
 
開發者ID:Zerthick,項目名稱:PlayerShopsRPG,代碼行數:22,代碼來源:Shop.java

示例4: StockItem

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public StockItem(ItemStack itemstack, Double sellfor, Double buyfor, Currency currency, int stockLimit) {
	item = itemstack.copy();
	if (sellfor!=null && sellfor>=0) sellprice = sellfor;
	if (buyfor!=null && buyfor>=0) buyprice = buyfor;
	this.currency = currency; 
	maxStock = stockLimit;
}
 
開發者ID:DosMike,項目名稱:VillagerShops,代碼行數:8,代碼來源:StockItem.java

示例5: itemStackEqualsIgnoreSize

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public static boolean itemStackEqualsIgnoreSize(ItemStack o1, ItemStack o2) {

        ItemStack copy1 = o1.copy();
        ItemStack copy2 = o2.copy();

        copy1.setQuantity(1);
        copy2.setQuantity(1);

        return copy1.equalTo(copy2);
    }
 
開發者ID:Zerthick,項目名稱:PlayerShopsRPG,代碼行數:11,代碼來源:InventoryUtils.java

示例6: getItemCount

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public static int getItemCount(PlayerInventory inventory, ItemStack itemStack) {

        ItemStack copy = itemStack.copy();

        return inventory.query(QueryOperationTypes.ITEM_STACK_IGNORE_QUANTITY.of(copy)).totalItems();
    }
 
開發者ID:Zerthick,項目名稱:PlayerShopsRPG,代碼行數:7,代碼來源:InventoryUtils.java


注:本文中的org.spongepowered.api.item.inventory.ItemStack.copy方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。