Search in sources :

Example 41 with ItemStack

use of net.minecraft.server.v1_10_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()));
    // 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()) {
        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_11_R1.NBTTagCompound) NBTTagString(net.minecraft.server.v1_11_R1.NBTTagString) NBTTagCompound(net.minecraft.server.v1_11_R1.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) NBTTagList(net.minecraft.server.v1_11_R1.NBTTagList) NBTTagList(net.minecraft.server.v1_11_R1.NBTTagList) TagList(de.keyle.knbt.TagList) NBTTagString(net.minecraft.server.v1_11_R1.NBTTagString) CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_11_R1.ItemStack)

Example 42 with ItemStack

use of net.minecraft.server.v1_10_R1.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, ItemStack.a);
        }
    }
}
Also used : IconMenuItem(de.Keyle.MyPet.api.gui.IconMenuItem) CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack) ItemStack(net.minecraft.server.v1_11_R1.ItemStack)

Example 43 with ItemStack

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

the class EntityMyCow 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 (itemStack.getItem() == Items.BUCKET && Configuration.MyPet.Cow.CAN_GIVE_MILK) {
            ItemStack milkBucket = new ItemStack(Items.BUCKET, 1, 0);
            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, milkBucket);
            return true;
        } else if (Configuration.MyPet.Cow.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_R2.ItemStack)

Example 44 with ItemStack

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

the class EntityMyOcelot method handlePlayerInteraction.

public boolean handlePlayerInteraction(EntityHuman entityhuman) {
    if (super.handlePlayerInteraction(entityhuman)) {
        return true;
    }
    ItemStack itemStack = entityhuman.inventory.getItemInHand();
    if (getOwner().equals(entityhuman)) {
        if (itemStack != null && canUseItem() && getOwner().getPlayer().isSneaking()) {
            if (Item.getId(itemStack.getItem()) == 351) {
                boolean colorChanged = false;
                if (itemStack.getData() == 11 && getMyPet().getCatType() != Type.WILD_OCELOT) {
                    getMyPet().setCatType(Type.WILD_OCELOT);
                    colorChanged = true;
                } else if (itemStack.getData() == 0 && getMyPet().getCatType() != Type.BLACK_CAT) {
                    getMyPet().setCatType(Type.BLACK_CAT);
                    colorChanged = true;
                } else if (itemStack.getData() == 14 && getMyPet().getCatType() != Type.RED_CAT) {
                    getMyPet().setCatType(Type.RED_CAT);
                    colorChanged = true;
                } else if (itemStack.getData() == 7 && getMyPet().getCatType() != Type.SIAMESE_CAT) {
                    getMyPet().setCatType(Type.SIAMESE_CAT);
                    colorChanged = true;
                }
                if (colorChanged) {
                    if (!entityhuman.abilities.canInstantlyBuild) {
                        if (--itemStack.count <= 0) {
                            entityhuman.inventory.setItem(entityhuman.inventory.itemInHandIndex, null);
                        }
                    }
                    return true;
                }
            } else if (Configuration.MyPet.Ocelot.GROW_UP_ITEM.compare(itemStack) && canUseItem() && 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_R2.ItemStack)

Example 45 with ItemStack

use of net.minecraft.server.v1_10_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) ItemStack(net.minecraft.server.v1_8_R2.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack) CustomInventory(de.Keyle.MyPet.compat.v1_8_R2.util.inventory.CustomInventory)

Aggregations

IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)18 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)12 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 CraftItemStack (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)9 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_10_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_11_R1.inventory.CraftItemStack)4 NBTTagList (net.minecraft.server.v1_10_R1.NBTTagList)3