Java Code Examples for org.bukkit.inventory.ItemStack#getTypeId()

The following examples show how to use org.bukkit.inventory.ItemStack#getTypeId() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CraftInventoryPlayer.java    From Kettle with GNU General Public License v3.0 6 votes vote down vote up
public int clear(int id, int data) {
    int count = 0;
    ItemStack[] items = getContents();

    for (int i = 0; i < items.length; i++) {
        ItemStack item = items[i];
        if (item == null) continue;
        if (id > -1 && item.getTypeId() != id) continue;
        if (data > -1 && item.getData().getData() != data) continue;

        count += item.getAmount();
        setItem(i, null);
    }

    return count;
}
 
Example 2
Source File: ProtocolItemListener.java    From Carbon with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("deprecation")
private void replaceItemStack(ItemStack itemStack) {
	if (itemStack == null) {
		return;
	}
	int itemid = itemStack.getTypeId();
	if (replacements[itemid] != -1) {
		itemStack.setTypeId(replacements[itemid]);
	}
}
 
Example 3
Source File: BrushBoundBaseBlock.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
public BrushBoundBaseBlock(Player player, LocalSession session, ItemStack item) {
    super(item.getTypeId(), item.getType().getMaxDurability() != 0 || item.getDurability() > 15 ? 0 : Math.max(0, item.getDurability()), getNBT(item));
    this.item = item;
    this.tool = brushCache.get(getKey(item));
    this.player = player;
    this.session = session;
}
 
Example 4
Source File: CraftShapelessRecipe.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void addToCraftingManager() {
    List<ItemStack> ingred = this.getIngredientList();
    Object[] data = new Object[ingred.size()];
    int i = 0;
    for (ItemStack mdata : ingred) {
        int id = mdata.getTypeId();
        short dmg = mdata.getDurability();
        data[i] = new net.minecraft.item.ItemStack(CraftMagicNumbers.getItem(id), 1, dmg);
        i++;
    }
    net.minecraft.item.crafting.CraftingManager.getInstance().addShapelessRecipe(CraftItemStack.asNMSCopy(this.getResult()), data);
}
 
Example 5
Source File: CraftInventory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public int firstPartial(int materialId) {
    ItemStack[] inventory = getContents();
    for (int i = 0; i < inventory.length; i++) {
        ItemStack item = inventory[i];
        if (item != null && item.getTypeId() == materialId && item.getAmount() < item.getMaxStackSize()) {
            return i;
        }
    }
    return -1;
}
 
Example 6
Source File: CraftInventory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public int first(int materialId) {
    ItemStack[] inventory = getContents();
    for (int i = 0; i < inventory.length; i++) {
        ItemStack item = inventory[i];
        if (item != null && item.getTypeId() == materialId) {
            return i;
        }
    }
    return -1;
}
 
Example 7
Source File: CraftInventory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public boolean contains(int materialId, int amount) {
    if (amount <= 0) {
        return true;
    }
    for (ItemStack item : getContents()) {
        if (item != null && item.getTypeId() == materialId) {
            if ((amount -= item.getAmount()) <= 0) {
                return true;
            }
        }
    }
    return false;
}
 
Example 8
Source File: CraftInventory.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public boolean contains(int materialId) {
    for (ItemStack item : getContents()) {
        if (item != null && item.getTypeId() == materialId) {
            return true;
        }
    }
    return false;
}
 
Example 9
Source File: CraftInventoryPlayer.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setArmorContents(ItemStack[] items) {
    int cnt = getSize();

    if (items == null) {
        items = new ItemStack[4];
    }
    for (ItemStack item : items) {
        if (item == null || item.getTypeId() == 0) {
            clear(cnt++);
        } else {
            setItem(cnt++, item);
        }
    }
}
 
Example 10
Source File: CraftInventoryCrafting.java    From Thermos with GNU General Public License v3.0 5 votes vote down vote up
public void setResult(ItemStack item) {
    net.minecraft.item.ItemStack[] contents = getResultInventory().getContents();
    if (item == null || item.getTypeId() <= 0) {
        contents[0] = null;
    } else {
        contents[0] = CraftItemStack.asNMSCopy(item);
    }
}
 
Example 11
Source File: BukkitPlayer.java    From FastAsyncWorldedit with GNU General Public License v3.0 5 votes vote down vote up
@Override
public BaseBlock getBlockInHand() throws WorldEditException {
    ItemStack itemStack = player.getItemInHand();
    if (itemStack == null) {
        return EditSession.nullBlock;
    }
    final int typeId = itemStack.getTypeId();
    switch (typeId) {
        case 0:
            return EditSession.nullBlock;
        case ItemID.INK_SACK:
            final Dye materialData = (Dye) itemStack.getData();
            if (materialData.getColor() == DyeColor.BROWN) {
                return FaweCache.getBlock(BlockID.COCOA_PLANT, 0);
            }
            break;
        case ItemID.HEAD:
            return new SkullBlock(0, (byte) itemStack.getDurability());

        default:
            final BaseBlock baseBlock = BlockType.getBlockForItem(typeId, itemStack.getDurability());
            if (baseBlock != null) {
                return baseBlock;
            }
            break;
    }
    BaseBlock block = FaweCache.getBlock(typeId, itemStack.getType().getMaxDurability() != 0 ? 0 : Math.max(0, itemStack.getDurability()));
    if (Settings.IMP.EXPERIMENTAL.PERSISTENT_BRUSHES && Fawe.<FaweBukkit>imp().getItemUtil() != null) {
        return new BrushBoundBaseBlock(this, WorldEdit.getInstance().getSession(this), itemStack);
    }
    return block;
}
 
