Search in sources :

Example 76 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack in project WLib by WizardlyBump17.

the class PacketListener method setSlot.

@SneakyThrows
private void setSlot(PacketPlayOutSetSlot packet) {
    final Field field = packet.getClass().getDeclaredField("f");
    field.setAccessible(true);
    final net.minecraft.world.item.ItemStack stack = (net.minecraft.world.item.ItemStack) field.get(packet);
    final CraftItemStack newItemStack = CraftItemStack.asCraftMirror(stack);
    if (!isValidItem(newItemStack))
        return;
    field.set(packet, CraftItemStack.asNMSCopy(fixItem(newItemStack)));
}
Also used : Field(java.lang.reflect.Field) CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack) SneakyThrows(lombok.SneakyThrows)

Example 77 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.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) == null) {
                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_8_R3.inventory.CraftItemStack)

Example 78 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.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.a) {
                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_12_R1.inventory.CraftItemStack)

Example 79 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.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) == null) {
                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_9_R2.inventory.CraftItemStack)

Example 80 with CraftItemStack

use of org.bukkit.craftbukkit.v1_18_R2.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

ItemStack (org.bukkit.inventory.ItemStack)35 Nullable (javax.annotation.Nullable)27 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)25 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)20 CraftItemStack (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack)17 CompoundTag (net.minecraft.nbt.CompoundTag)15 Material (org.bukkit.Material)14 Block (org.bukkit.block.Block)13 Field (java.lang.reflect.Field)11 SneakyThrows (lombok.SneakyThrows)11 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 Player (org.bukkit.entity.Player)9 BlockFace (org.bukkit.block.BlockFace)8 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)8 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)8 ArrayList (java.util.ArrayList)7 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_13_R2.inventory.CraftItemStack)6