Search in sources :

Example 26 with ItemStack

use of net.minecraft.server.v1_9_R2.ItemStack in project Denizen-For-Bukkit by DenizenScript.

the class ItemHelper_v1_9_R2 method addNbtData.

@Override
public ItemStack addNbtData(ItemStack itemStack, String key, Tag value) {
    net.minecraft.server.v1_9_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound tag = nmsItemStack.hasTag() ? nmsItemStack.getTag() : new NBTTagCompound();
    CompoundTag compound = CompoundTag_v1_9_R2.fromNMSTag(tag).createBuilder().put(key, value).build();
    nmsItemStack.setTag(((CompoundTag_v1_9_R2) compound).toNMSTag());
    return CraftItemStack.asBukkitCopy(nmsItemStack);
}
Also used : CompoundTag_v1_9_R2(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_9_R2) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound)

Example 27 with ItemStack

use of net.minecraft.server.v1_9_R2.ItemStack in project Denizen-For-Bukkit by DenizenScript.

the class ItemHelper_v1_9_R2 method setSkullSkin.

@Override
public ItemStack setSkullSkin(ItemStack itemStack, PlayerProfile playerProfile) {
    GameProfile gameProfile = new GameProfile(playerProfile.getUniqueId(), playerProfile.getName());
    if (playerProfile.hasTexture()) {
        gameProfile.getProperties().get("textures").clear();
        if (playerProfile.getTextureSignature() != null) {
            gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture(), playerProfile.getTextureSignature()));
        } else {
            gameProfile.getProperties().put("textures", new Property("textures", playerProfile.getTexture()));
        }
    }
    net.minecraft.server.v1_9_R2.ItemStack nmsItemStack = CraftItemStack.asNMSCopy(itemStack);
    NBTTagCompound tag = nmsItemStack.hasTag() ? nmsItemStack.getTag() : new NBTTagCompound();
    tag.set("SkullOwner", GameProfileSerializer.serialize(new NBTTagCompound(), gameProfile));
    nmsItemStack.setTag(tag);
    return CraftItemStack.asBukkitCopy(nmsItemStack);
}
Also used : GameProfile(com.mojang.authlib.GameProfile) CompoundTag_v1_9_R2(net.aufdemrand.denizen.nms.impl.jnbt.CompoundTag_v1_9_R2) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) Property(com.mojang.authlib.properties.Property)

Example 28 with ItemStack

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

the class IconMenuInventory method open.

@Override
public void open(IconMenu menu, HumanEntity player) {
    size = menu.getSize();
    minecraftInventory = new CustomInventory(size, menu.getTitle());
    for (int slot = 0; slot < size; slot++) {
        IconMenuItem menuItem = menu.getOption(slot);
        if (menuItem != null) {
            ItemStack item = createItemStack(menuItem);
            minecraftInventory.setItem(slot, item);
        }
    }
    player.openInventory(minecraftInventory.getBukkitInventory());
}
Also used : IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_10_R1.ItemStack) CustomInventory(de.Keyle.MyPet.compat.v1_10_R1.util.inventory.CustomInventory)

Example 29 with ItemStack

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

the class IconMenuInventory method createItemStack.

protected ItemStack createItemStack(IconMenuItem icon) {
    ItemStack is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(icon.getMaterial(), icon.getAmount(), (short) icon.getData()));
    // TODO allow items like FIRE (51)
    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));
        }
    }
    if (icon.getTags() != null) {
        NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags());
        for (String key : vanillaTag.c()) {
            is.getTag().set(key, vanillaTag.get(key));
        }
    }
    return is;
}
Also used : NBTTagCompound(net.minecraft.server.v1_10_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_10_R1.NBTTagString) NBTTagCompound(net.minecraft.server.v1_10_R1.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) NBTTagList(net.minecraft.server.v1_10_R1.NBTTagList) NBTTagString(net.minecraft.server.v1_10_R1.NBTTagString) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_10_R1.ItemStack)

Example 30 with ItemStack

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

the class IconMenuInventory method update.

@Override
public void update(IconMenu menu) {
    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) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_10_R1.ItemStack)

Aggregations

IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)18 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)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 ItemStack (net.minecraft.server.v1_8_R3.ItemStack)7 CraftItemStack (org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)5 ItemStack (net.minecraft.server.v1_10_R1.ItemStack)3 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)3 ItemStack (net.minecraft.server.v1_12_R1.ItemStack)3 ItemStack (net.minecraft.server.v1_9_R1.ItemStack)3 ItemStack (net.minecraft.server.v1_9_R2.ItemStack)3 NBTTagString (net.minecraft.server.v1_9_R2.NBTTagString)3 CraftItemStack (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)3 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)2