Rework custom recipe system (#3232)

This commit is contained in:
fscan
2018-06-24 17:20:29 +02:00
committed by GitHub
parent e72b5b369c
commit 841bc6e356
165 changed files with 680 additions and 6300 deletions
@@ -49,8 +49,6 @@ import appeng.core.features.AEFeature;
import appeng.core.localization.GuiText;
import appeng.integration.Integrations;
import appeng.items.parts.ItemFacade;
import appeng.recipes.game.ShapedRecipe;
import appeng.recipes.game.ShapelessRecipe;
@mezz.jei.api.JEIPlugin
@@ -68,9 +66,6 @@ public class JEIPlugin implements IModPlugin
@Override
public void register( IModRegistry registry )
{
registry.handleRecipes( ShapedRecipe.class, new ShapedRecipeHandler(), VanillaRecipeCategoryUid.CRAFTING );
registry.handleRecipes( ShapelessRecipe.class, new ShapelessRecipeHandler(), VanillaRecipeCategoryUid.CRAFTING );
IDefinitions definitions = AEApi.instance().definitions();
this.registerFacadeRecipe( definitions, registry );
@@ -1,35 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, 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.integration.modules.jei;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.IRecipeWrapperFactory;
import appeng.recipes.game.ShapedRecipe;
class ShapedRecipeHandler implements IRecipeWrapperFactory<ShapedRecipe>
{
@Override
public IRecipeWrapper getRecipeWrapper( ShapedRecipe recipe )
{
return new ShapedRecipeWrapper( recipe );
}
}
@@ -1,102 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, 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.integration.modules.jei;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.ItemStack;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.wrapper.IShapedCraftingRecipeWrapper;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.IIngredient;
import appeng.core.AEConfig;
import appeng.recipes.game.ShapedRecipe;
import appeng.util.Platform;
class ShapedRecipeWrapper implements IShapedCraftingRecipeWrapper
{
private final ShapedRecipe recipe;
public ShapedRecipeWrapper( ShapedRecipe recipe )
{
this.recipe = recipe;
}
@Override
public void getIngredients( IIngredients ingredients )
{
final boolean useSingleItems = AEConfig.instance().disableColoredCableRecipesInJEI();
Object[] items = this.recipe.getIIngredients();
int width = this.recipe.getWidth();
int height = this.recipe.getHeight();
List<List<ItemStack>> in = new ArrayList<>( width * height );
for( int x = 0; x < width; x++ )
{
for( int y = 0; y < height; y++ )
{
if( items[( x * height + y )] != null )
{
final IIngredient ing = (IIngredient) items[( x * height + y )];
List<ItemStack> slotList = Collections.emptyList();
try
{
ItemStack[] is = ing.getItemStackSet();
slotList = useSingleItems ? Platform.findPreferred( is ) : Arrays.asList( is );
}
catch( final RegistrationException | MissingIngredientException ignored )
{
}
in.add( slotList );
}
else
{
in.add( Collections.emptyList() );
}
}
}
ingredients.setInputLists( ItemStack.class, in );
ingredients.setOutput( ItemStack.class, this.recipe.getRecipeOutput() );
}
@Override
public int getWidth()
{
return this.recipe.getWidth();
}
@Override
public int getHeight()
{
return this.recipe.getHeight();
}
}
@@ -1,35 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, 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.integration.modules.jei;
import mezz.jei.api.recipe.IRecipeWrapper;
import mezz.jei.api.recipe.IRecipeWrapperFactory;
import appeng.recipes.game.ShapelessRecipe;
class ShapelessRecipeHandler implements IRecipeWrapperFactory<ShapelessRecipe>
{
@Override
public IRecipeWrapper getRecipeWrapper( ShapelessRecipe recipe )
{
return new ShapelessRecipeWrapper( recipe );
}
}
@@ -1,73 +0,0 @@
/*
* This file is part of Applied Energistics 2.
* Copyright (c) 2013 - 2014, 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.integration.modules.jei;
import java.util.ArrayList;
import java.util.List;
import com.google.common.collect.Lists;
import net.minecraft.item.ItemStack;
import mezz.jei.api.ingredients.IIngredients;
import mezz.jei.api.recipe.IRecipeWrapper;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.IIngredient;
import appeng.recipes.game.ShapelessRecipe;
class ShapelessRecipeWrapper implements IRecipeWrapper
{
private final ShapelessRecipe recipe;
public ShapelessRecipeWrapper( ShapelessRecipe recipe )
{
this.recipe = recipe;
}
@Override
public void getIngredients( IIngredients ingredients )
{
List<Object> recipeInput = this.recipe.getInput();
List<List<ItemStack>> inputs = new ArrayList<>( recipeInput.size() );
for( Object inputObj : recipeInput )
{
if( inputObj instanceof IIngredient )
{
IIngredient ingredient = (IIngredient) inputObj;
try
{
inputs.add( Lists.newArrayList( ingredient.getItemStackSet() ) );
}
catch( RegistrationException | MissingIngredientException registrationError )
{
throw new RuntimeException( "Unable to register recipe with JEI" );
}
}
}
ingredients.setInputLists( ItemStack.class, inputs );
ingredients.setOutput( ItemStack.class, this.recipe.getRecipeOutput() );
}
}