Search in sources :

Example 31 with NBTTagCompound

use of net.minecraft.server.v1_11_R1.NBTTagCompound in project Essentials by drtshock.

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)

Example 32 with NBTTagCompound

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

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

the class PlatformHelper method applyTagToEntity.

@Override
public void applyTagToEntity(TagCompound tag, Entity bukkitEntity) {
    net.minecraft.server.v1_11_R1.Entity entity = ((CraftEntity) bukkitEntity).getHandle();
    NBTTagCompound vanillaNBT = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
    // Just a temporary fix until I come up with a better solution
    if (bukkitEntity instanceof Villager) {
        EntityVillager villager = (EntityVillager) entity;
        villager.setProfession(vanillaNBT.getInt("Profession"));
        villager.riches = vanillaNBT.getInt("Riches");
        ReflectionUtil.setFieldValue("bJ", villager, vanillaNBT.getInt("Career"));
        ReflectionUtil.setFieldValue("bK", villager, vanillaNBT.getInt("CareerLevel"));
        ReflectionUtil.setFieldValue("bG", villager, vanillaNBT.getBoolean("Willing"));
        if (vanillaNBT.hasKeyOfType("Offers", 10)) {
            NBTTagCompound nbttaglist = vanillaNBT.getCompound("Offers");
            ReflectionUtil.setFieldValue("trades", villager, new MerchantRecipeList(nbttaglist));
        }
        NBTTagList invTag = vanillaNBT.getList("Inventory", 10);
        for (int i = 0; i < invTag.size(); ++i) {
            ItemStack itemstack = new ItemStack(invTag.get(i));
            villager.inventory.a(itemstack);
        }
        villager.m(true);
        if (villager.isBaby()) {
            villager.goalSelector.a(8, new PathfinderGoalPlay(villager, 0.32D));
        } else if (villager.getProfession() == 0) {
            villager.goalSelector.a(6, new PathfinderGoalVillagerFarm(villager, 0.6D));
        }
    }
// can not be used in 1.10
// entity.f(vanillaNBT);
}
Also used : CraftEntity(org.bukkit.craftbukkit.v1_11_R1.entity.CraftEntity) net.minecraft.server.v1_11_R1(net.minecraft.server.v1_11_R1) Villager(org.bukkit.entity.Villager) CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)

Example 34 with NBTTagCompound

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

the class ItemStackComparator method compareTagData.

public static boolean compareTagData(ItemStack i1, ItemStack i2) {
    if (i1.hasItemMeta() && i2.hasItemMeta()) {
        NBTTagCompound tag1 = CraftItemStack.asNMSCopy(i1).getTag();
        NBTTagCompound tag2 = CraftItemStack.asNMSCopy(i2).getTag();
        return tag1 != null && tag2 != null && tag1.equals(tag2);
    }
    return i1.hasItemMeta() == i2.hasItemMeta();
}
Also used : NBTTagCompound(net.minecraft.server.v1_8_R1.NBTTagCompound)

Example 35 with NBTTagCompound

use of net.minecraft.server.v1_11_R1.NBTTagCompound 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_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)

Aggregations

ItemStack (org.bukkit.inventory.ItemStack)17 CompoundTag (com.wasteofplastic.org.jnbt.CompoundTag)15 ListTag (com.wasteofplastic.org.jnbt.ListTag)15 StringTag (com.wasteofplastic.org.jnbt.StringTag)15 Tag (com.wasteofplastic.org.jnbt.Tag)15 Map (java.util.Map)15 ArrayList (java.util.ArrayList)10 ItemMeta (org.bukkit.inventory.meta.ItemMeta)10 TagCompound (de.keyle.knbt.TagCompound)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 NBTTagCompound (net.minecraft.server.v1_10_R1.NBTTagCompound)8 NBTTagCompound (net.minecraft.server.v1_11_R1.NBTTagCompound)8 NBTTagCompound (net.minecraft.server.v1_9_R2.NBTTagCompound)8 NBTTagCompound (net.minecraft.server.v1_12_R1.NBTTagCompound)6 NBTTagCompound (net.minecraft.server.v1_8_R3.NBTTagCompound)6 NBTTagCompound (net.minecraft.server.v1_9_R1.NBTTagCompound)6 NBTTagCompound (net.minecraft.server.v1_8_R1.NBTTagCompound)5 GameProfile (com.mojang.authlib.GameProfile)4 Property (com.mojang.authlib.properties.Property)4 HashMap (java.util.HashMap)4