package codechicken.lib.inventory;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.text.ITextComponent;
import net.minecraft.util.text.TextComponentString;

/**
 * Simple IInventory implementation with an array of items, name and maximum stack size
 */
public class InventorySimple implements IInventory {
    public ItemStack[] items;
    public int limit;
    public String name;

    public InventorySimple(ItemStack[] items, int limit, String name) {
        this.items = items;
        this.limit = limit;
        this.name = name;
    }

    public InventorySimple(ItemStack[] items, String name) {
        this(items, 64, name);
    }

    public InventorySimple(ItemStack[] items, int limit) {
        this(items, limit, "inv");
    }

    public InventorySimple(ItemStack[] items) {
        this(items, 64, "inv");
    }

    public InventorySimple(int size, int limit, String name) {
        this(new ItemStack[size], limit, name);
    }

    public InventorySimple(int size, int limit) {
        this(size, limit, "inv");
    }

    public InventorySimple(int size, String name) {
        this(size, 64, name);
    }

    public InventorySimple(int size) {
        this(size, 64, "inv");
    }

    @Override
    public int getSizeInventory() {
        return items.length;
    }

    @Override
    public ItemStack getStackInSlot(int slot) {
        return items[slot];
    }

    @Override
    public ItemStack decrStackSize(int slot, int amount) {
        return InventoryUtils.decrStackSize(this, slot, amount);
    }

    @Override
    public ItemStack removeStackFromSlot(int slot) {
        return InventoryUtils.removeStackFromSlot(this, slot);
    }

    @Override
    public void setInventorySlotContents(int slot, ItemStack stack) {
        items[slot] = stack;
        markDirty();
    }

    @Override
    public int getInventoryStackLimit() {
        return limit;
    }

    @Override
    public boolean isUseableByPlayer(EntityPlayer var1) {
        return true;
    }

    @Override
    public boolean isItemValidForSlot(int i, ItemStack itemstack) {
        return true;
    }

    @Override
    public void markDirty() {
    }

    @Override
    public void openInventory(EntityPlayer player) {
    }

    @Override
    public void closeInventory(EntityPlayer player) {
    }

    @Override
    public int getField(int id) {
        return 0;
    }

    @Override
    public void setField(int id, int value) {
    }

    @Override
    public int getFieldCount() {
        return 0;
    }

    @Override
    public void clear() {
        for (int i = 0; i < items.length; i++) {
            items[i] = null;
        }
    }

    @Override
    public String getName() {
        return "name";
    }

    @Override
    public boolean hasCustomName() {
        return true;
    }

    @Override
    public ITextComponent getDisplayName() {
        return new TextComponentString(getName());
    }
}

@@ -158,16 +158,54 @@
 mStack;%0A
+import net.minecraft.util.EnumFacing;%0A
 import n
@@ -294,16 +294,248 @@
 tString;
+%0Aimport net.minecraftforge.common.capabilities.Capability;%0Aimport net.minecraftforge.common.capabilities.ICapabilityProvider;%0Aimport net.minecraftforge.items.CapabilityItemHandler;%0Aimport net.minecraftforge.items.wrapper.InvWrapper;
 %0A%0A/**%0A *
@@ -674,16 +674,37 @@
 nventory
+, ICapabilityProvider
  %7B%0A    p
@@ -3314,11 +3314,472 @@
 );%0A    %7D
+%0A%0A    @Override%0A    public boolean hasCapability(Capability%3C?%3E capability, EnumFacing facing) %7B%0A        return capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY;%0A    %7D%0A%0A    @SuppressWarnings(%22unchecked%22)%0A    @Override%0A    public %3CT%3E T getCapability(Capability%3CT%3E capability, EnumFacing facing) %7B%0A        if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)%7B%0A            return (T) new InvWrapper(this);%0A        %7D%0A        return null;%0A    %7D
 %0A%7D%0A

implement ICapabilityProvider on InventorySimple.