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
@@ -1,88 +0,0 @@
/*
* 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.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.integration.Integrations;
import appeng.integration.abstraction.IRC;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Crusher implements ICraftHandler, IWebsiteSerializer
{
private IIngredient pro_input;
private IIngredient[] pro_output;
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
if( input.size() == 1 && output.size() == 1 )
{
final int outs = output.get( 0 ).size();
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
throw new RecipeException( "Crusher must have a single input, and single output." );
}
@Override
public void register() throws RegistrationException, MissingIngredientException
{
final IRC rc = Integrations.rc();
for( final ItemStack is : this.pro_input.getItemStackSet() )
{
try
{
rc.rockCrusher( is, this.pro_output[0].getItemStack() );
}
catch( final java.lang.RuntimeException err )
{
AELog.info( "RC not happy - " + err.getMessage() );
}
}
}
@Override
public String getPattern( final RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( final ItemStack output ) throws RegistrationException, MissingIngredientException
{
return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output );
}
}
@@ -1,88 +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.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.features.IGrinderRecipe;
import appeng.api.features.IGrinderRecipeBuilder;
import appeng.api.features.IGrinderRegistry;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Grind implements ICraftHandler, IWebsiteSerializer
{
private IIngredient pro_input;
private IIngredient[] pro_output;
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
if( input.size() == 1 && output.size() == 1 )
{
final int outs = output.get( 0 ).size();
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
throw new RecipeException( "Grind must have a single input, and single output." );
}
@Override
public void register() throws RegistrationException, MissingIngredientException
{
for( final ItemStack is : this.pro_input.getItemStackSet() )
{
final IGrinderRegistry grinderRegistry = AEApi.instance().registries().grinder();
final IGrinderRecipeBuilder builder = grinderRegistry.builder();
final IGrinderRecipe grinderRecipe = builder.withInput( is )
.withOutput( this.pro_output[0].getItemStack() )
.withTurns( 8 )
.build();
grinderRegistry.addRecipe( grinderRecipe );
}
}
@Override
public String getPattern( final RecipeHandler h )
{
return "grind\n" + h.getName( this.pro_input ) + '\n' + h.getName( this.pro_output[0] );
}
@Override
public boolean canCraft( final ItemStack output ) throws RegistrationException, MissingIngredientException
{
return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output );
}
}
@@ -0,0 +1,49 @@
package appeng.recipes.handlers;
import com.google.gson.JsonObject;
import net.minecraft.item.ItemStack;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.JsonContext;
import appeng.api.AEApi;
import appeng.api.features.IGrinderRecipeBuilder;
import appeng.api.features.IGrinderRegistry;
import appeng.recipes.IAERecipeFactory;
import appeng.recipes.factories.recipes.PartRecipeFactory;
public class GrinderHandler implements IAERecipeFactory
{
@Override
public void register( JsonObject json, JsonContext ctx )
{
// TODO only primary for now
JsonObject result = JsonUtils.getJsonObject( json, "result" );
ItemStack primary = PartRecipeFactory.getResult( result, ctx, "primary" );
ItemStack[] input = CraftingHelper.getIngredient( json.get( "input" ), ctx ).getMatchingStacks();
int turns = 5;
if( json.has( "turns" ) )
{
turns = JsonUtils.getInt( json, "turns" );
}
final IGrinderRegistry reg = AEApi.instance().registries().grinder();
for( int i = 0; i < input.length; ++i )
{
final IGrinderRecipeBuilder builder = reg.builder();
builder.withOutput( primary );
builder.withInput( input[i] );
builder.withTurns( turns );
reg.addRecipe( builder.build() );
}
}
}
@@ -1,101 +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.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.event.FMLInterModComms;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class HCCrusher implements ICraftHandler, IWebsiteSerializer
{
private IIngredient pro_input;
private IIngredient[] pro_output;
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
if( input.size() == 1 && output.size() == 1 )
{
final int outs = output.get( 0 ).size();
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
throw new RecipeException( "Crusher must have a single input, and single output." );
}
@Override
public void register() throws RegistrationException, MissingIngredientException
{
for( final ItemStack beginStack : this.pro_input.getItemStackSet() )
{
try
{
final NBTTagCompound toRegister = new NBTTagCompound();
final ItemStack endStack = this.pro_output[0].getItemStack();
final NBTTagCompound itemFrom = new NBTTagCompound();
final NBTTagCompound itemTo = new NBTTagCompound();
beginStack.writeToNBT( itemFrom );
endStack.writeToNBT( itemTo );
toRegister.setTag( "itemFrom", itemFrom );
toRegister.setTag( "itemTo", itemTo );
toRegister.setFloat( "pressureRatio", 1.0F );
FMLInterModComms.sendMessage( "HydCraft", "registerCrushingRecipe", toRegister );
}
catch( final java.lang.RuntimeException err )
{
AELog.info( "Hydraulicraft not happy - " + err.getMessage() );
}
}
}
@Override
public String getPattern( final RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( final ItemStack output ) throws RegistrationException, MissingIngredientException
{
return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output );
}
}
@@ -1,79 +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.recipes.handlers;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.features.IInscriberRecipeBuilder;
import appeng.api.features.InscriberProcessType;
/**
* recipe translation for inscribe process
*
* @author AlgorithmX2
* @author thatsIch
* @version rv2
* @since rv0
*/
public final class Inscribe extends InscriberProcess
{
@Override
public void register() throws RegistrationException, MissingIngredientException
{
if( this.getImprintable() == null )
{
return;
}
if( this.getOutput() == null )
{
return;
}
final IInscriberRecipeBuilder builder = AEApi.instance().registries().inscriber().builder();
final ItemStack[] realInput = this.getImprintable().getItemStackSet();
final List<ItemStack> inputs = new ArrayList<>( realInput.length );
Collections.addAll( inputs, realInput );
final ItemStack output = this.getOutput().getItemStack();
final InscriberProcessType type = InscriberProcessType.INSCRIBE;
builder.withInputs( inputs )
.withOutput( output )
.withProcessType( type );
if( this.getTopOptional() != null && !this.getTopOptional().getItemStack().isEmpty() )
{
builder.withTopOptional( this.getTopOptional().getItemStack() );
}
if( this.getBotOptional() != null && !this.getBotOptional().getItemStack().isEmpty() )
{
builder.withBottomOptional( this.getBotOptional().getItemStack() );
}
AEApi.instance().registries().inscriber().addRecipe( builder.build() );
}
}
@@ -0,0 +1,71 @@
package appeng.recipes.handlers;
import java.util.Arrays;
import java.util.List;
import com.google.gson.JsonObject;
import net.minecraft.item.ItemStack;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.JsonContext;
import appeng.api.AEApi;
import appeng.api.features.IInscriberRecipeBuilder;
import appeng.api.features.IInscriberRegistry;
import appeng.api.features.InscriberProcessType;
import appeng.recipes.IAERecipeFactory;
import appeng.recipes.factories.recipes.PartRecipeFactory;
public class InscriberHandler implements IAERecipeFactory
{
@Override
public void register( JsonObject json, JsonContext ctx )
{
ItemStack result = PartRecipeFactory.getResult( json, ctx );
String mode = JsonUtils.getString( json, "mode" );
JsonObject ingredients = JsonUtils.getJsonObject( json, "ingredients" );
List<ItemStack> middle = Arrays.asList( CraftingHelper.getIngredient( ingredients.get( "middle" ), ctx ).getMatchingStacks() );
ItemStack[] top = new ItemStack[] { null };
if( ingredients.has( "top" ) )
{
top = CraftingHelper.getIngredient( JsonUtils.getJsonObject( ingredients, "top" ), ctx ).getMatchingStacks();
}
ItemStack[] bottom = new ItemStack[] { null };
if( ingredients.has( "bottom" ) )
{
bottom = CraftingHelper.getIngredient( JsonUtils.getJsonObject( ingredients, "bottom" ), ctx ).getMatchingStacks();
}
final IInscriberRegistry reg = AEApi.instance().registries().inscriber();
for( int i = 0; i < top.length; ++i )
{
for( int j = 0; j < bottom.length; ++j )
{
final IInscriberRecipeBuilder builder = reg.builder();
builder.withOutput( result );
builder.withProcessType( "press".equals( mode ) ? InscriberProcessType.PRESS : InscriberProcessType.INSCRIBE );
builder.withInputs( middle );
if( top[i] != null )
{
builder.withTopOptional( top[i] );
}
if( bottom[j] != null )
{
builder.withBottomOptional( bottom[j] );
}
reg.addRecipe( builder.build() );
}
}
}
}
@@ -1,146 +0,0 @@
/*
* 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.recipes.handlers;
import java.util.List;
import javax.annotation.Nullable;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
/**
* basic inscriber process for recipes
*
* @author AlgorithmX2
* @author thatsIch
* @version rv2
* @since rv0
*/
public abstract class InscriberProcess implements ICraftHandler, IWebsiteSerializer
{
@Nullable
private IIngredient imprintable;
@Nullable
private IIngredient topOptional;
@Nullable
private IIngredient botOptional;
@Nullable
private IIngredient output;
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
if( output.size() == 1 && output.get( 0 ).size() == 1 )
{
if( input.size() == 1 && input.get( 0 ).size() > 1 )
{
this.imprintable = input.get( 0 ).get( 0 );
this.topOptional = input.get( 0 ).get( 1 );
if( input.get( 0 ).size() > 2 )
{
this.botOptional = input.get( 0 ).get( 2 );
}
this.output = output.get( 0 ).get( 0 );
}
else
{
throw new RecipeException( "Inscriber recipes cannot have rows, and must have more then one input." );
}
}
else
{
throw new RecipeException( "Inscriber recipes must produce a single output." );
}
}
@Override
public boolean canCraft( final ItemStack reqOutput ) throws RegistrationException, MissingIngredientException
{
return this.output != null && Platform.itemComparisons().isSameItem( this.output.getItemStack(), reqOutput );
}
@Override
public String getPattern( final RecipeHandler handler )
{
String pattern = "inscriber ";
if( this.output != null )
{
pattern += this.output.getQty() + '\n';
pattern += handler.getName( this.output ) + '\n';
}
if( this.topOptional != null )
{
pattern += handler.getName( this.topOptional ) + '\n';
}
if( this.imprintable != null )
{
pattern += handler.getName( this.imprintable );
}
if( this.botOptional != null )
{
pattern += '\n' + handler.getName( this.botOptional );
}
return pattern;
}
@Nullable
protected IIngredient getImprintable()
{
return this.imprintable;
}
@Nullable
protected IIngredient getTopOptional()
{
return this.topOptional;
}
@Nullable
protected IIngredient getBotOptional()
{
return this.botOptional;
}
@Nullable
protected IIngredient getOutput()
{
return this.output;
}
}
@@ -1,88 +0,0 @@
/*
* 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.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.integration.Integrations;
import appeng.integration.abstraction.IIC2;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Macerator implements ICraftHandler, IWebsiteSerializer
{
private IIngredient pro_input;
private IIngredient[] pro_output;
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
if( input.size() == 1 && output.size() == 1 )
{
final int outs = output.get( 0 ).size();
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
throw new RecipeException( "Grind must have a single input, and single output." );
}
@Override
public void register() throws RegistrationException, MissingIngredientException
{
IIC2 ic2 = Integrations.ic2();
for( final ItemStack is : this.pro_input.getItemStackSet() )
{
try
{
ic2.maceratorRecipe( is, this.pro_output[0].getItemStack() );
}
catch( final java.lang.RuntimeException err )
{
AELog.info( "IC2 not happy - " + err.getMessage() );
}
}
}
@Override
public String getPattern( final RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( final ItemStack output ) throws RegistrationException, MissingIngredientException
{
return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output );
}
}
@@ -1,89 +0,0 @@
/*
* 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.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.integration.Integrations;
import appeng.integration.abstraction.IMekanism;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class MekCrusher implements ICraftHandler, IWebsiteSerializer
{
private IIngredient pro_input;
private IIngredient[] pro_output;
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
if( input.size() == 1 && output.size() == 1 )
{
final int outs = output.get( 0 ).size();
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
throw new RecipeException( "MekCrusher must have a single input, and single output." );
}
@Override
public void register() throws RegistrationException, MissingIngredientException
{
IMekanism mekanism = Integrations.mekanism();
for( final ItemStack is : this.pro_input.getItemStackSet() )
{
try
{
mekanism.addCrusherRecipe( is, this.pro_output[0].getItemStack() );
}
catch( final java.lang.RuntimeException err )
{
AELog.info( "Mekanism not happy - " + err.getMessage() );
}
}
}
@Override
public String getPattern( final RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( final ItemStack output ) throws RegistrationException, MissingIngredientException
{
return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output );
}
}
@@ -1,88 +0,0 @@
/*
* 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.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.integration.Integrations;
import appeng.integration.abstraction.IMekanism;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class MekEnrichment implements ICraftHandler, IWebsiteSerializer
{
private IIngredient pro_input;
private IIngredient[] pro_output;
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
if( input.size() == 1 && output.size() == 1 )
{
final int outs = output.get( 0 ).size();
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
throw new RecipeException( "MekCrusher must have a single input, and single output." );
}
@Override
public void register() throws RegistrationException, MissingIngredientException
{
IMekanism mekanism = Integrations.mekanism();
for( final ItemStack is : this.pro_input.getItemStackSet() )
{
try
{
mekanism.addEnrichmentChamberRecipe( is, this.pro_output[0].getItemStack() );
}
catch( final java.lang.RuntimeException err )
{
AELog.info( "Mekanism not happy - " + err.getMessage() );
}
}
}
@Override
public String getPattern( final RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( final ItemStack output ) throws RegistrationException, MissingIngredientException
{
return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output );
}
}
@@ -1,63 +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.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraftforge.oredict.OreDictionary;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
public class OreRegistration implements ICraftHandler
{
private final List<IIngredient> inputs;
private final String name;
public OreRegistration( final List<IIngredient> in, final String out )
{
this.inputs = in;
this.name = out;
}
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
}
@Override
public void register() throws RegistrationException, MissingIngredientException
{
for( final IIngredient i : this.inputs )
{
for( final ItemStack is : i.getItemStackSet() )
{
OreDictionary.registerOre( this.name, is );
}
}
}
}
@@ -1,76 +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.recipes.handlers;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.AEApi;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.features.IInscriberRecipe;
import appeng.api.features.IInscriberRecipeBuilder;
import appeng.api.features.InscriberProcessType;
/**
* recipe translation for pressing in the inscriber
*
* @author AlgorithmX2
* @author thatsIch
* @version rv2
* @since rv0
*/
public final class Press extends InscriberProcess
{
@Override
public void register() throws RegistrationException, MissingIngredientException
{
if( this.getImprintable() == null )
{
return;
}
if( this.getOutput() == null )
{
return;
}
final IInscriberRecipeBuilder builder = AEApi.instance().registries().inscriber().builder();
final ItemStack[] realInput = this.getImprintable().getItemStackSet();
final List<ItemStack> inputs = new ArrayList<>( realInput.length );
Collections.addAll( inputs, realInput );
final ItemStack top = ( this.getTopOptional() == null ) ? ItemStack.EMPTY : this.getTopOptional().getItemStack();
final ItemStack bot = ( this.getBotOptional() == null ) ? ItemStack.EMPTY : this.getBotOptional().getItemStack();
final ItemStack output = this.getOutput().getItemStack();
final InscriberProcessType type = InscriberProcessType.PRESS;
final IInscriberRecipe recipe = builder.withInputs( inputs )
.withOutput( output )
.withTopOptional( top )
.withBottomOptional( bot )
.withProcessType( type )
.build();
AEApi.instance().registries().inscriber().addRecipe( recipe );
}
}
@@ -1,87 +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.recipes.handlers;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraftforge.fml.common.event.FMLInterModComms;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Pulverizer implements ICraftHandler, IWebsiteSerializer
{
private IIngredient pro_input;
private IIngredient[] pro_output;
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
if( input.size() == 1 && output.size() == 1 )
{
final int outs = output.get( 0 ).size();
if( input.get( 0 ).size() == 1 && outs == 1 )
{
this.pro_input = input.get( 0 ).get( 0 );
this.pro_output = output.get( 0 ).toArray( new IIngredient[outs] );
return;
}
}
throw new RecipeException( "Grind must have a single input, and single output." );
}
@Override
public void register() throws RegistrationException, MissingIngredientException
{
final NBTTagCompound toSend = new NBTTagCompound();
toSend.setInteger( "energy", 800 );
toSend.setTag( "primaryOutput", new NBTTagCompound() );
this.pro_output[0].getItemStack().writeToNBT( toSend.getCompoundTag( "primaryOutput" ) );
for( final ItemStack is : this.pro_input.getItemStackSet() )
{
toSend.setTag( "input", new NBTTagCompound() );
is.writeToNBT( toSend.getCompoundTag( "input" ) );
FMLInterModComms.sendMessage( "ThermalExpansion", "PulverizerRecipe", toSend );
}
}
@Override
public String getPattern( final RecipeHandler h )
{
return null;
}
@Override
public boolean canCraft( final ItemStack output ) throws RegistrationException, MissingIngredientException
{
return Platform.itemComparisons().isSameItem( this.pro_output[0].getItemStack(), output );
}
}
@@ -1,175 +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.recipes.handlers;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Shaped implements ICraftHandler, IWebsiteSerializer
{
private List<List<IIngredient>> inputs;
private IIngredient output;
private int rows;
private int cols;
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
if( output.size() == 1 && output.get( 0 ).size() == 1 )
{
this.rows = input.size();
if( this.rows > 0 && input.size() <= 3 )
{
this.cols = input.get( 0 ).size();
if( this.cols <= 3 && this.cols >= 1 )
{
for( final List<IIngredient> anInput : input )
{
if( anInput.size() != this.cols )
{
throw new RecipeException( "all rows in a shaped crafting recipe must contain the same number of ingredients." );
}
}
this.inputs = input;
this.output = output.get( 0 ).get( 0 );
}
else
{
throw new RecipeException( "Crafting recipes must have 1-3 columns." );
}
}
else
{
throw new RecipeException( "shaped crafting recipes must have 1-3 rows." );
}
}
else
{
throw new RecipeException( "Crafting must produce a single output." );
}
}
@Override
public void register() throws RegistrationException, MissingIngredientException
{
char first = 'A';
final List<Object> args = new ArrayList<>();
for( int y = 0; y < this.rows; y++ )
{
final StringBuilder row = new StringBuilder();
for( int x = 0; x < this.cols; x++ )
{
if( this.inputs.get( y ).get( x ).isAir() )
{
row.append( ' ' );
}
else
{
row.append( first );
args.add( first );
args.add( this.inputs.get( y ).get( x ) );
first++;
}
}
args.add( y, row.toString() );
}
final ItemStack outIS = this.output.getItemStack();
try
{
// TODO : 1.12 Cleanup/remove the old recipe loader.
// Registration.addRecipeToRegister( new ShapedRecipe( outIS, args.toArray( new Object[args.size()] ) ) );
}
catch( final Throwable e )
{
AELog.debug( e );
throw new RegistrationException( "Error while adding shaped recipe." );
}
}
@Override
public String getPattern( final RecipeHandler h )
{
String o = "shaped " + this.output.getQty() + ' ' + this.cols + 'x' + this.rows + '\n';
o += h.getName( this.output ) + '\n';
for( int y = 0; y < this.rows; y++ )
{
for( int x = 0; x < this.cols; x++ )
{
final IIngredient i = this.inputs.get( y ).get( x );
if( i.isAir() )
{
o += "air" + ( x + 1 == this.cols ? "\n" : " " );
}
else
{
o += h.getName( i ) + ( x + 1 == this.cols ? "\n" : " " );
}
}
}
return o.trim();
}
@Override
public boolean canCraft( final ItemStack reqOutput ) throws RegistrationException, MissingIngredientException
{
for( int y = 0; y < this.rows; y++ )
{
for( int x = 0; x < this.cols; x++ )
{
final IIngredient i = this.inputs.get( y ).get( x );
if( !i.isAir() )
{
for( final ItemStack r : i.getItemStackSet() )
{
if( Platform.itemComparisons().isSameItem( r, reqOutput ) )
{
return false;
}
}
}
}
}
return Platform.itemComparisons().isSameItem( this.output.getItemStack(), reqOutput );
}
}
@@ -1,141 +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.recipes.handlers;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.core.AELog;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Shapeless implements ICraftHandler, IWebsiteSerializer
{
private List<IIngredient> inputs;
private IIngredient output;
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
if( output.size() == 1 && output.get( 0 ).size() == 1 )
{
if( input.size() == 1 )
{
this.inputs = input.get( 0 );
this.output = output.get( 0 ).get( 0 );
}
else
{
throw new RecipeException( "Shapeless crafting recipes cannot have rows." );
}
}
else
{
throw new RecipeException( "Crafting must produce a single output." );
}
}
@Override
public void register() throws RegistrationException, MissingIngredientException
{
final List<Object> args = new ArrayList<>();
for( final IIngredient i : this.inputs )
{
args.add( i );
}
final ItemStack outIS = this.output.getItemStack();
try
{
// TODO : 1.12 Cleanup/remove the old recipe loader.
// Registration.addRecipeToRegister( new ShapelessRecipe( outIS, args.toArray( new Object[args.size()] ) )
// );
}
catch( final Throwable e )
{
AELog.debug( e );
throw new RegistrationException( "Error while adding shapeless recipe." );
}
}
@Override
public String getPattern( final RecipeHandler h )
{
final StringBuilder o = new StringBuilder( "shapeless " + this.output.getQty() + '\n' );
o.append( h.getName( this.output ) ).append( '\n' );
for( int y = 0; y < this.inputs.size(); y++ )
{
final IIngredient i = this.inputs.get( y );
if( i.isAir() )
{
o.append( "air" );
}
else
{
o.append( h.getName( i ) );
}
if( y + 1 == this.inputs.size() )
{
o.append( '\n' );
}
else
{
o.append( ' ' );
}
}
return o.toString().trim();
}
@Override
public boolean canCraft( final ItemStack reqOutput ) throws RegistrationException, MissingIngredientException
{
for( final IIngredient i : this.inputs )
{
if( !i.isAir() )
{
for( final ItemStack r : i.getItemStackSet() )
{
if( Platform.itemComparisons().isSameItem( r, reqOutput ) )
{
return false;
}
}
}
}
return Platform.itemComparisons().isSameItem( this.output.getItemStack(), reqOutput );
}
}
@@ -1,87 +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.recipes.handlers;
import java.util.List;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.registry.GameRegistry;
import appeng.api.exceptions.MissingIngredientException;
import appeng.api.exceptions.RecipeException;
import appeng.api.exceptions.RegistrationException;
import appeng.api.recipes.ICraftHandler;
import appeng.api.recipes.IIngredient;
import appeng.recipes.RecipeHandler;
import appeng.util.Platform;
public class Smelt implements ICraftHandler, IWebsiteSerializer
{
private IIngredient in;
private IIngredient out;
@Override
public void setup( final List<List<IIngredient>> input, final List<List<IIngredient>> output ) throws RecipeException
{
if( input.size() == 1 && output.size() == 1 )
{
final List<IIngredient> inputList = input.get( 0 );
final List<IIngredient> outputList = output.get( 0 );
if( inputList.size() == 1 && outputList.size() == 1 )
{
this.in = inputList.get( 0 );
this.out = outputList.get( 0 );
return;
}
}
throw new RecipeException( "Smelting recipe can only have a single input and output." );
}
@Override
public void register() throws RegistrationException, MissingIngredientException
{
if( this.in.getItemStack().getItem() == Items.AIR )
{
throw new RegistrationException( this.in.toString() + ": Smelting Input is not a valid item." );
}
if( this.out.getItemStack().getItem() == Items.AIR )
{
throw new RegistrationException( this.out.toString() + ": Smelting Output is not a valid item." );
}
GameRegistry.addSmelting( this.in.getItemStack(), this.out.getItemStack(), 0 );
}
@Override
public String getPattern( final RecipeHandler h )
{
return "smelt " + this.out.getQty() + '\n' + h.getName( this.out ) + '\n' + h.getName( this.in );
}
@Override
public boolean canCraft( final ItemStack reqOutput ) throws RegistrationException, MissingIngredientException
{
return Platform.itemComparisons().isSameItem( this.out.getItemStack(), reqOutput );
}
}
@@ -0,0 +1,36 @@
package appeng.recipes.handlers;
import com.google.gson.JsonObject;
import net.minecraft.item.ItemStack;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.common.crafting.CraftingHelper;
import net.minecraftforge.common.crafting.JsonContext;
import net.minecraftforge.fml.common.registry.GameRegistry;
import appeng.recipes.IAERecipeFactory;
import appeng.recipes.factories.recipes.PartRecipeFactory;
public class SmeltingHandler implements IAERecipeFactory
{
@Override
public void register( JsonObject json, JsonContext ctx )
{
ItemStack result = PartRecipeFactory.getResult( json, ctx );
ItemStack[] input = CraftingHelper.getIngredient( json.get( "input" ), ctx ).getMatchingStacks();
float xp = 0.0f;
if( json.has( "xp" ) )
{
xp = JsonUtils.getFloat( json, "xp" );
}
for( int i = 0; i < input.length; ++i )
{
GameRegistry.addSmelting( input[i], result, xp );
}
}
}