aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/gregtech/crossmod/holoinventory/GTInventoryDecoder.java
blob: 6774a32c6de18c57464d7fb0c3abf3f0965d0a88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package gregtech.crossmod.holoinventory;

import static net.dries007.holoInventory.util.NBTKeys.NBT_KEY_COUNT;

import java.util.List;

import net.dries007.holoInventory.compat.InventoryDecoder;
import net.dries007.holoInventory.compat.InventoryDecoderRegistry;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;

import gregtech.api.metatileentity.BaseTileEntity;

public class GTInventoryDecoder extends InventoryDecoder {

    public GTInventoryDecoder() {
        super(BaseTileEntity.class);
    }

    @Override
    public NBTTagList toNBT(IInventory inv) {
        List<ItemStack> items = ((BaseTileEntity) inv).getItemsForHoloGlasses();
        if (items == null) {
            return InventoryDecoderRegistry.DEFAULT.toNBT(inv);
        }
        NBTTagList tagList = new NBTTagList();
        for (ItemStack stack : items) {
            if (stack != null) {
                NBTTagCompound tag = stack.writeToNBT(new NBTTagCompound());
                tag.setInteger(NBT_KEY_COUNT, stack.stackSize);
                tagList.appendTag(tag);
            }
        }
        return tagList;
    }
}