Applied-Energistics-2-tiler.../core/features/registries/RecipeHandlerRegistry.java

80 lines
1.7 KiB
Java
Raw Normal View History

2014-02-20 00:33:36 +01:00
package appeng.core.features.registries;
import java.util.HashMap;
import java.util.LinkedList;
2014-02-20 00:33:36 +01:00
import appeng.api.features.IRecipeHandlerRegistry;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IRecipeHandler;
import appeng.api.recipes.ISubItemResolver;
2014-02-20 00:33:36 +01:00
import appeng.core.AELog;
import appeng.recipes.RecipeHandler;
public class RecipeHandlerRegistry implements IRecipeHandlerRegistry
{
HashMap<String, Class<? extends ICraftHandler>> handlers = new HashMap<String, Class<? extends ICraftHandler>>();
LinkedList<ISubItemResolver> resolvers = new LinkedList<ISubItemResolver>();
2014-02-20 00:33:36 +01:00
@Override
public void addNewCraftHandler(String name, Class<? extends ICraftHandler> handler)
{
handlers.put( name.toLowerCase(), handler );
2014-02-20 00:33:36 +01:00
}
@Override
public ICraftHandler getCraftHandlerFor(String name)
{
Class<? extends ICraftHandler> clz = handlers.get( name );
if ( clz == null )
return null;
try
{
2014-02-20 00:33:36 +01:00
return clz.newInstance();
}
catch (Throwable e)
{
AELog.severe( "Error Caused when trying to construct " + clz.getName() );
AELog.error( e );
handlers.put( name, null ); // clear it..
2014-02-20 00:33:36 +01:00
return null;
}
}
@Override
public IRecipeHandler createNewRecipehandler()
{
2014-02-20 00:33:36 +01:00
return new RecipeHandler();
}
@Override
public void addNewSubItemResolver(ISubItemResolver sir)
{
resolvers.add( sir );
}
@Override
public Object resolveItem(String nameSpace, String itemName)
{
for (ISubItemResolver sir : resolvers)
{
Object rr = null;
try
{
rr = sir.resolveItemByName( nameSpace, itemName );
}
catch (Throwable t)
{
AELog.error( t );
}
if ( rr != null )
return rr;
}
return null;
}
2014-02-20 00:33:36 +01:00
}