Search in sources :

Example 36 with Item

use of net.minecraft.server.v1_11_R1.Item in project MyPet by xXKeyleXx.

the class ConfigItem method load.

public void load(String data) {
    NBTBase nbtBase = null;
    if (data.contains("{")) {
        String tagString = data.substring(data.indexOf("{"));
        data = data.substring(0, data.indexOf("{"));
        try {
            nbtBase = MojangsonParser.parse(tagString);
        } catch (Exception e) {
            MyPetApi.getLogger().warning(ChatColor.RED + "Error" + ChatColor.RESET + " in config: " + ChatColor.YELLOW + e.getLocalizedMessage() + ChatColor.RESET + " caused by:");
            MyPetApi.getLogger().warning(data + tagString);
        }
    }
    String[] splitData = data.split("\\s+");
    if (splitData.length == 0) {
        return;
    }
    Item item = null;
    if (splitData.length >= 1) {
        if (Util.isInt(splitData[0])) {
            int itemId = Integer.parseInt(splitData[0]);
            item = Item.getById(itemId);
        } else {
            item = (Item) Item.REGISTRY.get(splitData[0]);
        }
    }
    if (item != null) {
        int itemDamage = 0;
        if (splitData.length >= 2) {
            if (splitData[1].startsWith("<")) {
                this.durabilityMode = DurabilityMode.Smaller;
                splitData[1] = splitData[1].substring(1);
            } else if (splitData[1].startsWith(">")) {
                this.durabilityMode = DurabilityMode.Bigger;
                splitData[1] = splitData[1].substring(1);
            } else {
                this.durabilityMode = DurabilityMode.Equal;
            }
            if (Util.isInt(splitData[1])) {
                itemDamage = Integer.parseInt(splitData[1]);
            }
        }
        net.minecraft.server.v1_7_R4.ItemStack is = new net.minecraft.server.v1_7_R4.ItemStack(item, 1, itemDamage);
        if (nbtBase != null) {
            is.setTag((NBTTagCompound) nbtBase);
        }
        this.item = CraftItemStack.asBukkitCopy(is);
    }
}
Also used : Item(net.minecraft.server.v1_7_R4.Item) NBTBase(net.minecraft.server.v1_7_R4.NBTBase) CraftItemStack(org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack) ItemStack(org.bukkit.inventory.ItemStack)

Example 37 with Item

use of net.minecraft.server.v1_11_R1.Item 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 38 with Item

use of net.minecraft.server.v1_11_R1.Item 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 39 with Item

use of net.minecraft.server.v1_11_R1.Item in project ORCID-Source by ORCID.

the class WorkEntityFactory method create.

@Override
public NotificationWorkEntity create(Object source, MappingContext mappingContext) {
    mappingContext.getSourceObjects();
    NotificationWorkEntity nwe = new NotificationWorkEntity();
    String putCode = ((Item) source).getPutCode();
    if (putCode != null) {
        WorkEntity work = workDao.find(Long.valueOf(putCode));
        nwe.setWork(work);
    }
    return nwe;
}
Also used : NotificationWorkEntity(org.orcid.persistence.jpa.entities.NotificationWorkEntity) Item(org.orcid.jaxb.model.notification.permission_v2.Item) WorkEntity(org.orcid.persistence.jpa.entities.WorkEntity) NotificationWorkEntity(org.orcid.persistence.jpa.entities.NotificationWorkEntity)

Example 40 with Item

use of net.minecraft.server.v1_11_R1.Item in project ORCID-Source by ORCID.

the class WorkManagerImpl method createItem.

private Item createItem(WorkEntity workEntity) {
    Item item = new Item();
    item.setItemName(workEntity.getTitle());
    item.setItemType(ItemType.WORK);
    item.setPutCode(String.valueOf(workEntity.getId()));
    return item;
}
Also used : Item(org.orcid.jaxb.model.notification.permission_v2.Item)

Aggregations

Item (org.orcid.jaxb.model.notification.permission_v2.Item)19 CraftItemStack (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)17 ItemStack (org.bukkit.inventory.ItemStack)13 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)12 Test (org.junit.Test)7 ExternalID (org.orcid.jaxb.model.record_v2.ExternalID)7 Field (java.lang.reflect.Field)6 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)5 Item (net.minecraft.server.v1_12_R1.Item)5 Items (org.orcid.jaxb.model.notification.permission_v2.Items)5 ArrayList (java.util.ArrayList)4 Container (net.minecraft.server.v1_11_R1.Container)3 NBTTagList (net.minecraft.server.v1_11_R1.NBTTagList)3 NBTTagString (net.minecraft.server.v1_11_R1.NBTTagString)3 ItemMeta (org.bukkit.inventory.meta.ItemMeta)3 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)2 ListTag (com.wasteofplastic.org.jnbt.ListTag)2 StringTag (com.wasteofplastic.org.jnbt.StringTag)2 Tag (com.wasteofplastic.org.jnbt.Tag)2 IconMenuItem (de.Keyle.MyPet.api.gui.IconMenuItem)2