Search in sources :

Example 46 with ItemStack

use of net.minecraft.server.v1_8_R1.ItemStack in project askyblock by tastybento.

the class NMSHandler method setPotion.

@Override
public ItemStack setPotion(Material itemMaterial, Tag itemTags, ItemStack chestItem) {
    // Try some backwards compatibility with new 1.9 schematics
    Map<String, Tag> cont = (Map<String, Tag>) ((CompoundTag) itemTags).getValue();
    if (cont != null) {
        if (((CompoundTag) itemTags).getValue().containsKey("tag")) {
            Map<String, Tag> contents = (Map<String, Tag>) ((CompoundTag) itemTags).getValue().get("tag").getValue();
            StringTag stringTag = ((StringTag) contents.get("Potion"));
            if (stringTag != null) {
                String tag = stringTag.getValue().replace("minecraft:", "");
                PotionType type = null;
                boolean strong = tag.contains("strong");
                boolean _long = tag.contains("long");
                // Bukkit.getLogger().info("tag = " + tag);
                if (tag.equals("fire_resistance") || tag.equals("long_fire_resistance")) {
                    type = PotionType.FIRE_RESISTANCE;
                } else if (tag.equals("harming") || tag.equals("strong_harming")) {
                    type = PotionType.INSTANT_DAMAGE;
                } else if (tag.equals("healing") || tag.equals("strong_healing")) {
                    type = PotionType.INSTANT_HEAL;
                } else if (tag.equals("invisibility") || tag.equals("long_invisibility")) {
                    type = PotionType.INVISIBILITY;
                } else if (tag.equals("leaping") || tag.equals("long_leaping") || tag.equals("strong_leaping")) {
                    type = PotionType.JUMP;
                } else if (tag.equals("night_vision") || tag.equals("long_night_vision")) {
                    type = PotionType.NIGHT_VISION;
                } else if (tag.equals("poison") || tag.equals("long_poison") || tag.equals("strong_poison")) {
                    type = PotionType.POISON;
                } else if (tag.equals("regeneration") || tag.equals("long_regeneration") || tag.equals("strong_regeneration")) {
                    type = PotionType.REGEN;
                } else if (tag.equals("slowness") || tag.equals("long_slowness")) {
                    type = PotionType.SLOWNESS;
                } else if (tag.equals("swiftness") || tag.equals("long_swiftness") || tag.equals("strong_swiftness")) {
                    type = PotionType.SPEED;
                } else if (tag.equals("strength") || tag.equals("long_strength") || tag.equals("strong_strength")) {
                    type = PotionType.STRENGTH;
                } else if (tag.equals("water_breathing") || tag.equals("long_water_breathing")) {
                    type = PotionType.WATER_BREATHING;
                } else if (tag.equals("water")) {
                    type = PotionType.WATER;
                } else if (tag.equals("weakness") || tag.equals("long_weakness")) {
                    type = PotionType.WEAKNESS;
                } else {
                    return chestItem;
                }
                Potion potion = new Potion(type);
                potion.setHasExtendedDuration(_long);
                potion.setLevel(strong ? 2 : 1);
                chestItem = potion.toItemStack(chestItem.getAmount());
            }
        }
    }
    return chestItem;
}
Also used : StringTag(com.wasteofplastic.org.jnbt.StringTag) Potion(org.bukkit.potion.Potion) NBTTagString(net.minecraft.server.v1_8_R1.NBTTagString) StringTag(com.wasteofplastic.org.jnbt.StringTag) CompoundTag(com.wasteofplastic.org.jnbt.CompoundTag) Tag(com.wasteofplastic.org.jnbt.Tag) ListTag(com.wasteofplastic.org.jnbt.ListTag) PotionType(org.bukkit.potion.PotionType) Map(java.util.Map)

Example 47 with ItemStack

use of net.minecraft.server.v1_8_R1.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_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_12_R1.ItemStack) CustomInventory(de.Keyle.MyPet.compat.v1_12_R1.util.inventory.CustomInventory)

Example 48 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(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()) {
        TagCompound enchTag = new TagCompound();
        enchTag.put("id", new TagShort(2));
        enchTag.put("lvl", new TagShort(1));
        TagList enchList = new TagList();
        enchList.addTag(enchTag);
        is.getTag().set("ench", ItemStackNBTConverter.compoundToVanillaCompound(enchList));
        is.getTag().setInt("HideFlags", 1);
    } 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 : TagShort(de.keyle.knbt.TagShort) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) NBTTagCompound(net.minecraft.server.v1_12_R1.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) NBTTagList(net.minecraft.server.v1_12_R1.NBTTagList) TagList(de.keyle.knbt.TagList) NBTTagString(net.minecraft.server.v1_12_R1.NBTTagString) CraftItemStack(org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_12_R1.ItemStack)

Example 49 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_9_R2.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)

Example 50 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(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));
        }
    }
    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_9_R2.NBTTagCompound) NBTTagString(net.minecraft.server.v1_9_R2.NBTTagString) NBTTagCompound(net.minecraft.server.v1_9_R2.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) NBTTagList(net.minecraft.server.v1_9_R2.NBTTagList) NBTTagString(net.minecraft.server.v1_9_R2.NBTTagString) ItemStack(net.minecraft.server.v1_9_R2.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)

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