use of de.keyle.knbt.TagShort in project MyPet by xXKeyleXx.
the class SkillTree method setIconItem.
public void setIconItem(short id, short damage, boolean enchantetGlow) {
getIconItem();
if (id > 0) {
iconItem.getCompoundData().put("id", new TagShort(id));
}
if (damage >= 0) {
iconItem.getCompoundData().put("Damage", new TagShort(damage));
}
if (!iconItem.getCompoundData().containsKey("tag")) {
iconItem.getCompoundData().put("tag", new TagCompound());
}
TagCompound tagCompound = iconItem.getAs("tag", TagCompound.class);
if (enchantetGlow) {
tagCompound.getCompoundData().put("ench", new TagList());
} else {
tagCompound.getCompoundData().remove("ench");
}
}
use of de.keyle.knbt.TagShort 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 de.keyle.knbt.TagShort 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;
}
Aggregations