package mcjty.rftools.blocks.crafter;

import mcjty.lib.container.*;
import mcjty.rftools.RFTools;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation;

public class CrafterContainer extends GenericContainer {
    public static final String CONTAINER_INVENTORY = "container";

    public static final int SLOT_CRAFTINPUT = 0;
    public static final int SLOT_CRAFTOUTPUT = 9;
    public static final int SLOT_BUFFER = 10;
    public static final int BUFFER_SIZE = (13*2);
    public static final int SLOT_BUFFEROUT = SLOT_BUFFER + BUFFER_SIZE;
    public static final int BUFFEROUT_SIZE = 4;
    public static final int SLOT_FILTER_MODULE = SLOT_BUFFEROUT + BUFFEROUT_SIZE;

    private final CrafterBaseTE crafterBaseTE;

    public CrafterBaseTE getCrafterTE() {
        return crafterBaseTE;
    }

    public static final ContainerFactory CONTAINER_FACTORY = new ContainerFactory(new ResourceLocation(RFTools.MODID, "gui/crafter.gui"));

    public CrafterContainer(EntityPlayer player, IInventory containerInventory) {
        super(CONTAINER_FACTORY);
        this.crafterBaseTE = (CrafterBaseTE)containerInventory; // TODO once this method is no longer reflectively called, refactor to remove this cast
        addInventory(CONTAINER_INVENTORY, containerInventory);
        addInventory(ContainerFactory.CONTAINER_PLAYER, player.inventory);
        generateSlots();
    }

    @Override
    protected Slot createSlot(SlotFactory slotFactory, IInventory inventory, int index, int x, int y, SlotType slotType) {
        if (index >= SLOT_BUFFER && index < SLOT_BUFFEROUT && slotType == SlotType.SLOT_INPUT) {
            return new BaseSlot(inventory, index, x, y) {
                @Override
                public boolean isItemValid(ItemStack stack) {
                    if (!crafterBaseTE.isItemValidForSlot(getSlotIndex(), stack)) {
                        return false;
                    }
                    return super.isItemValid(stack);
                }
            };
        } else if (index >= SLOT_BUFFEROUT && index < SLOT_FILTER_MODULE) {
            return new BaseSlot(inventory, index, x, y) {
                @Override
                public boolean isItemValid(ItemStack stack) {
                    if (!crafterBaseTE.isItemValidForSlot(getSlotIndex(), stack)) {
                        return false;
                    }
                    return super.isItemValid(stack);
                }
            };
        }
        return super.createSlot(slotFactory, inventory, index, x, y, slotType);
    }
}

@@ -2116,32 +2116,223 @@
                %7D
+%0A%0A                @Override%0A                public void onSlotChanged() %7B%0A                    crafterBaseTE.noRecipesWork = false;%0A                    super.onSlotChanged();%0A                %7D
 %0A            %7D;%0A
@@ -2759,32 +2759,223 @@
                %7D
+%0A%0A                @Override%0A                public void onSlotChanged() %7B%0A                    crafterBaseTE.noRecipesWork = false;%0A                    super.onSlotChanged();%0A                %7D
 %0A            %7D;%0A

Fix #1730