Search in sources :

Example 66 with CraftItemStack

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project LoliServer by Loli-Server.

the class CraftEventFactory method callEntityShootBowEvent.

/**
 * EntityShootBowEvent
 */
public static EntityShootBowEvent callEntityShootBowEvent(LivingEntity who, ItemStack bow, ItemStack consumableItem, Entity entityArrow, Hand hand, float force, boolean consumeItem) {
    org.bukkit.entity.LivingEntity shooter = (org.bukkit.entity.LivingEntity) who.getBukkitEntity();
    CraftItemStack itemInHand = CraftItemStack.asCraftMirror(bow);
    CraftItemStack itemConsumable = CraftItemStack.asCraftMirror(consumableItem);
    org.bukkit.entity.Entity arrow = entityArrow.getBukkitEntity();
    EquipmentSlot handSlot = (hand == Hand.MAIN_HAND) ? EquipmentSlot.HAND : EquipmentSlot.OFF_HAND;
    if (itemInHand != null && (itemInHand.getType() == Material.AIR || itemInHand.getAmount() == 0)) {
        itemInHand = null;
    }
    EntityShootBowEvent event = new EntityShootBowEvent(shooter, itemInHand, itemConsumable, arrow, handSlot, force, consumeItem);
    Bukkit.getPluginManager().callEvent(event);
    return event;
}
Also used : LivingEntity(net.minecraft.entity.LivingEntity) CraftLivingEntity(org.bukkit.craftbukkit.v1_16_R3.entity.CraftLivingEntity) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) EquipmentSlot(org.bukkit.inventory.EquipmentSlot) org.bukkit.event.entity(org.bukkit.event.entity) org.bukkit.entity(org.bukkit.entity)

Example 67 with CraftItemStack

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project MyPet by MyPetORG.

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 68 with CraftItemStack

use of org.bukkit.craftbukkit.v1_13_R2.inventory.CraftItemStack in project MyPet by MyPetORG.

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 69 with CraftItemStack

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

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 70 with CraftItemStack

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

the class v1_8_R2SpawnerProvider method setEntityType.

@Override
public ItemStack setEntityType(ItemStack is, EntityType type) {
    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 = new NBTTagCompound();
        itemStack.setTag(tag);
    }
    if (!tag.hasKey("BlockEntityTag")) {
        tag.set("BlockEntityTag", new NBTTagCompound());
    }
    tag = itemStack.getTag().getCompound("BlockEntityTag");
    tag.setString("EntityId", type.getName());
    ItemStack bukkitItemStack = CraftItemStack.asCraftMirror(itemStack).clone();
    return setDisplayName(bukkitItemStack, type);
}
Also used : CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R2.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)34 Nullable (javax.annotation.Nullable)27 CraftItemStack (org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack)27 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)22 CraftItemStack (org.bukkit.craftbukkit.v1_18_R2.inventory.CraftItemStack)18 CompoundTag (net.minecraft.nbt.CompoundTag)15 Material (org.bukkit.Material)14 Block (org.bukkit.block.Block)13 Field (java.lang.reflect.Field)12 SneakyThrows (lombok.SneakyThrows)11 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)9 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)9 Player (org.bukkit.entity.Player)9 BlockFace (org.bukkit.block.BlockFace)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 CraftItemStack (org.bukkit.craftbukkit.v1_16_R1.inventory.CraftItemStack)7 CraftWorld (org.bukkit.craftbukkit.v1_16_R3.CraftWorld)7