package common.init;

import java.util.Map;

import common.collect.Maps;
import common.tileentity.TileEntity;
import common.tileentity.TileEntityBanner;
import common.tileentity.TileEntityBeacon;
import common.tileentity.TileEntityBrewingStand;
import common.tileentity.TileEntityChest;
import common.tileentity.TileEntityComparator;
import common.tileentity.TileEntityDaylightDetector;
import common.tileentity.TileEntityDispenser;
import common.tileentity.TileEntityDropper;
import common.tileentity.TileEntityEnchantmentTable;
import common.tileentity.TileEntityFurnace;
import common.tileentity.TileEntityHopper;
import common.tileentity.TileEntityMobSpawner;
import common.tileentity.TileEntityPiston;
import common.tileentity.TileEntitySign;
import common.tileentity.TileEntityTianReactor;

public abstract class TileRegistry {
	public static final Map<String, Class<? extends TileEntity>> NAME_TO_CLASS = Maps.<String, Class<? extends TileEntity>>newHashMap();
	public static final Map<Class<? extends TileEntity>, String> CLASS_TO_NAME = Maps.<Class<? extends TileEntity>, String>newHashMap();
	public static final Map<Class<? extends TileEntity>, Integer> CLASS_TO_ID = Maps.<Class<? extends TileEntity>, Integer>newHashMap();
	
	private static int nextId;

	private static void addMapping(Class<? extends TileEntity> cl, String id) {
		if(NAME_TO_CLASS.containsKey(id))
			throw new IllegalArgumentException("Duplicate id: " + id);
		NAME_TO_CLASS.put(id, cl);
		CLASS_TO_NAME.put(cl, id);
		CLASS_TO_ID.put(cl, ++nextId);
	}

	static void register() {
		addMapping(TileEntityFurnace.class, "Furnace");
		addMapping(TileEntityChest.class, "Chest");
		addMapping(TileEntityDispenser.class, "Trap");
		addMapping(TileEntityDropper.class, "Dropper");
		addMapping(TileEntitySign.class, "Sign");
		addMapping(TileEntityPiston.class, "Piston");
		addMapping(TileEntityBrewingStand.class, "Cauldron");
		addMapping(TileEntityEnchantmentTable.class, "EnchantTable");
		addMapping(TileEntityBeacon.class, "Beacon");
		addMapping(TileEntityDaylightDetector.class, "DLDetector");
		addMapping(TileEntityHopper.class, "Hopper");
		addMapping(TileEntityComparator.class, "Comparator");
		addMapping(TileEntityBanner.class, "Banner");
		addMapping(TileEntityTianReactor.class, "TianReactor");
		addMapping(TileEntityMobSpawner.class, "MobSpawner");
	}
}
