Search in sources :

Example 6 with CraftItemStack

use of org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack in project MyPet by xXKeyleXx.

the class CustomInventory method addItem.

@Override
public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
    if (itemAdd == null) {
        return 0;
    }
    itemAdd = itemAdd.clone();
    for (int i = 0; i < this.getSize(); i++) {
        CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
        if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
            if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
                continue;
            }
            while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
                craftItem.setAmount(craftItem.getAmount() + 1);
                itemAdd.setAmount(itemAdd.getAmount() - 1);
            }
            if (itemAdd.getAmount() == 0) {
                break;
            }
        }
    }
    if (itemAdd.getAmount() > 0) {
        for (int i = 0; i < this.getSize(); i++) {
            if (getItem(i) == ItemStack.b) {
                if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
                    setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
                    itemAdd.setAmount(0);
                    break;
                } else {
                    CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
                    itemStack.setAmount(itemStack.getMaxStackSize());
                    setItem(i, CraftItemStack.asNMSCopy(itemStack));
                    itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
                }
                if (itemAdd.getAmount() == 0) {
                    break;
                }
            }
        }
    }
    return itemAdd.getAmount();
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)

Example 7 with CraftItemStack

use of org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack in project MyPet by xXKeyleXx.

the class CustomInventory method addItem.

@Override
public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
    if (itemAdd == null) {
        return 0;
    }
    itemAdd = itemAdd.clone();
    for (int i = 0; i < this.getContainerSize(); i++) {
        CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
        if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
            if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
                continue;
            }
            while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
                craftItem.setAmount(craftItem.getAmount() + 1);
                itemAdd.setAmount(itemAdd.getAmount() - 1);
            }
            if (itemAdd.getAmount() == 0) {
                break;
            }
        }
    }
    if (itemAdd.getAmount() > 0) {
        for (int i = 0; i < this.getContainerSize(); i++) {
            if (getItem(i) == ItemStack.EMPTY) {
                if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
                    setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
                    itemAdd.setAmount(0);
                    break;
                } else {
                    CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
                    itemStack.setAmount(itemStack.getMaxStackSize());
                    setItem(i, CraftItemStack.asNMSCopy(itemStack));
                    itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
                }
                if (itemAdd.getAmount() == 0) {
                    break;
                }
            }
        }
    }
    return itemAdd.getAmount();
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)

Example 8 with CraftItemStack

use of org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack in project MyPet by xXKeyleXx.

the class CustomInventory method addItem.

@Override
public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
    if (itemAdd == null) {
        return 0;
    }
    itemAdd = itemAdd.clone();
    for (int i = 0; i < this.getContainerSize(); i++) {
        CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
        if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
            if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
                continue;
            }
            while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
                craftItem.setAmount(craftItem.getAmount() + 1);
                itemAdd.setAmount(itemAdd.getAmount() - 1);
            }
            if (itemAdd.getAmount() == 0) {
                break;
            }
        }
    }
    if (itemAdd.getAmount() > 0) {
        for (int i = 0; i < this.getContainerSize(); i++) {
            if (getItem(i) == ItemStack.EMPTY) {
                if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
                    setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
                    itemAdd.setAmount(0);
                    break;
                } else {
                    CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
                    itemStack.setAmount(itemStack.getMaxStackSize());
                    setItem(i, CraftItemStack.asNMSCopy(itemStack));
                    itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
                }
                if (itemAdd.getAmount() == 0) {
                    break;
                }
            }
        }
    }
    return itemAdd.getAmount();
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)

Example 9 with CraftItemStack

use of org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack in project MyPet by xXKeyleXx.

the class CustomInventory method addItem.

public int addItem(org.bukkit.inventory.ItemStack itemAdd) {
    if (itemAdd == null) {
        return 0;
    }
    itemAdd = itemAdd.clone();
    for (int i = 0; i < this.getSize(); i++) {
        CraftItemStack craftItem = CraftItemStack.asCraftMirror(getItem(i));
        if (ItemStackComparator.compareItem(itemAdd, craftItem)) {
            if (craftItem.getAmount() >= craftItem.getMaxStackSize()) {
                continue;
            }
            while (craftItem.getAmount() < craftItem.getMaxStackSize() && itemAdd.getAmount() > 0) {
                craftItem.setAmount(craftItem.getAmount() + 1);
                itemAdd.setAmount(itemAdd.getAmount() - 1);
            }
            if (itemAdd.getAmount() == 0) {
                break;
            }
        }
    }
    if (itemAdd.getAmount() > 0) {
        for (int i = 0; i < this.getSize(); i++) {
            if (getItem(i) == ItemStack.b) {
                if (itemAdd.getAmount() <= itemAdd.getMaxStackSize()) {
                    setItem(i, CraftItemStack.asNMSCopy(itemAdd.clone()));
                    itemAdd.setAmount(0);
                    break;
                } else {
                    CraftItemStack itemStack = (CraftItemStack) itemAdd.clone();
                    itemStack.setAmount(itemStack.getMaxStackSize());
                    setItem(i, CraftItemStack.asNMSCopy(itemStack));
                    itemAdd.setAmount(itemAdd.getAmount() - itemStack.getMaxStackSize());
                }
                if (itemAdd.getAmount() == 0) {
                    break;
                }
            }
        }
    }
    return itemAdd.getAmount();
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack)

Example 10 with CraftItemStack

use of org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack in project Essentials by drtshock.

the class v1_8_R1SpawnerProvider method getEntityType.

@Override
public EntityType getEntityType(ItemStack is) {
    net.minecraft.server.v1_8_R1.ItemStack itemStack;
    CraftItemStack craftStack = CraftItemStack.asCraftCopy(is);
    itemStack = CraftItemStack.asNMSCopy(craftStack);
    NBTTagCompound tag = itemStack.getTag();
    if (tag == null || !tag.hasKey("BlockEntityTag")) {
        throw new IllegalArgumentException();
    }
    String name = tag.getCompound("BlockEntityTag").getString("EntityId");
    return EntityType.fromName(name);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R1.NBTTagCompound)

Aggregations

CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)5 CraftItemStack (org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack)5 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)4 NBTTagCompound (net.minecraft.server.v1_8_R2.NBTTagCompound)4 ItemStack (org.bukkit.inventory.ItemStack)4 CraftItemStack (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)1 CraftItemStack (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)1 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)1 CraftItemStack (org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack)1 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)1 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)1 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)1 CraftItemStack (org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)1 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)1 CraftItemStack (org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack)1 CraftItemStack (org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)1