package org.cyclops.cyclopscore.tileentity;

import com.google.common.collect.Maps;
import net.minecraft.util.EnumFacing;
import org.cyclops.cyclopscore.helper.DirectionHelpers;
import org.cyclops.cyclopscore.inventory.SimpleInventory;

import java.util.Collection;
import java.util.Map;

/**
 * A TileEntity with a static internal inventory.
 * @author rubensworks
 *
 */
public abstract class InventoryTileEntity extends InventoryTileEntityBase {
    
    protected SimpleInventory inventory;
    protected Map<EnumFacing, int[]> slotSides;
    
    /**
     * Make new tile with an inventory.
     * @param inventorySize Amount of slots in the inventory.
     * @param inventoryName Internal name of the inventory.
     * @param stackSize The maximum stacksize each slot can have
     */
    public InventoryTileEntity(int inventorySize, String inventoryName, int stackSize) {
        inventory = new SimpleInventory(inventorySize , inventoryName, stackSize);
        slotSides = Maps.newHashMap();
        for(EnumFacing side : DirectionHelpers.DIRECTIONS) {
            slotSides.put(side, new int[0]);
        }
    }
    
    /**
     * Make new tile with an inventory.
     * @param inventorySize Amount of slots in the inventory.
     * @param inventoryName Internal name of the inventory.
     */
    public InventoryTileEntity(int inventorySize, String inventoryName) {
        this(inventorySize , inventoryName, 64);
    }
    
    /**
     * Add mappings to slots to a certain (normalized) side of this TileEntity.
     * @param side The side to map this slots to.
     * @param slots The numerical representations of the slots to map.
     */
    protected void addSlotsToSide(EnumFacing side, Collection<Integer> slots) {
        int[] currentSlots = slotSides.get(side);
        int[] newSlots = new int[currentSlots.length + slots.size()];
        System.arraycopy(currentSlots, 0, newSlots, 0, currentSlots.length);
        int offset = currentSlots.length;
        for(int slot : slots) {
            newSlots[offset++] = slot;
        }
        slotSides.put(side, newSlots);
    }
    
    /**
     * Get the internal inventory.
     * @return The SimpleInventory.
     */
    public SimpleInventory getInventory() {
        return inventory;
    }

    @Override
    public int[] getSlotsForFace(EnumFacing side) {
        return slotSides.get(side);
    }

}

@@ -49,65 +49,83 @@
 ort 
-com.google.common.collect.Maps;%0Aimport net.minecraft.util
+net.minecraft.util.EnumFacing;%0Aimport org.cyclops.cyclopscore.datastructure
 .Enu
@@ -123,32 +123,35 @@
 cture.EnumFacing
+Map
 ;%0Aimport org.cyc
@@ -283,30 +283,8 @@
 ion;
-%0Aimport java.util.Map;
 %0A%0A/*
@@ -505,12 +505,8 @@
 ted 
-Map%3C
 Enum
@@ -511,18 +511,20 @@
 umFacing
-, 
+Map%3C
 int%5B%5D%3E s
@@ -977,20 +977,25 @@
 s = 
+EnumFacing
 Map
-s
 .new
-Hash
 Map(

Improve inventory side slot retrieval efficiency