package openperipheral.integration.appeng;

import java.util.Map;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import openperipheral.api.helpers.ItemStackMetaProviderSimple;
import appeng.api.AEApi;
import appeng.api.storage.*;

import com.google.common.collect.Maps;

public class StorageCellMetaProvider extends ItemStackMetaProviderSimple<Item> {

	@Override
	public Object getMeta(Item target, ItemStack stack) {
		IMEInventoryHandler<?> inventory = AEApi.instance().registries().cell().getCellInventory(stack, null, StorageChannel.ITEMS);// get the inventory handler from ae api
		if (inventory instanceof ICellInventoryHandler) {
			ICellInventoryHandler handler = (ICellInventoryHandler)inventory;
			ICellInventory cellInventory = handler.getCellInv();
			if (cellInventory != null) {
				Map<String, Object> ret = Maps.newHashMap();

				ret.put("preformatted", handler.isPreformatted());
				ret.put("fuzzy", handler.isFuzzy());
				ret.put("freeBytes", cellInventory.getFreeBytes());
				ret.put("totalBytes", cellInventory.getTotalBytes());
				ret.put("usedBytes", cellInventory.getUsedBytes());
				ret.put("totalTypes", cellInventory.getTotalItemTypes());
				ret.put("usedTypes", cellInventory.getStoredItemTypes());
				ret.put("freeTypes", cellInventory.getRemainingItemTypes());

				return ret;
			}
		}

		return null;
	}

	@Override
	public String getKey() {
		return "me_cell";
	}

}

@@ -159,16 +159,14 @@
 api.
-helpers.
+meta.I
 Item
@@ -162,32 +162,38 @@
 .meta.IItemStack
+Custom
 MetaProviderSimp
@@ -188,22 +188,16 @@
 Provider
-Simple
 ;%0Aimport
@@ -326,16 +326,20 @@
 der 
-extend
+implement
 s 
+I
 Item
@@ -343,16 +343,22 @@
 temStack
+Custom
 MetaProv
@@ -365,22 +365,16 @@
 ider
-Simple
 %3CItem%3E %7B
 %0A%0A%09@
@@ -369,16 +369,302 @@
 %3CItem%3E %7B
+%0A%0A%09@Override%0A%09public String getKey() %7B%0A%09%09return %22me_cell%22;%0A%09%7D%0A%0A%09@Override%0A%09public Class%3C? extends Item%3E getTargetClass() %7B%0A%09%09return Item.class;%0A%09%7D%0A%0A%09@Override%0A%09public boolean canApply(Item target, ItemStack stack) %7B%0A%09%09return AEApi.instance().registries().cell().isCellHandled(stack);%0A%09%7D
 %0A%0A%09@Over
@@ -1654,67 +1654,6 @@
 %09%7D%0A%0A
-%09@Override%0A%09public String getKey() %7B%0A%09%09return %22me_cell%22;%0A%09%7D%0A%0A
 %7D%0A

Add custom filter rules to ME cell provider (missed that one)