package de.maxhenkel.skycraft.blocks.tileentity;

import net.minecraft.inventory.InventoryBasic;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;

public class TileEntityOreWasher extends TileEntity{

    public InventoryBasic inv;
    
    public TileEntityOreWasher(){
        inv=new InventoryBasic("OreWasher", false, 3);
    }
    
    @Override
    public void writeToNBT(NBTTagCompound compound) {
        super.writeToNBT(compound);
        NBTTagList list=new NBTTagList();
        for(int i=0; i<inv.getSizeInventory(); i++){
            if(inv.getStackInSlot(i)!=null){
                NBTTagCompound tag=new NBTTagCompound();
                tag.setByte("slot", (byte) i);
                inv.getStackInSlot(i).writeToNBT(tag);
                list.appendTag(tag);
            }
        }
        compound.setTag("ItemStacks", list);
    }
    
    @Override
    public void readFromNBT(NBTTagCompound compound) {
        super.readFromNBT(compound);
        
        NBTTagList list=compound.getTagList("ItemStacks", 10);
        this.inv=new InventoryBasic("Composter", false, 3);
        
        for(int i=0; i<list.tagCount(); i++){
            NBTTagCompound tag=list.getCompoundTagAt(i);
            byte b=tag.getByte("slot");
            
            if(b>=0&&b<inv.getSizeInventory()){
                inv.setInventorySlotContents(b, ItemStack.loadItemStackFromNBT(tag));
            }
        }
    }
    
}
