2014-02-20 00:33:36 +01:00
|
|
|
package appeng.core.features.registries;
|
|
|
|
|
|
|
|
import java.util.HashMap;
|
2014-02-25 06:33:31 +01:00
|
|
|
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;
|
2014-02-25 06:33:31 +01:00
|
|
|
import appeng.api.recipes.ISubItemResolver;
|
2014-02-20 00:33:36 +01:00
|
|
|
import appeng.core.AELog;
|
|
|
|
import appeng.recipes.RecipeHandler;
|
|
|
|
|
2014-02-25 06:33:31 +01:00
|
|
|
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
|
2014-02-25 06:33:31 +01:00
|
|
|
public void addNewCraftHandler(String name, Class<? extends ICraftHandler> handler)
|
|
|
|
{
|
|
|
|
handlers.put( name.toLowerCase(), handler );
|
2014-02-20 00:33:36 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-02-25 06:33:31 +01:00
|
|
|
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();
|
2014-02-25 06:33:31 +01:00
|
|
|
}
|
|
|
|
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
|
2014-02-25 06:33:31 +01:00
|
|
|
public IRecipeHandler createNewRecipehandler()
|
|
|
|
{
|
2014-02-20 00:33:36 +01:00
|
|
|
return new RecipeHandler();
|
|
|
|
}
|
2014-02-25 06:33:31 +01:00
|
|
|
|
|
|
|
@Override
|
|
|
|
public void addNewSubItemResolver(ISubItemResolver sir)
|
|
|
|
{
|
|
|
|
resolvers.add( sir );
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2014-03-10 03:11:29 +01:00
|
|
|
public Object resolveItem(String nameSpace, String itemName)
|
2014-02-25 06:33:31 +01:00
|
|
|
{
|
|
|
|
for (ISubItemResolver sir : resolvers)
|
|
|
|
{
|
2014-03-10 03:11:29 +01:00
|
|
|
Object rr = null;
|
2014-03-09 22:39:30 +01:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
rr = sir.resolveItemByName( nameSpace, itemName );
|
|
|
|
}
|
|
|
|
catch (Throwable t)
|
|
|
|
{
|
|
|
|
AELog.error( t );
|
|
|
|
}
|
2014-02-25 06:33:31 +01:00
|
|
|
|
|
|
|
if ( rr != null )
|
|
|
|
return rr;
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2014-02-20 00:33:36 +01:00
|
|
|
}
|