Search in sources :

Example 11 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)

Example 12 with TagList

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.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_10_R1.inventory.CraftItemStack) TagCompound(de.keyle.knbt.TagCompound) TagByte(de.keyle.knbt.TagByte)

Example 13 with TagList

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

the class MyGiant 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;
}
Also used : ArrayList(java.util.ArrayList) EquipmentSlot(de.Keyle.MyPet.api.entity.EquipmentSlot) TagInt(de.keyle.knbt.TagInt) TagList(de.keyle.knbt.TagList) TagCompound(de.keyle.knbt.TagCompound)

Example 14 with TagList

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

the class MyHusk method writeExtendedInfo.

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

Example 15 with TagList

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

the class MyPigZombie method readExtendedInfo.

@Override
public void readExtendedInfo(TagCompound info) {
    if (info.getCompoundData().containsKey("Baby")) {
        setBaby(info.getAs("Baby", TagByte.class).getBooleanData());
    }
    if (info.getCompoundData().containsKey("Equipment")) {
        TagList equipment = info.getAs("Equipment", TagList.class);
        for (int i = 0; i < equipment.getReadOnlyList().size(); i++) {
            TagCompound item = equipment.getTagAs(i, TagCompound.class);
            ItemStack itemStack = MyPetApi.getPlatformHelper().compundToItemStack(item);
            setEquipment(EquipmentSlot.getSlotById(item.getAs("Slot", TagInt.class).getIntData()), itemStack);
        }
    }
}
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