package com.voxelwind.server.game.level.provider.anvil.util;

import com.flowpowered.nbt.ByteTag;
import com.flowpowered.nbt.CompoundMap;
import com.flowpowered.nbt.ShortTag;
import com.voxelwind.api.game.item.ItemStack;
import com.voxelwind.api.game.item.ItemType;
import com.voxelwind.api.game.item.ItemTypes;
import com.voxelwind.server.game.item.VoxelwindItemStack;

public class VoxelwindNBTUtils {
    public static ItemStack createItemStack(CompoundMap map) {
        ByteTag countTag = (ByteTag) map.get("Count");
        ShortTag damageTag = (ShortTag) map.get("Damage");
        ShortTag idTag = (ShortTag) map.get("id");

        // TODO: "tag" compound
        ItemType type = ItemTypes.forId(idTag.getValue());
        return new VoxelwindItemStack(type, countTag.getValue(), type.createDataFor(damageTag.getValue()).orElse(null));
    }
}

@@ -82,23 +82,17 @@
 red.nbt.
-ByteTag
+*
 ;%0Aimport
@@ -100,72 +100,40 @@
 com.
-flowpowered.nbt.CompoundMap;%0Aimport com.flowpowered.nbt.ShortTag
+google.common.base.Preconditions
 ;%0Aim
@@ -675,24 +675,24 @@
 etValue());%0A
-
         retu
@@ -805,11 +805,875 @@
 );%0A    %7D
+%0A%0A    public static ItemStack%5B%5D createItemStacks(ListTag%3CCompoundTag%3E tag, int knownSize) %7B%0A        ItemStack%5B%5D all = new ItemStack%5BknownSize%5D;%0A        for (CompoundTag slotTag : tag.getValue()) %7B%0A            CompoundMap slotMap = slotTag.getValue();%0A            Tag%3C?%3E inSlotTagRaw = slotMap.get(%22Slot%22);%0A            Preconditions.checkArgument(inSlotTagRaw != null, %22Slot NBT tag is missing from compound%22);%0A            Preconditions.checkArgument(inSlotTagRaw instanceof ByteTag, %22Slot NBT tag is not a Byte%22);%0A            ByteTag inSlotTag = (ByteTag) inSlotTagRaw;%0A            if (inSlotTag.getValue() %3C 0 %7C%7C inSlotTag.getValue() %3E= knownSize) %7B%0A                throw new IllegalArgumentException(%22Found illegal slot %22 + inSlotTag.getValue());%0A            %7D%0A            all%5BinSlotTag.getValue()%5D = createItemStack(slotMap);%0A        %7D%0A        return all;%0A    %7D
 %0A%7D%0A

Add NBT block entity inventory deserialization