Search in sources :

Example 11 with TagCompound

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

the class EntityConverterService method convertSaddledHorse.

public void convertSaddledHorse(AbstractHorse horse, TagCompound properties) {
    if (horse.getInventory() instanceof HorseInventory) {
        if (((HorseInventory) horse.getInventory()).getSaddle() != null) {
            TagCompound saddle = MyPetApi.getPlatformHelper().itemStackToCompund(((HorseInventory) horse.getInventory()).getSaddle());
            properties.getCompoundData().put("Saddle", saddle);
        }
    }
}
Also used : HorseInventory(org.bukkit.inventory.HorseInventory) TagCompound(de.keyle.knbt.TagCompound)

Example 12 with TagCompound

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() - 1;
    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);
}
Also used : TagInt(de.keyle.knbt.TagInt) TagCompound(de.keyle.knbt.TagCompound)

Example 13 with TagCompound

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

the class EntityConverterService method convertHorse.

public void convertHorse(Horse horse, TagCompound properties) {
    int style = horse.getStyle().ordinal();
    int color = horse.getColor().ordinal();
    int variant = color & 255 | style << 8;
    if (horse.getInventory().getArmor() != null) {
        TagCompound armor = MyPetApi.getPlatformHelper().itemStackToCompund(horse.getInventory().getArmor());
        properties.getCompoundData().put("Armor", armor);
    }
    properties.getCompoundData().put("Variant", new TagInt(variant));
    if (horse.isCarryingChest()) {
        ItemStack[] contents = horse.getInventory().getContents();
        for (int i = 2; i < contents.length; i++) {
            ItemStack item = contents[i];
            if (item != null) {
                horse.getWorld().dropItem(horse.getLocation(), item);
            }
        }
    }
}
Also used : TagInt(de.keyle.knbt.TagInt) ItemStack(org.bukkit.inventory.ItemStack) TagCompound(de.keyle.knbt.TagCompound)

Example 14 with TagCompound

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

Example 15 with TagCompound

use of de.keyle.knbt.TagCompound 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 != ItemStack.a) {
            TagCompound item = ItemStackNBTConverter.itemStackToCompund(itemStack);
            item.getCompoundData().put("Slot", new TagByte((byte) i));
            itemList.add(item);
        }
    }
    compound.getCompoundData().put("Items", new TagList(itemList));
    return compound;
}
Also used : ArrayList(java.util.ArrayList) TagList(de.keyle.knbt.TagList) CraftItemStack(org.bukkit.craftbukkit.v1_11_R1.inventory.CraftItemStack) TagCompound(de.keyle.knbt.TagCompound) TagByte(de.keyle.knbt.TagByte)

Aggregations

TagCompound (de.keyle.knbt.TagCompound)141 TagInt (de.keyle.knbt.TagInt)53 TagByte (de.keyle.knbt.TagByte)49 TagList (de.keyle.knbt.TagList)47 ItemStack (org.bukkit.inventory.ItemStack)47 ArrayList (java.util.ArrayList)18 TagString (de.keyle.knbt.TagString)12 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)9 InvocationTargetException (java.lang.reflect.InvocationTargetException)9 MaterialData (org.bukkit.material.MaterialData)9 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)8 MyPetPlayer (de.Keyle.MyPet.api.player.MyPetPlayer)5 InactiveMyPet (de.Keyle.MyPet.entity.InactiveMyPet)3 TagShort (de.keyle.knbt.TagShort)3 CraftItemStack (org.bukkit.craftbukkit.v1_10_R1.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_7_R4.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_8_R3.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_9_R1.inventory.CraftItemStack)3