use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.
the class Pickup method save.
public TagCompound save() {
TagCompound nbtTagCompound = new TagCompound();
nbtTagCompound.getCompoundData().put("Active", new TagByte(pickup));
return nbtTagCompound;
}
use of de.keyle.knbt.TagCompound 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 de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.
the class CustomInventory method load.
public void load(TagCompound nbtTagCompound) {
TagList items = nbtTagCompound.getAs("Items", TagList.class);
for (int i = 0; i < items.size(); i++) {
TagCompound itemCompound = items.getTagAs(i, TagCompound.class);
ItemStack itemStack = ItemStackNBTConverter.compundToItemStack(itemCompound);
setItem(itemCompound.getAs("Slot", TagByte.class).getByteData(), itemStack);
}
}
use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.
the class EntityConverterService method convertEquipable.
public void convertEquipable(LivingEntity entity, TagCompound properties) {
List<TagCompound> equipmentList = new ArrayList<>();
if (random.nextFloat() <= entity.getEquipment().getChestplateDropChance()) {
ItemStack itemStack = entity.getEquipment().getChestplate();
if (itemStack != null && itemStack.getType() != Material.AIR) {
TagCompound item = MyPetApi.getPlatformHelper().itemStackToCompund(itemStack);
item.getCompoundData().put("Slot", new TagInt(EquipmentSlot.Chestplate.getSlotId()));
equipmentList.add(item);
}
}
if (random.nextFloat() <= entity.getEquipment().getHelmetDropChance()) {
ItemStack itemStack = entity.getEquipment().getHelmet();
if (itemStack != null && itemStack.getType() != Material.AIR) {
TagCompound item = MyPetApi.getPlatformHelper().itemStackToCompund(itemStack);
item.getCompoundData().put("Slot", new TagInt(EquipmentSlot.Helmet.getSlotId()));
equipmentList.add(item);
}
}
if (random.nextFloat() <= entity.getEquipment().getLeggingsDropChance()) {
ItemStack itemStack = entity.getEquipment().getLeggings();
if (itemStack != null && itemStack.getType() != Material.AIR) {
TagCompound item = MyPetApi.getPlatformHelper().itemStackToCompund(itemStack);
item.getCompoundData().put("Slot", new TagInt(EquipmentSlot.Leggins.getSlotId()));
equipmentList.add(item);
}
}
if (random.nextFloat() <= entity.getEquipment().getBootsDropChance()) {
ItemStack itemStack = entity.getEquipment().getBoots();
if (itemStack != null && itemStack.getType() != Material.AIR) {
TagCompound item = MyPetApi.getPlatformHelper().itemStackToCompund(itemStack);
item.getCompoundData().put("Slot", new TagInt(EquipmentSlot.Boots.getSlotId()));
equipmentList.add(item);
}
}
properties.getCompoundData().put("Equipment", new TagList(equipmentList));
}
use of de.keyle.knbt.TagCompound in project MyPet by xXKeyleXx.
the class EntityConverterService method convertVillager.
public void convertVillager(Villager villager, TagCompound properties) {
int profession = villager.getProfession().ordinal();
if (MyPetApi.getCompatUtil().compareWithMinecraftVersion("1.10") >= 0) {
profession--;
}
properties.getCompoundData().put("Profession", new TagInt(profession));
TagCompound villagerTag = MyPetApi.getPlatformHelper().entityToTag(villager);
String[] allowedTags = { "Riches", "Career", "CareerLevel", "Willing", "Inventory", "Offers" };
Set<String> keys = new HashSet<>(villagerTag.getCompoundData().keySet());
for (String key : keys) {
if (Arrays.binarySearch(allowedTags, key) > -1) {
continue;
}
villagerTag.remove(key);
}
properties.getCompoundData().put("OriginalData", villagerTag);
}
Aggregations