Search in sources :

Example 51 with ItemStack

use of net.minecraft.server.v1_8_R1.ItemStack in project MyPet by xXKeyleXx.

the class IconMenuInventory method createItemStack.

protected ItemStack createItemStack(IconMenuItem icon) {
    ItemStack is = CraftItemStack.asNMSCopy(CraftItemStack.asCraftCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount(), (short) icon.getData())));
    if (is == null) {
        is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.SAPLING));
    }
    NBTTagList emptyList = new NBTTagList();
    if (is.getTag() == null) {
        is.setTag(new NBTTagCompound());
    }
    if (icon.getBukkitMeta() != null) {
        try {
            applyToItemMethhod.invoke(icon.getBukkitMeta(), is.getTag());
        } catch (InvocationTargetException | IllegalAccessException e) {
            e.printStackTrace();
        }
    }
    // remove item attributes like attack damage
    is.getTag().set("AttributeModifiers", emptyList);
    // add enchantment glowing
    if (icon.isGlowing()) {
        is.getTag().set("ench", emptyList);
    } else {
        is.getTag().remove("ench");
    }
    // Prepare display tag
    NBTTagCompound display;
    if (is.getTag().hasKey("display")) {
        display = is.getTag().getCompound("display");
    } else {
        display = new NBTTagCompound();
        is.getTag().set("display", display);
    }
    // set Title
    if (!icon.getTitle().equals("")) {
        display.setString("Name", icon.getTitle());
    }
    if (icon.getLore().size() > 0) {
        // set Lore
        NBTTagList loreTag = new NBTTagList();
        display.set("Lore", loreTag);
        for (String loreLine : icon.getLore()) {
            loreTag.add(new NBTTagString(loreLine));
        }
    }
    if (icon.hasMeta()) {
        TagCompound tag = new TagCompound();
        icon.getMeta().applyTo(tag);
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
        for (String key : vanillaTag.c()) {
            is.getTag().set(key, vanillaTag.get(key));
        }
    }
    return is;
}
Also used : NBTTagList(net.minecraft.server.v1_8_R3.NBTTagList) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) NBTTagString(net.minecraft.server.v1_8_R3.NBTTagString) NBTTagString(net.minecraft.server.v1_8_R3.NBTTagString) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R3.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 52 with ItemStack

use of net.minecraft.server.v1_8_R1.ItemStack in project MyPet by xXKeyleXx.

the class IconMenuInventory method update.

@Override
public void update(IconMenu menu) {
    if (minecraftInventory != null) {
        for (int slot = 0; slot < size; slot++) {
            IconMenuItem menuItem = menu.getOption(slot);
            if (menuItem != null) {
                ItemStack item = createItemStack(menuItem);
                minecraftInventory.setItem(slot, item);
            } else {
                minecraftInventory.setItem(slot, null);
            }
        }
    }
}
Also used : IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) ItemStack(net.minecraft.server.v1_8_R3.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)

Example 53 with ItemStack

use of net.minecraft.server.v1_8_R1.ItemStack in project MyPet by xXKeyleXx.

the class EntityMyBlaze method handlePlayerInteraction.

public boolean handlePlayerInteraction(EntityHuman entityhuman) {
    if (super.handlePlayerInteraction(entityhuman)) {
        return true;
    }
    ItemStack itemStack = entityhuman.inventory.getItemInHand();
    if (getOwner().equals(entityhuman) && itemStack != null && canUseItem()) {
        if (getMyPet().isOnFire() && itemStack.getItem() == Items.GLASS_BOTTLE && itemStack.getData() == 0 && getOwner().getPlayer().isSneaking()) {
            getMyPet().setOnFire(false);
            makeSound("random.fizz", 1.0F, 1.0F);
            if (!entityhuman.abilities.canInstantlyBuild) {
                if (--itemStack.count <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, new ItemStack(Items.GLASS_BOTTLE));
                } else {
                    if (!entityhuman.inventory.pickup(new ItemStack(Items.GLASS_BOTTLE))) {
                        entityhuman.drop(new ItemStack(Items.GLASS_BOTTLE), true);
                    }
                }
            }
            return true;
        } else if (!getMyPet().isOnFire() && itemStack.getItem() == Items.FLINT_AND_STEEL && getOwner().getPlayer().isSneaking()) {
            getMyPet().setOnFire(true);
            makeSound("fire.ignite", 1.0F, 1.0F);
            if (!entityhuman.abilities.canInstantlyBuild) {
                itemStack.damage(1, entityhuman);
            }
            return true;
        }
    }
    return false;
}
Also used : ItemStack(net.minecraft.server.v1_8_R3.ItemStack)

