diff --git a/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java b/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java index f66cc98..f72f574 100644 --- a/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java +++ b/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java @@ -4,6 +4,7 @@ package com.almostreliable.unified.api; public final class ModConstants { public static final String IE = "immersiveengineering"; public static final String AMETHYST_IMBUEMENT = "amethyst_imbuement"; + public static final String AD_ASTRA = "ad_astra"; private ModConstants() {} } diff --git a/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeContext.java b/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeContext.java index aa2ab0d..9251710 100644 --- a/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeContext.java +++ b/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeContext.java @@ -24,6 +24,9 @@ public interface RecipeContext { @Nullable JsonElement createResultReplacement(@Nullable JsonElement element); + @Nullable + JsonElement createResultReplacement(@Nullable JsonElement element, boolean includeTagCheck, String... lookupKeys); + ResourceLocation getType(); boolean hasProperty(String property); diff --git a/Common/src/main/java/com/almostreliable/unified/compat/AdAstraRecipeUnifier.java b/Common/src/main/java/com/almostreliable/unified/compat/AdAstraRecipeUnifier.java new file mode 100644 index 0000000..2144347 --- /dev/null +++ b/Common/src/main/java/com/almostreliable/unified/compat/AdAstraRecipeUnifier.java @@ -0,0 +1,14 @@ +package com.almostreliable.unified.compat; + +import com.almostreliable.unified.api.recipe.RecipeConstants; +import com.almostreliable.unified.api.recipe.RecipeUnifier; +import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder; + +public class AdAstraRecipeUnifier implements RecipeUnifier { + @Override + public void collectUnifier(RecipeUnifierBuilder builder) { + builder.put("output", (json, ctx) -> { + return ctx.createResultReplacement(json, false, RecipeConstants.ITEM, "id"); + }); + } +} diff --git a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeContextImpl.java b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeContextImpl.java index 9b49c72..d1095f2 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeContextImpl.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeContextImpl.java @@ -94,16 +94,22 @@ public class RecipeContextImpl implements RecipeContext { @Override @Nullable public JsonElement createResultReplacement(@Nullable JsonElement element) { + return createResultReplacement(element, true, RecipeConstants.ITEM); + } + + @Override + @Nullable + public JsonElement createResultReplacement(@Nullable JsonElement element, boolean includeTagCheck, String... lookupKeys) { if (element == null) { return null; } JsonElement copy = element.deepCopy(); - JsonElement result = tryCreateResultReplacement(copy); + JsonElement result = tryCreateResultReplacement(copy, includeTagCheck, lookupKeys); return element.equals(result) ? null : result; } @Nullable - private JsonElement tryCreateResultReplacement(JsonElement element) { + public JsonElement tryCreateResultReplacement(JsonElement element, boolean lookupForTag, String... keys) { if (element instanceof JsonPrimitive primitive) { ResourceLocation item = ResourceLocation.tryParse(primitive.getAsString()); ResourceLocation replacement = getReplacementForItem(item); @@ -113,17 +119,20 @@ public class RecipeContextImpl implements RecipeContext { return null; } - if (element instanceof JsonArray array && JsonUtils.replaceOn(array, this::tryCreateResultReplacement)) { + if (element instanceof JsonArray array && + JsonUtils.replaceOn(array, j -> tryCreateResultReplacement(j, lookupForTag, keys))) { return element; } if (element instanceof JsonObject object) { - if (JsonUtils.replaceOn(object, RecipeConstants.ITEM, this::tryCreateResultReplacement)) { - return element; + for (String key : keys) { + if (JsonUtils.replaceOn(object, key, j -> tryCreateResultReplacement(j, lookupForTag, keys))) { + return element; + } } // Some mods have tags for results instead of items. We replace those with the preferred item. - if (object.get(RecipeConstants.TAG) instanceof JsonPrimitive primitive) { + if (lookupForTag && object.get(RecipeConstants.TAG) instanceof JsonPrimitive primitive) { ResourceLocation item = getPreferredItemForTag(Utils.toItemTag(primitive.getAsString()), $ -> true); if (item != null) { object.remove(RecipeConstants.TAG); diff --git a/Fabric/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformFabric.java b/Fabric/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformFabric.java index 2a45309..45372d3 100644 --- a/Fabric/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformFabric.java +++ b/Fabric/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformFabric.java @@ -1,6 +1,7 @@ package com.almostreliable.unified; import com.almostreliable.unified.api.ModConstants; +import com.almostreliable.unified.compat.AdAstraRecipeUnifier; import com.almostreliable.unified.compat.AmethystImbuementRecipeUnifier; import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory; import com.almostreliable.unified.utils.UnifyTag; @@ -48,6 +49,7 @@ public class AlmostUnifiedPlatformFabric implements AlmostUnifiedPlatform { @Override public void bindRecipeHandlers(RecipeHandlerFactory factory) { + factory.registerForMod(ModConstants.AD_ASTRA, new AdAstraRecipeUnifier()); factory.registerForMod(ModConstants.AMETHYST_IMBUEMENT, new AmethystImbuementRecipeUnifier()); } diff --git a/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java b/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java index 96b9c4d..bb5fe46 100644 --- a/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java +++ b/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java @@ -1,6 +1,7 @@ package com.almostreliable.unified; import com.almostreliable.unified.api.ModConstants; +import com.almostreliable.unified.compat.AdAstraRecipeUnifier; import com.almostreliable.unified.compat.IERecipeUnifier; import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory; import com.almostreliable.unified.utils.UnifyTag; @@ -57,6 +58,7 @@ public class AlmostUnifiedPlatformForge implements AlmostUnifiedPlatform { @Override public void bindRecipeHandlers(RecipeHandlerFactory factory) { + factory.registerForMod(ModConstants.AD_ASTRA, new AdAstraRecipeUnifier()); factory.registerForMod(ModConstants.IE, new IERecipeUnifier()); }