Search in sources :

Example 21 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) {
    byte type = (byte) horse.getVariant().ordinal();
    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);
    }
    if (horse.getInventory().getSaddle() != null) {
        TagCompound saddle = MyPetApi.getPlatformHelper().itemStackToCompund(horse.getInventory().getSaddle());
        properties.getCompoundData().put("Saddle", saddle);
    }
    properties.getCompoundData().put("Type", new TagByte(type));
    properties.getCompoundData().put("Variant", new TagInt(variant));
    properties.getCompoundData().put("Chest", new TagByte(horse.isCarryingChest()));
    properties.getCompoundData().put("Age", new TagInt(horse.getAge()));
    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) TagByte(de.keyle.knbt.TagByte)

Example 22 with TagCompound

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));
        }
    }
    return is;
}
Also used : NBTTagCompound(net.minecraft.server.v1_8_R2.NBTTagCompound) NBTTagString(net.minecraft.server.v1_8_R2.NBTTagString) NBTTagCompound(net.minecraft.server.v1_8_R2.NBTTagCompound) TagCompound(de.keyle.knbt.TagCompound) InvocationTargetException(java.lang.reflect.InvocationTargetException) NBTTagList(net.minecraft.server.v1_8_R2.NBTTagList) NBTTagString(net.minecraft.server.v1_8_R2.NBTTagString) ItemStack(net.minecraft.server.v1_8_R2.ItemStack) CraftItemStack(org.bukkit.craftbukkit.v1_8_R2.inventory.CraftItemStack)

Example 23 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_8_R2.inventory.CraftItemStack) TagCompound(de.keyle.knbt.TagCompound)

Example 24 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 != null) {
            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_8_R2.inventory.CraftItemStack) TagCompound(de.keyle.knbt.TagCompound) TagByte(de.keyle.knbt.TagByte)

Example 25 with TagCompound

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

the class EggIconService method updateIcon.

@Override
public void updateIcon(MyPetType type, IconMenuItem icon) {
    icon.setMaterial(Material.MONSTER_EGG);
    TagCompound entityTag = new TagCompound();
    switch(type) {
        case Bat:
            entityTag.put("id", new TagString("Bat"));
            break;
        case Blaze:
            entityTag.put("id", new TagString("Blaze"));
            break;
        case CaveSpider:
            entityTag.put("id", new TagString("CaveSpider"));
            break;
        case Chicken:
            entityTag.put("id", new TagString("Chicken"));
            break;
        case Cow:
            entityTag.put("id", new TagString("Cow"));
            break;
        case Creeper:
            entityTag.put("id", new TagString("Creeper"));
            break;
        case EnderDragon:
            entityTag.put("id", new TagString("EnderDragon"));
            break;
        case Enderman:
            entityTag.put("id", new TagString("Enderman"));
            break;
        case Endermite:
            entityTag.put("id", new TagString("Endermite"));
            break;
        case Ghast:
            entityTag.put("id", new TagString("Ghast"));
            break;
        case Giant:
            entityTag.put("id", new TagString("Giant"));
            break;
        case Guardian:
            entityTag.put("id", new TagString("Guardian"));
            break;
        case Horse:
            entityTag.put("id", new TagString("EntityHorse"));
            break;
        case IronGolem:
            entityTag.put("id", new TagString("VillagerGolem"));
            icon.setGlowing(true);
            break;
        case MagmaCube:
            entityTag.put("id", new TagString("LavaSlime"));
            break;
        case Mooshroom:
            entityTag.put("id", new TagString("MushroomCow"));
            break;
        case Ocelot:
            entityTag.put("id", new TagString("Ozelot"));
            break;
        case Pig:
            entityTag.put("id", new TagString("pig"));
            break;
        case PigZombie:
            entityTag.put("id", new TagString("PigZombie"));
            break;
        case PolarBear:
            entityTag.put("id", new TagString("PolarBear"));
            break;
        case Rabbit:
            entityTag.put("id", new TagString("Rabbit"));
            break;
        case Sheep:
            entityTag.put("id", new TagString("Sheep"));
            break;
        case Silverfish:
            entityTag.put("id", new TagString("Silverfish"));
            break;
        case Skeleton:
            entityTag.put("id", new TagString("Skeleton"));
            break;
        case Slime:
            entityTag.put("id", new TagString("Slime"));
            break;
        case Snowman:
            entityTag.put("id", new TagString("Snowman"));
            break;
        case Spider:
            entityTag.put("id", new TagString("Spider"));
            break;
        case Squid:
            entityTag.put("id", new TagString("Squid"));
            break;
        case Witch:
            entityTag.put("id", new TagString("Witch"));
            break;
        case Wither:
            entityTag.put("id", new TagString("WitherBoss"));
            icon.setGlowing(true);
            break;
        case Wolf:
            entityTag.put("id", new TagString("Wolf"));
            break;
        case Villager:
            entityTag.put("id", new TagString("Villager"));
            break;
        case Zombie:
            entityTag.put("id", new TagString("Zombie"));
            break;
    }
    icon.addTag("EntityTag", entityTag);
}
Also used : TagString(de.keyle.knbt.TagString) TagCompound(de.keyle.knbt.TagCompound)

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