package crazypants.enderio.machine.vacuum;

import java.awt.Point;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

import com.enderio.core.common.ContainerEnder;

public class ContainerVacuumChest extends ContainerEnder<TileVacuumChest> {

  private Slot filterSlot;
  private Runnable filterChangedCB;

  public ContainerVacuumChest(EntityPlayer player, InventoryPlayer inventory, final TileVacuumChest te) {
    super(inventory, te);
  }
  
  @Override
  protected void addSlots(InventoryPlayer playerInv) {
    int x = 8;
    int y = 18;
    int index = -1;
    for (int i = 0; i < TileVacuumChest.ITEM_ROWS; ++i) {
      for (int j = 0; j < 9; ++j) {
        addSlotToContainer(new Slot(getInv(), ++index, x + j * 18, y + i * 18));
      }
    }

    filterSlot = new FilterSlot(new InventoryFilterUpgrade(getInv()));
    addSlotToContainer(filterSlot);
  }
  
  @Override
  public Point getPlayerInventoryOffset() {
    Point p = super.getPlayerInventoryOffset();
    p.translate(0, 40);
    return p;
  }

  @Override
  public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) {
    ItemStack itemstack = null;
    Slot slot = (Slot) this.inventorySlots.get(par2);

    if(slot != null && slot.getHasStack()) {
      ItemStack itemstack1 = slot.getStack();
      itemstack = itemstack1.copy();

      if(par2 < TileVacuumChest.ITEM_SLOTS) {
        if(!this.mergeItemStack(itemstack1, TileVacuumChest.ITEM_SLOTS, this.inventorySlots.size()-1, true)) {
          return null;
        }
      } else if(!this.mergeItemStack(itemstack1, 0, TileVacuumChest.ITEM_SLOTS, false)) {
        return null;
      }

      if(itemstack1.stackSize == 0) {
        slot.putStack((ItemStack) null);
      } else {
        slot.onSlotChanged();
      }
    }
    return itemstack;
  }

  void setFilterChangedCB(Runnable filterChangedCB) {
    this.filterChangedCB = filterChangedCB;
  }

  void filterChanged() {
    if(filterChangedCB != null) {
      filterChangedCB.run();
    }
  }

  class FilterSlot extends Slot {
    InventoryFilterUpgrade inv;

    FilterSlot(InventoryFilterUpgrade inv) {
      super(inv, 0, 8, 86);
      this.inv = inv;
    }

    @Override
    public void onSlotChanged() {
      filterChanged();
    }

    @Override
    public boolean isItemValid(ItemStack stack) {
      return inv.isItemValidForSlot(0, stack);
    }
  }
}

@@ -628,24 +628,132 @@
 layerInv) %7B%0A
+    filterSlot = new FilterSlot(new InventoryFilterUpgrade(getInv()));%0A    addSlotToContainer(filterSlot);%0A%0A
     int x = 
@@ -755,16 +755,16 @@
  x = 8;%0A
-
     int 
@@ -983,116 +983,8 @@
    %7D
-%0A%0A    filterSlot = new FilterSlot(new InventoryFilterUpgrade(getInv()));%0A    addSlotToContainer(filterSlot);
 %0A  %7D
@@ -1115,16 +1115,16 @@
 0, 40);%0A
+
     retu
@@ -1138,793 +1138,8 @@
  %7D%0A%0A
-  @Override%0A  public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) %7B%0A    ItemStack itemstack = null;%0A    Slot slot = (Slot) this.inventorySlots.get(par2);%0A%0A    if(slot != null && slot.getHasStack()) %7B%0A      ItemStack itemstack1 = slot.getStack();%0A      itemstack = itemstack1.copy();%0A%0A      if(par2 %3C TileVacuumChest.ITEM_SLOTS) %7B%0A        if(!this.mergeItemStack(itemstack1, TileVacuumChest.ITEM_SLOTS, this.inventorySlots.size()-1, true)) %7B%0A          return null;%0A        %7D%0A      %7D else if(!this.mergeItemStack(itemstack1, 0, TileVacuumChest.ITEM_SLOTS, false)) %7B%0A        return null;%0A      %7D%0A%0A      if(itemstack1.stackSize == 0) %7B%0A        slot.putStack((ItemStack) null);%0A      %7D else %7B%0A        slot.onSlotChanged();%0A      %7D%0A    %7D%0A    return itemstack;%0A  %7D%0A%0A
   vo

Fix Vacuum Chest shift-click