Example 54 with ItemStack

use of net.minecraft.server.v1_8_R1.ItemStack in project MyPet by xXKeyleXx.

the class EntityMyMooshroom method handlePlayerInteraction.

public boolean handlePlayerInteraction(final EntityHuman entityhuman) {
    if (super.handlePlayerInteraction(entityhuman)) {
        return true;
    }
    ItemStack itemStack = entityhuman.inventory.getItemInHand();
    if (itemStack != null) {
        if (itemStack.getItem().equals(Items.BOWL)) {
            if (!getOwner().equals(entityhuman) || !canUseItem() || !Configuration.MyPet.Mooshroom.CAN_GIVE_SOUP) {
                final int itemInHandIndex = entityhuman.inventory.itemInHandIndex;
                ItemStack is = new ItemStack(Items.MUSHROOM_STEW);
                final ItemStack oldIs = entityhuman.inventory.getItem(itemInHandIndex);
                entityhuman.inventory.setItem(itemInHandIndex, is);
                Bukkit.getScheduler().scheduleSyncDelayedTask(MyPetApi.getPlugin(), () -> entityhuman.inventory.setItem(itemInHandIndex, oldIs), 2L);
            } else {
                if (--itemStack.count <= 0) {
                    entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, new ItemStack(Items.MUSHROOM_STEW));
                } else {
                    if (!entityhuman.inventory.pickup(new ItemStack(Items.MUSHROOM_STEW))) {
                        entityhuman.drop(new ItemStack(Items.MUSHROOM_STEW), true);
                    }
                }
                return true;
            }
        }
        if (getOwner().equals(entityhuman) && canUseItem()) {
            if (Configuration.MyPet.Mooshroom.GROW_UP_ITEM.compare(itemStack) && getMyPet().isBaby() && getOwner().getPlayer().isSneaking()) {
                if (!entityhuman.abilities.canInstantlyBuild) {
                    if (--itemStack.count <= 0) {
                        entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
                    }
                }
                getMyPet().setBaby(false);
                return true;
            }
        }
    }
    return false;
}
Also used : ItemStack(net.minecraft.server.v1_8_R3.ItemStack)

Example 55 with ItemStack

use of net.minecraft.server.v1_8_R1.ItemStack in project Essentials by EssentialsX.

the class v1_8_R1SpawnerProvider method setEntityType.

@Override
public ItemStack setEntityType(ItemStack is, EntityType type) {
    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 = 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_R1.inventory.CraftItemStack) NBTTagCompound(net.minecraft.server.v1_8_R1.NBTTagCompound) CraftItemStack(org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Aggregations

IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)18 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)9 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)8 ItemStack (net.minecraft.server.v1_8_R3.ItemStack)8 ItemStack (net.minecraft.server.v1_7_R4.ItemStack)7 ItemStack (net.minecraft.server.v1_8_R1.ItemStack)7 ItemStack (net.minecraft.server.v1_8_R2.ItemStack)7 NBTTagString (net.minecraft.server.v1_8_R1.NBTTagString)5 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)4 ListTag (com.wasteofplastic.org.jnbt.ListTag)4 StringTag (com.wasteofplastic.org.jnbt.StringTag)4 Tag (com.wasteofplastic.org.jnbt.Tag)4 Map (java.util.Map)4 ItemStack (net.minecraft.server.v1_10_R1.ItemStack)4 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)4 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)4 CraftItemStack (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)4 CraftItemStack (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)4