Search in sources :

Example 21 with TagList

use of de.keyle.knbt.TagList in project MyPet by xXKeyleXx.

the class MyZombie method writeExtendedInfo.

@Override
public TagCompound writeExtendedInfo() {
    TagCompound info = super.writeExtendedInfo();
    info.getCompoundData().put("Baby", new TagByte(isBaby()));
    info.getCompoundData().put("Type", new TagInt(type.ordinal()));
    info.getCompoundData().put("Profession", new TagInt(profession));
    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;
}
Also used : TagInt(de.keyle.knbt.TagInt) ArrayList(java.util.ArrayList) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) TagList(de.keyle.knbt.TagList) TagCompound(de.keyle.knbt.TagCompound) TagByte(de.keyle.knbt.TagByte)

Example 22 with TagList

use of de.keyle.knbt.TagList 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");
    }
}
Also used : TagShort(de.keyle.knbt.TagShort) TagList(de.keyle.knbt.TagList) TagCompound(de.keyle.knbt.TagCompound)

Example 23 with TagList

use of de.keyle.knbt.TagList in project MyPet by xXKeyleXx.

the class SkullMeta method applyTo.

public void applyTo(TagCompound tag) {
    if (hasOwner()) {
        TagCompound ownerTag = new TagCompound();
        ownerTag.put("Name", new TagString(getOwner()));
        if (hasTexture()) {
            TagCompound propertiesTag = new TagCompound();
            TagList textureList = new TagList();
            TagCompound textureTag = new TagCompound();
            JSONObject jsonObject = new JSONObject();
            JSONObject texturesObject = new JSONObject();
            JSONObject skinObject = new JSONObject();
            jsonObject.put("textures", texturesObject);
            texturesObject.put("SKIN", skinObject);
            skinObject.put("url", getTexture());
            String base64 = BaseEncoding.base64Url().encode(jsonObject.toJSONString().getBytes());
            textureTag.put("Value", new TagString(base64));
            textureList.addTag(textureTag);
            propertiesTag.put("textures", textureList);
            ownerTag.put("Properties", propertiesTag);
        }
        tag.put("SkullOwner", ownerTag);
    }
}
Also used : JSONObject(org.json.simple.JSONObject) TagString(de.keyle.knbt.TagString) TagList(de.keyle.knbt.TagList) TagString(de.keyle.knbt.TagString) TagCompound(de.keyle.knbt.TagCompound)

Example 24 with TagList

use of de.keyle.knbt.TagList 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);
    }
}
Also used : TagList(de.keyle.knbt.TagList) CraftItemStack(org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack) TagCompound(de.keyle.knbt.TagCompound)

Example 25 with TagList

use of de.keyle.knbt.TagList 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));
}
Also used : TagInt(de.keyle.knbt.TagInt) TagList(de.keyle.knbt.TagList) ItemStack(org.bukkit.inventory.ItemStack) TagCompound(de.keyle.knbt.TagCompound)

Aggregations

TagCompound (de.keyle.knbt.TagCompound)47 TagList (de.keyle.knbt.TagList)47 TagInt (de.keyle.knbt.TagInt)25 ArrayList (java.util.ArrayList)17 ItemStack (org.bukkit.inventory.ItemStack)17 TagByte (de.keyle.knbt.TagByte)13 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)8 TagShort (de.keyle.knbt.TagShort)3 CraftItemStack (org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 CraftItemStack (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_8_R1.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack)2 CraftItemStack (org.bukkit.craftbukkit.v1_9_R2.inventory.CraftItemStack)2 TagString (de.keyle.knbt.TagString)1 ItemStack (net.minecraft.server.v1_11_R1.ItemStack)1