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


Java Item.setCount方法代码示例

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


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

示例1: getItemHelper

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public static Item getItemHelper(CompoundTag tag) {
    if (!tag.contains("id") || !tag.contains("Count")) {
        return Item.get(0);
    }

    Item item;
    try {
        item = Item.get(tag.getShort("id"), !tag.contains("Damage") ? 0 : tag.getShort("Damage"), tag.getByte("Count"));
    } catch (Exception e) {
        item = Item.fromString(tag.getString("id"));
        item.setDamage(!tag.contains("Damage") ? 0 : tag.getShort("Damage"));
        item.setCount(tag.getByte("Count"));
    }

    if (tag.contains("tag") && tag.get("tag") instanceof CompoundTag) {
        item.setNamedTag(tag.getCompound("tag"));
    }

    return item;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:21,代码来源:NBTIO.java

示例2: canAddItem

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean canAddItem(Item item) {
    item = item.clone();
    boolean checkDamage = item.hasMeta();
    boolean checkTag = item.getCompoundTag() != null;
    for (int i = 0; i < this.getSize(); ++i) {
        Item slot = this.getItem(i);
        if (item.equals(slot, checkDamage, checkTag)) {
            int diff;
            if ((diff = slot.getMaxStackSize() - slot.getCount()) > 0) {
                item.setCount(item.getCount() - diff);
            }
        } else if (slot.getId() == Item.AIR) {
            item.setCount(item.getCount() - this.getMaxStackSize());
        }

        if (item.getCount() <= 0) {
            return true;
        }
    }

    return false;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:24,代码来源:BaseInventory.java

示例3: onEnchant

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public void onEnchant(Player who, Item before, Item after) {
    Item result = (before.getId() == Item.BOOK) ? new ItemBookEnchanted() : before;
    if (!before.hasEnchantments() && after.hasEnchantments() && after.getId() == result.getId() && this.levels != null && this.entries != null) {
        Enchantment[] enchantments = after.getEnchantments();
        for (int i = 0; i < 3; i++) {
            if (Arrays.equals(enchantments, this.entries[i].getEnchantments())) {
                Item lapis = this.getItem(1);
                int level = who.getExperienceLevel();
                int exp = who.getExperience();
                int cost = this.entries[i].getCost();
                if (lapis.getId() == Item.DYE && lapis.getDamage() == DyeColor.BLUE.getDyeData() && lapis.getCount() > i && level >= cost) {
                    result.addEnchantment(enchantments);
                    this.setItem(0, result);
                    lapis.setCount(lapis.getCount() - i - 1);
                    this.setItem(1, lapis);
                    who.setExperience(exp, level - cost);
                    break;
                }
            }
        }
    }
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:23,代码来源:EnchantInventory.java

示例4: onActivate

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean onActivate(Item item, Player player) {
    BlockEntity blockEntity = this.getLevel().getBlockEntity(this);
    BlockEntityItemFrame itemFrame = (BlockEntityItemFrame) blockEntity;
    if (itemFrame.getItem().getId() == Item.AIR) {
        // We can't use Item.get(item.getId(), item.getDamage(), 1) because
        // we need to keep the item's NBT tags
        Item itemOnFrame = item.clone(); // So we clone the item
        itemOnFrame.setCount(1); // Change it to only one item (if we keep +1, visual glitches will happen)
        itemFrame.setItem(itemOnFrame); // And then we set it on the item frame
        // The item will be removed from the player's hand a few lines ahead
        this.getLevel().addSound(new ItemFrameItemAddedSound(this));
        if (player != null && player.isSurvival()) {
            int count = item.getCount();
            if (count-- <= 0) {
                player.getInventory().setItemInHand(new ItemBlock(new BlockAir(), 0, 0));
                return true;
            }
            item.setCount(count);
            player.getInventory().setItemInHand(item);
        }
    } else {
        int itemRot = itemFrame.getItemRotation();
        if (itemRot >= 7) {
            itemRot = 0;
        } else {
            itemRot++;
        }
        itemFrame.setItemRotation(itemRot);
        this.getLevel().addSound(new ItemFrameItemRotated(this));
    }
    return true;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:34,代码来源:BlockItemFrame.java

示例5: matchItems

import cn.nukkit.item.Item; //导入方法依赖的package包/类
protected boolean matchItems(List<Item> needItems, List<Item> haveItems) {
    for (InventoryAction action : this.actions) {
        if (action.getTargetItem().getId() != Item.AIR) {
            needItems.add(action.getTargetItem());
        }

        if (!action.isValid(this.source)) {
            return false;
        }

        if (action.getSourceItem().getId() != Item.AIR) {
            haveItems.add(action.getSourceItem());
        }
    }

    for (Item needItem : new ArrayList<>(needItems)) {
        for (Item haveItem : new ArrayList<>(haveItems)) {
            if (needItem.equals(haveItem)) {
                int amount = Math.min(haveItem.getCount(), needItem.getCount());
                needItem.setCount(needItem.getCount() - amount);
                haveItem.setCount(haveItem.getCount() - amount);
                if (haveItem.getCount() == 0) {
                    haveItems.remove(haveItem);
                }
                if (needItem.getCount() == 0) {
                    needItems.remove(needItem);
                    break;
                }
            }
        }
    }

    return haveItems.isEmpty() && needItems.isEmpty();
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:35,代码来源:SimpleInventoryTransaction.java

示例6: removeIngredient

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public ShapelessRecipe removeIngredient(Item item) {
    for (Item ingredient : this.ingredients) {
        if (item.getCount() <= 0) {
            break;
        }

        if (ingredient.equals(item, item.hasMeta(), item.getCompoundTag() != null)) {
            this.ingredients.remove(ingredient);
            item.setCount(item.getCount() - 1);
        }
    }

    return this;
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:15,代码来源:ShapelessRecipe.java

示例7: onActivate

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean onActivate(Item item, Player player) {
    BlockEntity blockEntity = getLevel().getBlockEntity(this);
    if (!(blockEntity instanceof BlockEntityFlowerPot)) return false;
    if (blockEntity.namedTag.getShort("item") != 0 || blockEntity.namedTag.getInt("mData") != 0) return false;
    int itemID;
    int itemMeta;
    if (!canPlaceIntoFlowerPot(item.getId())) {
        if (!canPlaceIntoFlowerPot(item.getBlock().getId())) {
            return true;
        }
        itemID = item.getBlock().getId();
        itemMeta = item.getDamage();
    } else {
        itemID = item.getId();
        itemMeta = item.getDamage();
    }
    blockEntity.namedTag.putShort("item", itemID);
    blockEntity.namedTag.putInt("data", itemMeta);

    this.meta = 1;
    this.getLevel().setBlock(this, this, true);
    ((BlockEntityFlowerPot) blockEntity).spawnToAll();

    if (player.isSurvival()) {
        item.setCount(item.getCount() - 1);
        player.getInventory().setItemInHand(item.getCount() > 0 ? item : Item.get(Item.AIR));
    }
    return true;
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:31,代码来源:BlockFlowerPot.java

示例8: onInteract

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public boolean onInteract(Player player, Item item) {
	Item change;
	if (item.getId() == 0) {
		this.sendHand(player);
		this.sendArmor(player);
		player.getInventory().sendContents(player);
		return false;
	} else if (item.isHelmet()) {
		change = this.getHelmet();
		this.setHelmet(item.clone());
	} else if (item.isChestplate()) {
		change = this.getChestPlate();
		this.setChestPlate(item.clone());
	} else if (item.isLeggings()) {
		change = this.getLeggins();
		this.setLeggins(item.clone());
	} else if (item.isBoots()) {
		change = this.getBoots();
		this.setBoots(item.clone());
	} else {
		if (item.getCount() > 1) {
			change = item.clone();
			change.setCount(change.getCount() - 1);
	    	player.getInventory().setItemInHand(change);
			player.getInventory().addItem(this.getHand());
			item.setCount(1);
			this.setHand(item.clone());
			return false;
		} else {
			change = this.getHand();
			this.setHand(item);
		}
	}
	player.getInventory().setItemInHand(change);
    return false;
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:37,代码来源:EntityArmorStand.java

示例9: matchItems

import cn.nukkit.item.Item; //导入方法依赖的package包/类
protected boolean matchItems(List<Item> needItems, List<Item> haveItems) {
    for (Transaction ts : this.transactions) {
        if (ts.getTargetItem().getId() != Item.AIR) {
            needItems.add(ts.getTargetItem());
        }
        Item checkSourceItem = ts.getInventory().getItem(ts.getSlot());
        Item sourceItem = ts.getSourceItem();
        if (!checkSourceItem.deepEquals(sourceItem) || sourceItem.getCount() != checkSourceItem.getCount()) {
            return false;
        }
        if (sourceItem.getId() != Item.AIR) {
            haveItems.add(sourceItem);
        }
    }

    for (Item needItem : new ArrayList<>(needItems)) {
        for (Item haveItem : new ArrayList<>(haveItems)) {
            if (needItem.deepEquals(haveItem)) {
                int amount = Math.min(haveItem.getCount(), needItem.getCount());
                needItem.setCount(needItem.getCount() - amount);
                haveItem.setCount(haveItem.getCount() - amount);
                if (haveItem.getCount() == 0) {
                    haveItems.remove(haveItem);
                }
                if (needItem.getCount() == 0) {
                    needItems.remove(needItem);
                    break;
                }
            }
        }
    }

    return true;
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:35,代码来源:SimpleTransactionGroup.java

示例10: addIngredient

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public ShapelessRecipe addIngredient(Item item) {
    if (this.ingredients.size() > 9) {
        throw new IllegalArgumentException("Shapeless recipes cannot have more than 9 ingredients");
    }

    Item it = item.clone();
    it.setCount(1);

    while (item.getCount() > 0) {
        this.ingredients.add(it.clone());
        item.setCount(item.getCount() - 1);
    }

    return this;
}
 
开发者ID:CoreXDevelopment,项目名称:CoreX,代码行数:16,代码来源:ShapelessRecipe.java


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