Search in sources :

Example 56 with TagList

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

the class CustomInventory method save.

@Override
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.b) {
            TagCompound item = ItemStackNBTConverter.itemStackToCompound(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_16_R3.inventory.CraftItemStack) TagCompound(de.keyle.knbt.TagCompound) TagByte(de.keyle.knbt.TagByte)

Example 57 with TagList

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

the class CustomInventory method load.

@Override
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.compoundToItemStack(itemCompound);
        setItem(itemCompound.getAs("Slot", TagByte.class).getByteData(), itemStack);
    }
}
Also used : TagList(de.keyle.knbt.TagList) CraftItemStack(org.bukkit.craftbukkit.v1_16_R3.inventory.CraftItemStack) TagCompound(de.keyle.knbt.TagCompound)

Aggregations

TagCompound (de.keyle.knbt.TagCompound)57 TagList (de.keyle.knbt.TagList)57 ArrayList (java.util.ArrayList)26 TagInt (de.keyle.knbt.TagInt)19 ItemStack (org.bukkit.inventory.ItemStack)16 TagByte (de.keyle.knbt.TagByte)15 TagShort (de.keyle.knbt.TagShort)9 TagString (de.keyle.knbt.TagString)9 CompoundTag (net.minecraft.nbt.CompoundTag)8 ListTag (net.minecraft.nbt.ListTag)8 InvocationTargetException (java.lang.reflect.InvocationTargetException)6 TagBase (de.keyle.knbt.TagBase)5 List (java.util.List)5 CraftItemStack (org.bukkit.craftbukkit.v1_17_R1.inventory.CraftItemStack)5 ItemStack (net.minecraft.world.item.ItemStack)4 CraftItemStack (org.bukkit.craftbukkit.v1_12_R1.inventory.CraftItemStack)3 CraftItemStack (org.bukkit.craftbukkit.v1_18_R1.inventory.CraftItemStack)3 Dynamic (com.mojang.serialization.Dynamic)2 EquipmentSlot (de.Keyle.MyPet.api.entity.EquipmentSlot)2 MyPetBaby (de.Keyle.MyPet.api.entity.MyPetBaby)2