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 7df82976..39bd2c16 100644 --- a/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java +++ b/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java @@ -20,6 +20,11 @@ public final class ModConstants { public static final String INTEGRATED_DYNAMICS = "integrateddynamics"; public static final String MEKANISM = "mekanism"; public static final String MODERN_INDUSTRIALIZATION = "modern_industrialization"; + public static final String WOODENCOG = "woodencog"; + public static final String TERRAFIRMACRAFT = "tfc"; + public static final String ADVANCED_TFC_TECH = "advancedtfctech"; + public static final String FIRMALIFE = "firmalife"; + public static final String TFC_WATER_FLASKS = "waterflasks"; private ModConstants() {} } diff --git a/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeConstants.java b/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeConstants.java index a2c95001..c339e61d 100644 --- a/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeConstants.java +++ b/Common/src/main/java/com/almostreliable/unified/api/recipe/RecipeConstants.java @@ -51,5 +51,20 @@ public final class RecipeConstants { // cyclic public static final String BONUS = "bonus"; + // terrafirmacraft + public static final String STACK = "stack"; + public static final String EXTRA_PRODUCTS = "extra_products"; + public static final String FIRST_INPUT = "first_input"; + public static final String SECOND_INPUT = "second_input"; + public static final String INPUT_ITEM = "input_item"; + public static final String OUTPUT_ITEM = "input_item"; + public static final String EXTRA_DROP = "extra_drop"; + public static final String BATCH = "batch"; + public static final String RESULT_ITEM = "result_item"; + public static final String MOLD = "mold"; + public static final String PRIMARY_INGREDIENT = "primary_ingredient"; + public static final String SECONDARY_INPUT = "secondary_input"; + public static final String BASE_INGREDIENT = "base_ingredient"; + private RecipeConstants() {} } 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 754abe26..031740ab 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 @@ -22,6 +22,9 @@ public interface RecipeContext { @Nullable JsonElement createIngredientReplacement(@Nullable JsonElement element); + @Nullable + JsonElement createIngredientReplacement(@Nullable JsonElement element, String... lookupKeys); + @Nullable JsonElement createResultReplacement(@Nullable JsonElement element); 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 cee07ebb..5a9ae813 100644 --- a/Common/src/main/java/com/almostreliable/unified/recipe/RecipeContextImpl.java +++ b/Common/src/main/java/com/almostreliable/unified/recipe/RecipeContextImpl.java @@ -60,26 +60,37 @@ public UnifyTag getPreferredTagForItem(@Nullable ResourceLocation item) { @Nullable @Override public JsonElement createIngredientReplacement(@Nullable JsonElement element) { + return createIngredientReplacement( + element, + RecipeConstants.VALUE, + RecipeConstants.BASE, + RecipeConstants.INGREDIENT + ); + } + + @Nullable + @Override + public JsonElement createIngredientReplacement(@Nullable JsonElement element, String... lookupKeys) { if (element == null) { return null; } JsonElement copy = element.deepCopy(); - tryCreateIngredientReplacement(copy); + tryCreateIngredientReplacement(copy, lookupKeys); return element.equals(copy) ? null : copy; } - private void tryCreateIngredientReplacement(@Nullable JsonElement element) { + private void tryCreateIngredientReplacement(@Nullable JsonElement element, String... lookupKeys) { if (element instanceof JsonArray array) { for (JsonElement e : array) { - tryCreateIngredientReplacement(e); + tryCreateIngredientReplacement(e, lookupKeys); } } if (element instanceof JsonObject object) { - tryCreateIngredientReplacement(object.get(RecipeConstants.VALUE)); - tryCreateIngredientReplacement(object.get(RecipeConstants.BASE)); - tryCreateIngredientReplacement(object.get(RecipeConstants.INGREDIENT)); + for (String key : lookupKeys) { + tryCreateIngredientReplacement(object.get(key), lookupKeys); + } if (object.get(RecipeConstants.TAG) instanceof JsonPrimitive primitive) { UnifyTag tag = Utils.toItemTag(primitive.getAsString()); diff --git a/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java b/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java index 047abf3c..9bfb0cd3 100644 --- a/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java +++ b/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java @@ -65,6 +65,13 @@ public void bindRecipeHandlers(RecipeHandlerFactory factory) { factory.registerForMod(ModConstants.IMMERSIVE_ENGINEERING, new ImmersiveEngineeringRecipeUnifier()); factory.registerForMod(ModConstants.INTEGRATED_DYNAMICS, new IntegratedDynamicsRecipeUnifier()); factory.registerForMod(ModConstants.MEKANISM, new MekanismRecipeUnifier()); + List.of( + ModConstants.TERRAFIRMACRAFT, + ModConstants.ADVANCED_TFC_TECH, + ModConstants.FIRMALIFE, + ModConstants.TFC_WATER_FLASKS, + ModConstants.WOODENCOG + ).forEach(modId -> factory.registerForMod(modId, new TerraFirmaCraftRecipeUnifier())); } @Override diff --git a/Forge/src/main/java/com/almostreliable/unified/compat/TerraFirmaCraftRecipeUnifier.java b/Forge/src/main/java/com/almostreliable/unified/compat/TerraFirmaCraftRecipeUnifier.java new file mode 100644 index 00000000..76a8621e --- /dev/null +++ b/Forge/src/main/java/com/almostreliable/unified/compat/TerraFirmaCraftRecipeUnifier.java @@ -0,0 +1,74 @@ +package com.almostreliable.unified.compat; + +import com.almostreliable.unified.api.recipe.RecipeConstants; +import com.almostreliable.unified.api.recipe.RecipeContext; +import com.almostreliable.unified.api.recipe.RecipeUnifier; +import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder; +import com.google.gson.JsonElement; + +import javax.annotation.Nullable; +import java.util.List; + +public class TerraFirmaCraftRecipeUnifier implements RecipeUnifier { + + public static final String ITEM_OUTPUT = "item_output"; + + @Override + public void collectUnifier(RecipeUnifierBuilder builder) { + List.of( + // barrel_sealed, vat + RecipeConstants.INPUT_ITEM, + // blast_furnace, bloomery + RecipeConstants.CATALYST, + // casting + RecipeConstants.MOLD, + // advanced shapeless crafting + RecipeConstants.PRIMARY_INGREDIENT, + // glassworking + RecipeConstants.BATCH, + // power_loom + RecipeConstants.INPUTS, + RecipeConstants.SECONDARY_INPUT, + // welding + RecipeConstants.FIRST_INPUT, + RecipeConstants.SECOND_INPUT + ).forEach(key -> builder.put(key, (json, ctx) -> ctx.createIngredientReplacement( + json, + RecipeConstants.VALUE, + RecipeConstants.BASE, + RecipeConstants.INGREDIENT, + RecipeConstants.BASE_INGREDIENT + ))); + + List.of( + // beamhouse, advanced shapeless crafting, fleshing_machine, grist_mill, thresher + RecipeConstants.RESULT, + // filling + RecipeConstants.RESULTS, + // barrel_sealed, mixing_bowl, vat + RecipeConstants.OUTPUT_ITEM, + // chisel, scraping + RecipeConstants.EXTRA_DROP, + // heating, oven + RecipeConstants.RESULT_ITEM, + // pot + ITEM_OUTPUT, + // power_loom, thresher + RecipeConstants.SECONDARIES, + // extra products shapeless crafting + RecipeConstants.EXTRA_PRODUCTS + ).forEach(key -> builder.put(key, this::createResultReplacement)); + } + + @Nullable + private JsonElement createResultReplacement(JsonElement json, RecipeContext ctx) { + return ctx.createResultReplacement( + json, + false, + RecipeConstants.ITEM, + RecipeConstants.STACK, + RecipeConstants.OUTPUT, + RecipeConstants.BASE_INGREDIENT + ); + } +}