// Path: com/bafomdad/realfilingcabinet/network/PacketRFC.java
// public class PacketRFC implements IMessage {
// 	
// 	private NBTTagCompound tags = new NBTTagCompound();
// 	
// 	public PacketRFC() {}
// 	
// 	public PacketRFC(NBTTagCompound tags) {
// 		
// 		this.tags = tags;
// 	}
// 
// 	@Override
// 	public void fromBytes(ByteBuf buf) {
// 
// 		tags = ByteBufUtils.readTag(buf);
// 	}
// 
// 	@Override
// 	public void toBytes(ByteBuf buf) {
// 
// 		ByteBufUtils.writeTag(buf, tags);
// 	}
// 	
// 	public static class Handler implements IMessageHandler<PacketRFC, IMessage> {
// 
// 		@Override
// 		public PacketRFC onMessage(PacketRFC message, MessageContext ctx) {
// 
// 			if (!message.tags.hasKey("windowId", 3))
// 				return null;
// 			
// 			int wid = message.tags.hasKey("windowId", 3) ? message.tags.getInteger("windowId") : -1;
// 			Container cont = Minecraft.getMinecraft().player.openContainer;
// 			
// 			if (cont == null || cont.windowId != wid)
// 				return null;
// 			
// 			for (Slot slot : cont.inventorySlots) {
// 				ItemStack stack = slot.getStack();
// 				CapabilityFolder cap;
// 				if (!stack.hasTagCompound()) continue;
// 				
// 				else if (stack.hasCapability(CapabilityProviderFolder.FOLDER_CAP, null) && stack.getTagCompound().hasKey("folderCap")) {
// 					cap = stack.getCapability(CapabilityProviderFolder.FOLDER_CAP, null);
// 					cap.deserializeNBT(stack.getTagCompound().getCompoundTag("folderCap"));
// 					stack.getTagCompound().removeTag("folderCap");
// 					
// 				} else continue;
// 				
// 				if (stack.getTagCompound().getSize() <= 0)
// 					stack.setTagCompound(null);
// 			}
// 			return null;
// 		}
// 	}
// }
// 
// Path: com/bafomdad/realfilingcabinet/network/RFCPacketHandler.java
// public class RFCPacketHandler {
// 
// 	public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("RealFilingCabinet".toLowerCase());
// 	private static byte packetId = 0;
// 	
// 	public static void init() {
// 		
// 		INSTANCE.registerMessage(PacketMouse.Handler.class, PacketMouse.class, packetId++, Side.SERVER);
// //		INSTANCE.registerMessage(RFCTileMessage.Handler.class, RFCTileMessage.class, packetId++, Side.SERVER);
// 	}
// 	
// 	public static void initClient() {
// 		
// 		INSTANCE.registerMessage(PacketRFC.Handler.class, PacketRFC.class, packetId++, Side.CLIENT);
// 	}
// }


import com.bafomdad.realfilingcabinet.network.PacketRFC;
import com.bafomdad.realfilingcabinet.network.RFCPacketHandler;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
package com.bafomdad.realfilingcabinet.gui;



public class RFCContainerListener implements IContainerListener {
	
	private final EntityPlayerMP player;
	
	public RFCContainerListener(EntityPlayerMP player) {
		
		this.player = player;
	}

	@Override
	public void sendAllContents(Container containerToSend, NonNullList<ItemStack> itemsList) {

		NBTTagCompound tag = new NBTTagCompound();
		tag.setInteger("windowId", containerToSend.windowId);
		
		for (int i = 0; i < itemsList.size(); i++)
			tag.setBoolean("updateAll", true);
		
		RFCPacketHandler.INSTANCE.sendTo(new PacketRFC(tag), player);
	}

