use of net.minecraft.server.v1_11_R1.NBTTagString 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;
}
use of net.minecraft.server.v1_11_R1.NBTTagString 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;
}
use of net.minecraft.server.v1_11_R1.NBTTagString 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 (Object key : vanillaTag.c()) {
is.getTag().set(key.toString(), vanillaTag.get(key.toString()));
}
}
return is;
}
use of net.minecraft.server.v1_11_R1.NBTTagString 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;
}
use of net.minecraft.server.v1_11_R1.NBTTagString in project MyPet by xXKeyleXx.
the class IconMenuInventory method createItemStack.
protected ItemStack createItemStack(IconMenuItem icon) {
ItemStack is = CraftItemStack.asNMSCopy(CraftItemStack.asCraftCopy(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));
}
}
return is;
}
Aggregations