package net.mcft.copy.betterstorage.inventory;

import net.mcft.copy.betterstorage.block.tileentity.TileEntityContainer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;

/** An inventory that is connected to a TileEntityInventoy. */
public class InventoryTileEntity extends InventoryBetterStorage {
	
	public final TileEntityContainer mainTileEntity;
	public final TileEntityContainer[] tileEntities;
	public final IInventory inventory;
	public final int columns, rows;
	
	private InventoryTileEntity(TileEntityContainer mainTileEntity, TileEntityContainer[] tileEntities, IInventory inventory) {
		this.mainTileEntity = mainTileEntity;
		this.tileEntities = tileEntities;
		this.inventory = inventory;
		
		columns = mainTileEntity.getColumns();
		rows = inventory.getSizeInventory() / columns;
	}
	public InventoryTileEntity(TileEntityContainer mainTileEntity, TileEntityContainer... tileEntities) {
		this(mainTileEntity, tileEntities, new InventoryStacks(getAllContents(tileEntities)));
	}
	public InventoryTileEntity(TileEntityContainer tileEntity) {
		this(tileEntity, new TileEntityContainer[]{ tileEntity }, new InventoryStacks(tileEntity.contents));
	}
	
	private static ItemStack[][] getAllContents(TileEntityContainer... tileEntities) {
		ItemStack[][] allContents = new ItemStack[tileEntities.length][];
		for (int i = 0; i < tileEntities.length; i++)
			allContents[i] = tileEntities[i].contents;
		return allContents;
	}
	
	@Override
	public String getInvName() { return mainTileEntity.getContainerTitle(); }
	@Override
	public boolean isInvNameLocalized() { return !mainTileEntity.shouldLocalizeTitle(); }
	
	@Override
	public int getSizeInventory() { return inventory.getSizeInventory(); }
	@Override
	public ItemStack getStackInSlot(int slot) { return inventory.getStackInSlot(slot); }
	@Override
	public void setInventorySlotContents(int slot, ItemStack stack) {
		inventory.setInventorySlotContents(slot, stack);
	}
	@Override
	public void onInventoryChanged() {  }
	
	@Override
	public boolean isUseableByPlayer(EntityPlayer player) {
		for (TileEntityContainer tileEntity : tileEntities)
			if (!tileEntity.canPlayerUseContainer(player))
				return false;
		return true;
	}
	@Override
	public void openChest() {
		mainTileEntity.onContainerOpened();
	}
	@Override
	public void closeChest() {
		mainTileEntity.onContainerClosed();
	}
	
}

@@ -548,22 +548,21 @@
 ws;%0A%09%0A%09p
-rivate
+ublic
  Invento
@@ -1125,16 +1125,38 @@
 leEntity
+, IInventory inventory
 ) %7B%0A%09%09th
@@ -1210,16 +1210,112 @@
 ntity %7D,
+ inventory);%0A%09%7D%0A%09public InventoryTileEntity(TileEntityContainer tileEntity) %7B%0A%09%09this(tileEntity,
  new Inv

Add InventoryTileEntity(TileEntity, IInventory)