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


Java ItemStack.getQuantity方法代碼示例

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


在下文中一共展示了ItemStack.getQuantity方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: execute

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
@Override public CommandResult execute(CommandSource commandSource, CommandContext commandContext) throws CommandException {
    if (!(commandSource instanceof Player)) {
        commandSource.sendMessage(Text.of("You need to be in game or specify a player for this command to work."));
        return CommandResult.empty();
    }
    Player plr = (Player)commandSource;
    if(!plr.getItemInHand(HandTypes.MAIN_HAND).isPresent()){
        commandSource.sendMessage(Text.of("You must be holding an item to deposit a key."));
        return CommandResult.empty();
    }
    ItemStack key = plr.getItemInHand(HandTypes.MAIN_HAND).get();
    if(HuskyCrates.instance.crateUtilities.vcFromKey(key) == null){
        commandSource.sendMessage(Text.of(TextColors.RED,"Not a valid key."));
        return CommandResult.empty();
    }
    VirtualCrate virtualCrate = HuskyCrates.instance.crateUtilities.vcFromKey(plr.getItemInHand(HandTypes.MAIN_HAND).get());
    int keyCount = key.getQuantity();
    plr.setItemInHand(HandTypes.MAIN_HAND,null);
    virtualCrate.giveVirtualKeys(plr,keyCount);
    //commandSource.sendMessage(Text.of(TextColors.GREEN,"Successfully deposited " + keyCount + " ", TextSerializers.FORMATTING_CODE.deserialize(virtualCrate.displayName),TextColors.GREEN," Key(s)."));
    commandSource.sendMessage(TextSerializers.FORMATTING_CODE.deserialize(
            virtualCrate.getLangData().formatter(virtualCrate.getLangData().depositSuccess,null,plr,virtualCrate,null,null,keyCount)
    ));
    return CommandResult.success();
}
 
開發者ID:codeHusky,項目名稱:HuskyCrates-Sponge,代碼行數:26,代碼來源:DepositKey.java

示例2: processCostItem

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private void processCostItem(Player player, String command, Consumer<CommandResult> callback)
{
    int count = Integer.parseInt(command.replaceFirst("\\s++$", ""));
    ItemStack stackUsed = SpongeUnimplemented.getItemHeldByMouse(player).createStack();
    int stackUsedQuantity = stackUsed.getQuantity();
    if (stackUsedQuantity > count)
    {
        stackUsed.setQuantity(stackUsedQuantity - count);
        SpongeUnimplemented.setItemHeldByMouse(player, stackUsed.createSnapshot());
        callback.accept(CommandResult.success());
    }
    else
    {
        SpongeUnimplemented.setItemHeldByMouse(player, ItemStackSnapshot.NONE);
        callback.accept(CommandResult.empty());
    }
}
 
開發者ID:ustc-zzzz,項目名稱:VirtualChest,代碼行數:18,代碼來源:VirtualChestActions.java

示例3: getFrom

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
/** Tries to take a certain amount of items represented by this item from the inventory 
 * @param quantity the amount of items supposed to take, overriding the default in item  
 * @returns the amount of items taken out of the inventory */
public int getFrom(Inventory inv, int quantity) {
	int ammountLeft = quantity;
	Inventory result = inv.queryAny(item);
	for (Inventory s : result.slots()) {
		ItemStack onSlot = s.poll(ammountLeft).orElse(null);
		if (onSlot == null)continue;
		if (onSlot.getQuantity()<=ammountLeft) {
			ammountLeft -= onSlot.getQuantity();
		} else {
			onSlot.setQuantity(onSlot.getQuantity()-ammountLeft);
			ammountLeft = 0;
			s.offer(onSlot);
		}
		if (ammountLeft == 0) break;
	}
	return quantity-ammountLeft;
}
 
開發者ID:DosMike,項目名稱:VillagerShops,代碼行數:21,代碼來源:StockItem.java

