Fixed recipe crash when another mod registers a wooden gear.
I'll have to go through every other recipe later.
This commit is contained in:
@@ -25,6 +25,7 @@ import java.io.FileOutputStream;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
import java.util.Map.Entry;
|
import java.util.Map.Entry;
|
||||||
|
import java.util.function.BooleanSupplier;
|
||||||
import java.util.zip.ZipEntry;
|
import java.util.zip.ZipEntry;
|
||||||
import java.util.zip.ZipOutputStream;
|
import java.util.zip.ZipOutputStream;
|
||||||
|
|
||||||
@@ -36,7 +37,9 @@ import com.google.common.collect.HashMultimap;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import net.minecraft.item.Item;
|
import net.minecraft.item.Item;
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.util.JsonUtils;
|
||||||
import net.minecraft.util.ResourceLocation;
|
import net.minecraft.util.ResourceLocation;
|
||||||
|
import net.minecraftforge.common.crafting.IConditionFactory;
|
||||||
import net.minecraftforge.common.crafting.IIngredientFactory;
|
import net.minecraftforge.common.crafting.IIngredientFactory;
|
||||||
import net.minecraftforge.common.crafting.JsonContext;
|
import net.minecraftforge.common.crafting.JsonContext;
|
||||||
import net.minecraftforge.fml.common.LoaderState;
|
import net.minecraftforge.fml.common.LoaderState;
|
||||||
@@ -763,6 +766,17 @@ public class RecipeHandler implements IRecipeHandler
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static class MaterialExists implements IConditionFactory
|
||||||
|
{
|
||||||
|
@Override
|
||||||
|
public BooleanSupplier parse( JsonContext jsonContext, JsonObject jsonObject ) {
|
||||||
|
String material = JsonUtils.getString( jsonObject, "material" );
|
||||||
|
Object result = (Object) Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, material );
|
||||||
|
return () -> result != null;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public static class PartFactory implements IIngredientFactory
|
public static class PartFactory implements IIngredientFactory
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|||||||
@@ -47,12 +47,7 @@ public class PartShapelessCraftingFactory extends ShapelessOreRecipe
|
|||||||
|
|
||||||
String ingredient = resultObject.get( "part" ).getAsString();
|
String ingredient = resultObject.get( "part" ).getAsString();
|
||||||
Object result = (Object) Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, ingredient );
|
Object result = (Object) Api.INSTANCE.registries().recipes().resolveItem( AppEng.MOD_ID, ingredient );
|
||||||
if( result instanceof ResolverResultSet )
|
if( result instanceof ResolverResult )
|
||||||
{
|
|
||||||
ResolverResultSet resolverResultSet = (ResolverResultSet) result;
|
|
||||||
return new PartShapelessCraftingFactory(group.isEmpty() ? null : new ResourceLocation(group), ings, resolverResultSet.results.toArray( new ItemStack[resolverResultSet.results.size()] )[0]);
|
|
||||||
}
|
|
||||||
else if( result instanceof ResolverResult )
|
|
||||||
{
|
{
|
||||||
ResolverResult resolverResult = (ResolverResult) result;
|
ResolverResult resolverResult = (ResolverResult) result;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,7 @@
|
|||||||
{
|
{
|
||||||
|
"conditions": {
|
||||||
|
"material_exists": "appeng.recipes.RecipeHandler$MaterialExists"
|
||||||
|
},
|
||||||
"ingredients": {
|
"ingredients": {
|
||||||
"part": "appeng.recipes.RecipeHandler$PartFactory"
|
"part": "appeng.recipes.RecipeHandler$PartFactory"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -1,4 +1,10 @@
|
|||||||
{
|
{
|
||||||
|
"conditions": [
|
||||||
|
{
|
||||||
|
"type": "appliedenergistics2:material_exists",
|
||||||
|
"material": "material.WoodenGear"
|
||||||
|
}
|
||||||
|
],
|
||||||
"result": {
|
"result": {
|
||||||
"type": "appliedenergistics2:part",
|
"type": "appliedenergistics2:part",
|
||||||
"part": "material.WoodenGear"
|
"part": "material.WoodenGear"
|
||||||
|
|||||||
Reference in New Issue
Block a user