	@Override
	public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack) {

		NBTTagCompound tag = new NBTTagCompound();
		tag.setInteger("windowId", containerToSend.windowId);
		tag.setBoolean("updateAll", false);
		tag.setInteger("slotId", slotInd);
		
// Path: com/bafomdad/realfilingcabinet/network/PacketRFC.java
// public class PacketRFC implements IMessage {
// 	
// 	private NBTTagCompound tags = new NBTTagCompound();
// 	
// 	public PacketRFC() {}
// 	
// 	public PacketRFC(NBTTagCompound tags) {
// 		
// 		this.tags = tags;
// 	}
// 
// 	@Override
// 	public void fromBytes(ByteBuf buf) {
// 
// 		tags = ByteBufUtils.readTag(buf);
// 	}
// 
// 	@Override
// 	public void toBytes(ByteBuf buf) {
// 
// 		ByteBufUtils.writeTag(buf, tags);
// 	}
// 	
// 	public static class Handler implements IMessageHandler<PacketRFC, IMessage> {
// 
// 		@Override
// 		public PacketRFC onMessage(PacketRFC message, MessageContext ctx) {
// 
// 			if (!message.tags.hasKey("windowId", 3))
// 				return null;
// 			
// 			int wid = message.tags.hasKey("windowId", 3) ? message.tags.getInteger("windowId") : -1;
// 			Container cont = Minecraft.getMinecraft().player.openContainer;
// 			
// 			if (cont == null || cont.windowId != wid)
// 				return null;
// 			
// 			for (Slot slot : cont.inventorySlots) {
// 				ItemStack stack = slot.getStack();
// 				CapabilityFolder cap;
// 				if (!stack.hasTagCompound()) continue;
// 				
// 				else if (stack.hasCapability(CapabilityProviderFolder.FOLDER_CAP, null) && stack.getTagCompound().hasKey("folderCap")) {
// 					cap = stack.getCapability(CapabilityProviderFolder.FOLDER_CAP, null);
// 					cap.deserializeNBT(stack.getTagCompound().getCompoundTag("folderCap"));
// 					stack.getTagCompound().removeTag("folderCap");
// 					
// 				} else continue;
// 				
// 				if (stack.getTagCompound().getSize() <= 0)
// 					stack.setTagCompound(null);
// 			}
// 			return null;
// 		}
// 	}
// }
// 
// Path: com/bafomdad/realfilingcabinet/network/RFCPacketHandler.java
// public class RFCPacketHandler {
// 
// 	public static final SimpleNetworkWrapper INSTANCE = NetworkRegistry.INSTANCE.newSimpleChannel("RealFilingCabinet".toLowerCase());
// 	private static byte packetId = 0;
// 	
// 	public static void init() {
// 		
// 		INSTANCE.registerMessage(PacketMouse.Handler.class, PacketMouse.class, packetId++, Side.SERVER);
// //		INSTANCE.registerMessage(RFCTileMessage.Handler.class, RFCTileMessage.class, packetId++, Side.SERVER);
// 	}
// 	
// 	public static void initClient() {
// 		
// 		INSTANCE.registerMessage(PacketRFC.Handler.class, PacketRFC.class, packetId++, Side.CLIENT);
// 	}
// }


// Path: com/bafomdad/realfilingcabinet/gui/RFCContainerListener.java
import com.bafomdad.realfilingcabinet.network.PacketRFC;
import com.bafomdad.realfilingcabinet.network.RFCPacketHandler;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IContainerListener;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;

package com.bafomdad.realfilingcabinet.gui;



public class RFCContainerListener implements IContainerListener {
	
	private final EntityPlayerMP player;
	
	public RFCContainerListener(EntityPlayerMP player) {
		
		this.player = player;
	}

	@Override
	public void sendAllContents(Container containerToSend, NonNullList<ItemStack> itemsList) {

		NBTTagCompound tag = new NBTTagCompound();
		tag.setInteger("windowId", containerToSend.windowId);
		
		for (int i = 0; i < itemsList.size(); i++)
			tag.setBoolean("updateAll", true);
		
		RFCPacketHandler.INSTANCE.sendTo(new PacketRFC(tag), player);
	}

	@Override
	public void sendSlotContents(Container containerToSend, int slotInd, ItemStack stack) {

		NBTTagCompound tag = new NBTTagCompound();
		tag.setInteger("windowId", containerToSend.windowId);
		tag.setBoolean("updateAll", false);
		tag.setInteger("slotId", slotInd);
		
		RFCPacketHandler.INSTANCE.sendTo(new PacketRFC(tag), player);