示例4: onItemUse

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
@Override
public boolean onItemUse(ItemStack itemStack, Player player, HandType currHand, BlockSnapshot clickedBlock,
        Direction side, Vector3d hitPoint) {
    CustomWorld world = WorldManager.toCustomWorld(player.getWorld());
    Vector3d pos;
    if (hitPoint == null) {
        pos = clickedBlock.getPosition().add(side.asBlockOffset()).toDouble().add(0.5, 0, 0.5);
    } else {
        pos = clickedBlock.getPosition().toDouble().add(hitPoint);
    }
    TurtleEntity turtle = new TurtleEntity(player.getWorld());
    turtle.setPosition(pos);
    Vector3d r = player.getHeadRotation();
    turtle.setRotation(new Vector3d(r.getX(), r.getY() + 180, r.getZ()));
    if (world.spawnEntity(turtle)) {
        if (player.gameMode().get() != GameModes.CREATIVE) {
            itemStack.setQuantity(itemStack.getQuantity() - 1);
            if (itemStack.getQuantity() == 0) {
                itemStack = null;
            }
            player.setItemInHand(currHand, itemStack);
        }
    }
    return false;
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:26,代碼來源:ItemTurtle.java

示例5: decrementStack

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
@Override
public ItemStack decrementStack(int index, int count) {
    ItemStack original = this.itemArray[index];
    if (original == null) {
        return null;
    }
    if (original.getQuantity() <= count) {
        this.itemArray[index] = null;
        return original;
    } else {
        ItemStack rest = ImplUtil.splitItemStack(original, count);
        if (original.getQuantity() == 0) {
            this.itemArray[index] = null;
        }
        return rest;
    }

}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:19,代碼來源:SimpleInventory.java

示例6: ofItem

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public static Text ofItem(@Nullable ItemStack item) {
	if (item == null) {
		return Text.EMPTY;
	}
	String q = item.getQuantity() > 1 ? " (" + item.getQuantity() + ")" : "";
	return Text.of(TextActions.showItem(item.createSnapshot()), item.getOrElse(Keys.DISPLAY_NAME, Text.of(item)),
			q);
}
 
開發者ID:rojo8399,項目名稱:PlaceholderAPI,代碼行數:9,代碼來源:TextUtils.java

示例7: commandHat

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private CompletableFuture<Boolean> commandHat(final EPlayer player) {
	Optional<ItemStack> item = player.getItemInMainHand();
	
	// Le jouer n'a pas d'objet dans la main
	if (!item.isPresent()) {
		EAMessages.EMPTY_ITEM_IN_HAND.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
	
	Optional<ItemStack> helmet = player.getHelmet();
		
	// Le joueur a un casque sur la tête
	if (helmet.isPresent() && UtilsItemType.isHelmet(helmet.get().getType())) {
		EEMessages.HAT_NO_EMPTY.sender()
			.replace("{item}", EChat.getButtomItem(player.getHelmet().get(), EEMessages.HAT_ITEM_COLOR.getColor()))
			.sendTo(player);
		return CompletableFuture.completedFuture(false);
	}
		
	// Le joueur a un item sur la tête
	if (helmet.isPresent()) {
		player.giveItemAndDrop(helmet.get());
	}
	
	ItemStack stack = player.getItemInMainHand().get();
	if (stack.getQuantity() > 1){
           stack.setQuantity(stack.getQuantity() - 1);
           player.setItemInMainHand(stack);
	} else {
		player.setItemInMainHand(null);
	}
	
       stack.setQuantity(1);
       player.setHelmet(stack);
       
       EEMessages.HAT_IS_HAT.sender()
		.replace("{item}", EChat.getButtomItem(item.get(), EEMessages.HAT_ITEM_COLOR.getColor()))
		.sendTo(player);
       return CompletableFuture.completedFuture(true);
}
 
開發者ID:EverCraft,項目名稱:EverEssentials,代碼行數:41,代碼來源:EEHat.java

示例8: offerTo

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
/** Try to add the represented itemstack to the target inventory without doing any economy changes.
	 * This function is able to give a fraction of the represented stack size. 
	 * @param quantity the amount of items supposed to give, overriding the default in item  
	 * @returns the amount of given items */
	public int offerTo(Inventory inv, int quantity) {
		ItemStack copy = item.copy();
		copy.setQuantity(quantity);
		inv.offer(copy);
		int c = copy.getQuantity();
//		VillagerShops.l("Rejected "+c);
		return quantity-c;
	}
 
開發者ID:DosMike,項目名稱:VillagerShops,代碼行數:13,代碼來源:StockItem.java

示例9: checkZero

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
private void checkZero() {
    this.hasZeroStacks = false;
    for (int i = 1; i <= 9; i++) {
        ItemStack stack = this.inventory.getStack(i);
        if (stack != null && stack.getQuantity() == 0) {
            this.hasZeroStacks = true;
            break;
        }
    }
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:11,代碼來源:TileAutoCrafting.java

示例10: destroy

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public void destroy(Cause closeCause) {
    this.ready = false;
    for (Container container : Lists.newArrayList(this.containers)) {
        removeContainer(container);
        containerToPlayer(container).closeInventory(closeCause);
    }
    for (int i = 0; i < this.inventory.getSize(); i++) {
        ItemStack item = this.inventory.getStack(i);
        if (item != null && item.getQuantity() > 0) {
            dropItem(item);
        }
    }
    this.inventory.clear();
}
 
開發者ID:simon816,項目名稱:Industrialization,代碼行數:15,代碼來源:TileAutoCrafting.java

示例11: ItemStackView

import org.spongepowered.api.item.inventory.ItemStack; //導入方法依賴的package包/類
public ItemStackView(ItemStack value) {
    super(value);

    this.type = value.getItem();
    this.quantity = value.getQuantity();
}
 
開發者ID:Valandur,項目名稱:Web-API,代碼行數:7,代碼來源:ItemStackView.java


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