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


Java Item.getCount方法代码示例

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


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

示例1: removeFromAll

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public void removeFromAll(Item item) {
    int count = item.getCount();

    for (int i = 0; i < this.size; i++) {
        Item target = this.getItem(i);

        if (target.equals(item, true, false)) {
            count--;
            target.count--;
            this.setItem(i, target);
            if (count <= 0) break;
        }
    }

    if (count != 0) {
        MainLogger.getLogger().debug("Unexpected ingredient count (" + count + ") in crafting grid");
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:19,代码来源:CraftingGrid.java

示例2: 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:Rsplwe,项目名称:Nukkit-Java9,代码行数:23,代码来源:EnchantInventory.java

示例3: setItem

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public void setItem(int index, Item item) {
    int i = this.getSlotIndex(index);

    CompoundTag d = NBTIO.putItemHelper(item, index);

    if (item.getId() == Item.AIR || item.getCount() <= 0) {
        if (i >= 0) {
            this.namedTag.getList("Items").getAll().remove(i);
        }
    } else if (i < 0) {
        (this.namedTag.getList("Items", CompoundTag.class)).add(d);
    } else {
        (this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
    }
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:17,代码来源:BlockEntityBrewingStand.java

示例4: setItem

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public void setItem(int index, Item item) {
    int i = this.getSlotIndex(index);

    CompoundTag d = NBTIO.putItemHelper(item, index);

    // If item is air or count less than 0, remove the item from the "Items" list
    if (item.getId() == Item.AIR || item.getCount() <= 0) {
        if (i >= 0) {
            this.namedTag.getList("Items").remove(i);
        }
    } else if (i < 0) {
        // If it is less than i, then it is a new item, so we are going to add it at the end of the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(d);
    } else {
        // If it is more than i, then it is an update on a slot, so we are going to overwrite the item in the list
        (this.namedTag.getList("Items", CompoundTag.class)).add(i, d);
    }
}
 
开发者ID:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:20,代码来源:BlockEntityChest.java

示例5: 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:JupiterDevelopmentTeam,项目名称:Jupiter,代码行数:24,代码来源:BaseInventory.java

示例6: 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

示例7: 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

示例8: setItem

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean setItem(int index, Item item) {
    item = item.clone();
    if (index < 0 || index >= this.size) {
        return false;
    } else if (item.getId() == 0 || item.getCount() <= 0) {
        return this.clear(index);
    }

    InventoryHolder holder = this.getHolder();
    if (holder instanceof Entity) {
        EntityInventoryChangeEvent ev = new EntityInventoryChangeEvent((Entity) holder, this.getItem(index), item, index);
        Server.getInstance().getPluginManager().callEvent(ev);
        if (ev.isCancelled()) {
            this.sendSlot(index, this.getViewers());
            return false;
        }

        item = ev.getNewItem();
    }

    Item old = this.getItem(index);
    this.slots.put(index, item.clone());
    this.onSlotChange(index, old);

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

示例9: isFull

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean isFull() {
    if (this.slots.size() < this.getSize()) {
        return false;
    }

    for (Item item : this.slots.values()) {
        if (item == null || item.getId() == 0 || item.getCount() < item.getMaxStackSize() || item.getCount() < this.getMaxStackSize()) {
            return false;
        }
    }

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

示例10: isEmpty

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public boolean isEmpty() {
    if (this.getMaxStackSize() <= 0) {
        return false;
    }

    for (Item item : this.slots.values()) {
        if (item != null && item.getId() != 0 && item.getCount() > 0) {
            return false;
        }
    }

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

示例11: 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:CoreXDevelopment,项目名称:CoreX,代码行数:15,代码来源:ShapelessRecipe.java

示例12: setData

import cn.nukkit.item.Item; //导入方法依赖的package包/类
@Override
public void setData(Item data) {
    this.blockId = data.getId();
    this.meta = (data.hasMeta() ? data.getDamage() : 0);
    this.count = data.getCount();
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:7,代码来源:SlotEntityData.java

示例13: readMetadata

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public static EntityMetadata readMetadata(byte[] payload) {
    BinaryStream stream = new BinaryStream();
    stream.setBuffer(payload);
    long count = stream.getUnsignedVarInt();
    EntityMetadata m = new EntityMetadata();
    for (int i = 0; i < count; i++) {
        int key = (int) stream.getUnsignedVarInt();
        int type = (int) stream.getUnsignedVarInt();
        EntityData value = null;
        switch (type) {
            case Entity.DATA_TYPE_BYTE:
                value = new ByteEntityData(key, stream.getByte());
                break;
            case Entity.DATA_TYPE_SHORT:
                value = new ShortEntityData(key, stream.getLShort());
                break;
            case Entity.DATA_TYPE_INT:
                value = new IntEntityData(key, stream.getVarInt());
                break;
            case Entity.DATA_TYPE_FLOAT:
                value = new FloatEntityData(key, stream.getLFloat());
                break;
            case Entity.DATA_TYPE_STRING:
                value = new StringEntityData(key, stream.getString());
                break;
            case Entity.DATA_TYPE_SLOT:
                Item item = stream.getSlot();
                value = new SlotEntityData(key, item.getId(), item.getDamage(), item.getCount());
                break;
            case Entity.DATA_TYPE_POS:
                BlockVector3 v3 = stream.getSignedBlockPosition();
                value = new IntPositionEntityData(key, v3.x, v3.y, v3.z);
                break;
            case Entity.DATA_TYPE_LONG:
                value = new LongEntityData(key, stream.getVarLong());
                break;
            case Entity.DATA_TYPE_VECTOR3F:
                value = new Vector3fEntityData(key, stream.getVector3f());
                break;
        }
        if (value != null) m.put(value);
    }
    return m;
}
 
开发者ID:Rsplwe,项目名称:Nukkit-Java9,代码行数:45,代码来源:Binary.java

示例14: SlotEntityData

import cn.nukkit.item.Item; //导入方法依赖的package包/类
public SlotEntityData(int id, Item item) {
    this(id, item.getId(), (byte) (item.hasMeta() ? item.getDamage() : 0), item.getCount());
}
 
开发者ID:FrontierDevs,项目名称:Jenisys3,代码行数:4,代码来源:SlotEntityData.java


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