Refactored GrinderRegistry. (#2644)

* Refactored GrinderRegistry.

Changed IGrinderRegistry#getRecipes to return an unmodifiable collection.
Added a way to remove recipes explicitly instead the internal list.
Added a cache to lookup recipes instead of iterating a list.

Renamed IGrinderEntry to IGrinderRecipe
Made IGrindRecipe immutable for easy caching.

Improved GrinderLogging and Exception Handling
JEI Workaround as it expects a List instead Collection.

* Added blacklist of explicit oredict names for the grindstone.

This can be used should the automatic recipe generation create unintended
loopholes.
This commit is contained in:
yueh
2016-12-02 23:47:50 +01:00
committed by GitHub
parent c405e725b2
commit eb1e86cacb
10 changed files with 361 additions and 265 deletions
@@ -22,16 +22,16 @@ package appeng.integration.modules.jei;
import mezz.jei.api.recipe.IRecipeHandler;
import mezz.jei.api.recipe.IRecipeWrapper;
import appeng.api.features.IGrinderEntry;
import appeng.api.features.IGrinderRecipe;
class GrinderRecipeHandler implements IRecipeHandler<IGrinderEntry>
class GrinderRecipeHandler implements IRecipeHandler<IGrinderRecipe>
{
@Override
public Class<IGrinderEntry> getRecipeClass()
public Class<IGrinderRecipe> getRecipeClass()
{
return IGrinderEntry.class;
return IGrinderRecipe.class;
}
@Override
@@ -41,19 +41,19 @@ class GrinderRecipeHandler implements IRecipeHandler<IGrinderEntry>
}
@Override
public String getRecipeCategoryUid( IGrinderEntry recipe )
public String getRecipeCategoryUid( IGrinderRecipe recipe )
{
return GrinderRecipeCategory.UID;
}
@Override
public IRecipeWrapper getRecipeWrapper( IGrinderEntry recipe )
public IRecipeWrapper getRecipeWrapper( IGrinderRecipe recipe )
{
return new GrinderRecipeWrapper( recipe );
}
@Override
public boolean isRecipeValid( IGrinderEntry recipe )
public boolean isRecipeValid( IGrinderRecipe recipe )
{
return true;
}
@@ -31,15 +31,15 @@ import net.minecraft.item.ItemStack;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.BlankRecipeWrapper;
import appeng.api.features.IGrinderEntry;
import appeng.api.features.IGrinderRecipe;
class GrinderRecipeWrapper extends BlankRecipeWrapper
{
private final IGrinderEntry recipe;
private final IGrinderRecipe recipe;
GrinderRecipeWrapper( IGrinderEntry recipe )
GrinderRecipeWrapper( IGrinderRecipe recipe )
{
this.recipe = recipe;
}
@@ -50,14 +50,8 @@ class GrinderRecipeWrapper extends BlankRecipeWrapper
ingredients.setInput( ItemStack.class, recipe.getInput() );
List<ItemStack> outputs = new ArrayList<>( 3 );
outputs.add( recipe.getOutput() );
if( recipe.getOptionalOutput() != null )
{
outputs.add( recipe.getOptionalOutput() );
}
if( recipe.getSecondOptionalOutput() != null )
{
outputs.add( recipe.getSecondOptionalOutput() );
}
recipe.getOptionalOutput().ifPresent( outputs::add );
recipe.getSecondOptionalOutput().ifPresent( outputs::add );
ingredients.setOutputs( ItemStack.class, outputs );
}
@@ -24,6 +24,7 @@ import java.util.List;
import java.util.Optional;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Lists;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@@ -70,8 +71,10 @@ public class JEIPlugin extends BlankModPlugin
registerDescriptions( definitions, registry );
// Allow recipe transfer from JEI to crafting and pattern terminal
registry.getRecipeTransferRegistry().addRecipeTransferHandler( new RecipeTransferHandler<>( ContainerCraftingTerm.class ), VanillaRecipeCategoryUid.CRAFTING );
registry.getRecipeTransferRegistry().addRecipeTransferHandler( new RecipeTransferHandler<>( ContainerPatternTerm.class ), VanillaRecipeCategoryUid.CRAFTING );
registry.getRecipeTransferRegistry().addRecipeTransferHandler( new RecipeTransferHandler<>( ContainerCraftingTerm.class ),
VanillaRecipeCategoryUid.CRAFTING );
registry.getRecipeTransferRegistry().addRecipeTransferHandler( new RecipeTransferHandler<>( ContainerPatternTerm.class ),
VanillaRecipeCategoryUid.CRAFTING );
}
private void registerDescriptions( IDefinitions definitions, IModRegistry registry )
@@ -130,7 +133,7 @@ public class JEIPlugin extends BlankModPlugin
return;
}
registry.addRecipes( AEApi.instance().registries().grinder().getRecipes() );
registry.addRecipes( Lists.newArrayList( AEApi.instance().registries().grinder().getRecipes() ) );
registry.addRecipeHandlers( new GrinderRecipeHandler() );
registry.addRecipeCategories( new GrinderRecipeCategory( registry.getJeiHelpers().getGuiHelper() ) );
registry.addRecipeCategoryCraftingItem( grindstone, GrinderRecipeCategory.UID );