use of de.keyle.knbt.TagList 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()));
if (is == null) {
is = CraftItemStack.asNMSCopy(new org.bukkit.inventory.ItemStack(Material.STONE));
}
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();
}
}
// add enchantment glowing
if (icon.isGlowing()) {
TagCompound enchTag = new TagCompound();
enchTag.put("id", new TagString("minecraft:feather_falling"));
enchTag.put("lvl", new TagShort(1));
TagList enchList = new TagList();
enchList.addTag(enchTag);
is.getTag().set("Enchantments", ItemStackNBTConverter.compoundToVanillaCompound(enchList));
} else {
is.getTag().remove("Enchantments");
}
// hide item attributes like attack damage
is.getTag().setInt("HideFlags", 63);
// 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", "{\"text\":\"" + icon.getTitle() + "\"}");
}
if (icon.getLore().size() > 0) {
// set Lore
NBTTagList loreTag = new NBTTagList();
display.set("Lore", loreTag);
for (String loreLine : icon.getLore()) {
IChatBaseComponent cm = CraftChatMessage.fromStringOrNull(loreLine);
loreTag.add(NBTTagString.a(IChatBaseComponent.ChatSerializer.a(cm)));
}
}
if (icon.hasMeta()) {
TagCompound tag = new TagCompound();
icon.getMeta().applyTo(tag);
NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(tag);
for (String key : vanillaTag.getKeys()) {
is.getTag().set(key, vanillaTag.get(key));
}
}
if (icon.getTags() != null) {
NBTTagCompound vanillaTag = (NBTTagCompound) ItemStackNBTConverter.compoundToVanillaCompound(icon.getTags());
for (String key : vanillaTag.getKeys()) {
is.getTag().set(key, vanillaTag.get(key));
}
}
return is;
}
use of de.keyle.knbt.TagList in project MyPet by xXKeyleXx.
the class CustomInventory method save.
public TagCompound save(TagCompound compound) {
List<TagCompound> itemList = new ArrayList<>();
for (int i = 0; i < this.items.size(); i++) {
ItemStack itemStack = this.items.get(i);
if (itemStack != null) {
TagCompound item = ItemStackNBTConverter.itemStackToCompound(itemStack);
item.getCompoundData().put("Slot", new TagByte((byte) i));
itemList.add(item);
}
}
compound.getCompoundData().put("Items", new TagList(itemList));
return compound;
}
use of de.keyle.knbt.TagList in project MyPet by xXKeyleXx.
the class MyWitherSkeleton method readExtendedInfo.
@SuppressWarnings("unchecked")
@Override
public void readExtendedInfo(TagCompound info) {
if (info.containsKey("Equipment")) {
TagList equipment = info.getAs("Equipment", TagList.class);
List<TagBase> equipmentList = (List<TagBase>) equipment.getData();
for (TagBase tag : equipmentList) {
if (tag instanceof TagCompound) {
TagCompound item = (TagCompound) tag;
try {
ItemStack itemStack = MyPetApi.getPlatformHelper().compundToItemStack(item);
setEquipment(EquipmentSlot.getSlotById(item.getAs("Slot", TagInt.class).getIntData()), itemStack);
} catch (Exception e) {
MyPetApi.getLogger().warning("Could not load Equipment item from pet data!");
}
}
}
}
}
use of de.keyle.knbt.TagList in project MyPet by xXKeyleXx.
the class MyStray method writeExtendedInfo.
@Override
public TagCompound writeExtendedInfo() {
TagCompound info = super.writeExtendedInfo();
List<TagCompound> itemList = new ArrayList<>();
for (EquipmentSlot slot : EquipmentSlot.values()) {
if (getEquipment(slot) != null) {
TagCompound item = MyPetApi.getPlatformHelper().itemStackToCompund(getEquipment(slot));
item.getCompoundData().put("Slot", new TagInt(slot.getSlotId()));
itemList.add(item);
}
}
info.getCompoundData().put("Equipment", new TagList(itemList));
return info;
}
use of de.keyle.knbt.TagList in project MyPet by xXKeyleXx.
the class MyGiant method readExtendedInfo.
@SuppressWarnings("unchecked")
@Override
public void readExtendedInfo(TagCompound info) {
if (info.containsKey("Equipment")) {
TagList equipment = info.get("Equipment");
List<TagBase> equipmentList = (List<TagBase>) equipment.getData();
for (TagBase tag : equipmentList) {
if (tag instanceof TagCompound) {
TagCompound item = (TagCompound) tag;
try {
ItemStack itemStack = MyPetApi.getPlatformHelper().compundToItemStack(item);
setEquipment(EquipmentSlot.getSlotById(item.getAs("Slot", TagInt.class).getIntData()), itemStack);
} catch (Exception e) {
MyPetApi.getLogger().warning("Could not load Equipment item from pet data!");
}
}
}
}
}
Aggregations