Example 12
Source File: CraftInventory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public int firstPartial(int materialId) {
    ItemStack[] inventory = getStorageContents();
    for (int i = 0; i < inventory.length; i++) {
        ItemStack item = inventory[i];
        if (item != null && item.getTypeId() == materialId && item.getAmount() < item.getMaxStackSize()) {
            return i;
        }
    }
    return -1;
}
 
Example 13
Source File: CraftInventory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public int first(int materialId) {
    ItemStack[] inventory = getStorageContents();
    for (int i = 0; i < inventory.length; i++) {
        ItemStack item = inventory[i];
        if (item != null && item.getTypeId() == materialId) {
            return i;
        }
    }
    return -1;
}
 
Example 14
Source File: CraftInventory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public HashMap<Integer, ItemStack> all(int materialId) {
    HashMap<Integer, ItemStack> slots = new HashMap<Integer, ItemStack>();

    ItemStack[] inventory = getStorageContents();
    for (int i = 0; i < inventory.length; i++) {
        ItemStack item = inventory[i];
        if (item != null && item.getTypeId() == materialId) {
            slots.put(i, item);
        }
    }
    return slots;
}
 
Example 15
Source File: CraftInventory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public boolean contains(int materialId, int amount) {
    if (amount <= 0) {
        return true;
    }
    for (ItemStack item : getStorageContents()) {
        if (item != null && item.getTypeId() == materialId) {
            if ((amount -= item.getAmount()) <= 0) {
                return true;
            }
        }
    }
    return false;
}
 
Example 16
Source File: CraftInventory.java    From Kettle with GNU General Public License v3.0 5 votes vote down vote up
public boolean contains(int materialId) {
    for (ItemStack item : getStorageContents()) {
        if (item != null && item.getTypeId() == materialId) {
            return true;
        }
    }
    return false;
}
 
Example 17
Source File: BukkitPlayerBlockBag.java    From FastAsyncWorldedit with GNU General Public License v3.0 4 votes vote down vote up
@Override
public void storeItem(BaseItem item) throws BlockBagException {
    final int id = item.getType();
    final int damage = item.getData();
    int amount = (item instanceof BaseItemStack) ? ((BaseItemStack) item).getAmount() : 1;
    assert(amount <= 64);
    boolean usesDamageValue = ItemType.usesDamageValue(id);

    if (id == BlockID.AIR) {
        throw new IllegalArgumentException("Can't store air block");
    }

    loadInventory();

    int freeSlot = -1;

    for (int slot = 0; slot < items.length; ++slot) {
        ItemStack bukkitItem = items[slot];

        if (bukkitItem == null) {
            // Delay using up a free slot until we know there are no stacks
            // of this item to merge into

            if (freeSlot == -1) {
                freeSlot = slot;
            }
            continue;
        }

        if (bukkitItem.getTypeId() != id) {
            // Type id doesn't fit
            continue;
        }

        if (usesDamageValue && bukkitItem.getDurability() != damage) {
            // Damage value doesn't fit.
            continue;
        }

        int currentAmount = bukkitItem.getAmount();
        if (currentAmount < 0) {
            // Unlimited
            return;
        }
        if (currentAmount >= 64) {
            // Full stack
            continue;
        }

        int spaceLeft = 64 - currentAmount;
        if (spaceLeft >= amount) {
            bukkitItem.setAmount(currentAmount + amount);
            return;
        }

        bukkitItem.setAmount(64);
        amount -= spaceLeft;
    }

    if (freeSlot > -1) {
        items[freeSlot] = new ItemStack(id, amount);
        return;
    }

    throw new OutOfSpaceException(id);
}
 
Example 18
Source File: HandItemCache.java    From ViaVersion with MIT License 4 votes vote down vote up
public static Item convert(ItemStack itemInHand) {
    if (itemInHand == null) return new Item(0, (byte) 0, (short) 0, null);
    return new Item(itemInHand.getTypeId(), (byte) itemInHand.getAmount(), itemInHand.getDurability(), null);
}
 
Example 19
Source File: ItemManager.java    From civcraft with GNU General Public License v2.0 4 votes vote down vote up
@SuppressWarnings("deprecation")
public static int getId(ItemStack stack) {
	return stack.getTypeId();
}
 
Example 20
Source File: CraftItemStack.java    From Kettle with GNU General Public License v3.0 4 votes vote down vote up
private CraftItemStack(ItemStack item) {
    this(item.getTypeId(), item.getAmount(), item.getDurability(), item.hasItemMeta() ? item.getItemMeta() : null);
}