Applied-Energistics-2-tiler.../src/main/java/appeng/core/features/registries/RecipeHandlerRegistry.java
thatsIch 29a55f914b Fixes #1786: Locale critical code now uses the english local for transmission. Fixes Turkish Problem.
Applied English Locale where localization is not expected as in internal recipe handling and IMC handling, basically which interacts with public API where we either require to enforce the incoming text with regex ([a-z0-9]) or just expect proper usage of the API, but with just using upper cases in recipe files it would break in Turkish Locale like

ALIAS

another option would have been to use `equalsIgnoreCase` in some cases, but not all applicable
2015-09-30 13:26:56 +02:00

116 lines
2.8 KiB
Java

/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2015, AlgorithmX2, All rights reserved.
*
* Applied Energistics 2 is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Applied Energistics 2 is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with Applied Energistics 2. If not, see <http://www.gnu.org/licenses/lgpl>.
*/
package appeng.core.features.registries;
import java.util.Collection;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.Locale;
import java.util.Map;
import javax.annotation.Nullable;
import appeng.api.features.IRecipeHandlerRegistry;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IRecipeHandler;
import appeng.api.recipes.ISubItemResolver;
import appeng.core.AELog;
import appeng.recipes.RecipeHandler;
/**
* @author AlgorithmX2
* @author thatsIch
* @version rv3 - 10.08.2015
* @since rv0
*/
public class RecipeHandlerRegistry implements IRecipeHandlerRegistry
{
private final Map<String, Class<? extends ICraftHandler>> handlers = new HashMap<String, Class<? extends ICraftHandler>>( 20 );
private final Collection<ISubItemResolver> resolvers = new LinkedList<ISubItemResolver>();
@Override
public void addNewCraftHandler( String name, Class<? extends ICraftHandler> handler )
{
this.handlers.put( name.toLowerCase( Locale.ENGLISH ), handler );
}
@Override
public void addNewSubItemResolver( ISubItemResolver sir )
{
this.resolvers.add( sir );
}
@Nullable
@Override
public ICraftHandler getCraftHandlerFor( String name )
{
Class<? extends ICraftHandler> clz = this.handlers.get( name );
if( clz == null )
{
return null;
}
try
{
return clz.newInstance();
}
catch( Throwable e )
{
AELog.severe( "Error Caused when trying to construct " + clz.getName() );
AELog.error( e );
this.handlers.put( name, null ); // clear it..
return null;
}
}
@Override
public IRecipeHandler createNewRecipehandler()
{
return new RecipeHandler();
}
@Nullable
@Override
public Object resolveItem( String nameSpace, String itemName )
{
for( ISubItemResolver sir : this.resolvers )
{
Object rr = null;
try
{
rr = sir.resolveItemByName( nameSpace, itemName );
}
catch( Throwable t )
{
AELog.error( t );
}
if( rr != null )
{
return rr;
}
}
return null;
}
}