Search in sources :

Example 6 with CraftItemStack

use of org.bukkit.craftbukkit.v1_14_R1.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_14_R1.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_14_R1.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_14_R1.inventory.CraftItemStack in project Essentials by EssentialsX.

the class v1_8_R2SpawnerProvider method getEntityType.

@Override
public EntityType getEntityType(ItemStack is) {
    net.minecraft.server.v1_8_R2.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_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R2.NBTTagCompound)

Example 10 with CraftItemStack

use of org.bukkit.craftbukkit.v1_14_R1.inventory.CraftItemStack in project EverNifeCore by EverNife.

the class NMSUtils_v1_12_R1 method getHandle.

private ItemStack getHandle(org.bukkit.inventory.ItemStack itemStack) {
    Validate.notNull(itemStack, "itemStack can not be null!");
    try {
        CraftItemStack craftItemStack = (CraftItemStack) itemStack;
        ItemStack mcStack = (ItemStack) handle_field.get(craftItemStack);
        return mcStack;
    } catch (Exception e) {
        Class c = itemStack.getClass();
        EverNifeCore.warning("Failed to get ItemStack Handle for:" + "\n" + "\nPackage: " + c.getPackage() + "" + "\nClass: " + c.getSimpleName() + "" + "\nFull Identifier: " + c.getName());
        e.printStackTrace();
        throw new RuntimeException(e);
    }
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)

Aggregations

Nullable (javax.annotation.Nullable)27 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)23 ItemStack (org.bukkit.inventory.ItemStack)23 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)19 CompoundTag (net.minecraft.nbt.CompoundTag)15 CraftItemStack (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack)15 Material (org.bukkit.Material)14 Block (org.bukkit.block.Block)13 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 Player (org.bukkit.entity.Player)9 BlockFace (org.bukkit.block.BlockFace)8 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)8 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)7 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)7 CraftLivingEntity (org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity)7 CraftItemStack (org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack)6 CraftPlayer (org.bukkit.craftbukkit.v1_16_R3.entity.CraftPlayer)6 CraftItemStack (org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)6 NBTTagCompound (net.minecraft.server.v1_13_R2.NBTTagCompound)5 NBTTagCompound (net.minecraft.server.v1_16_R1.NBTTagCompound)5