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 f1627ca..053e9a3 100644 --- a/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java +++ b/Common/src/main/java/com/almostreliable/unified/api/ModConstants.java @@ -15,6 +15,7 @@ public final class ModConstants { public static final String ARS_SCALAES = "ars_scalaes"; public static final String CYCLIC = "cyclic"; public static final String ENDER_IO = "enderio"; + public static final String GREGTECH_MODERN = "gtceu"; public static final String IMMERSIVE_ENGINEERING = "immersiveengineering"; public static final String MEKANISM = "mekanism"; public static final String MODERN_INDUSTRIALIZATION = "modern_industrialization"; 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 bb8a320..a2c9500 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 @@ -26,6 +26,10 @@ public final class RecipeConstants { public static final String PEDESTAL_ITEMS = "pedestalItems"; public static final String REAGENT = "reagent"; + // gregtech modern + public static final String TICK_INPUTS = "tickInputs"; + public static final String TICK_OUTPUTS = "tickOutputs"; + // immersive engineering public static final String INPUT_0 = "input0"; public static final String INPUT_1 = "input1"; diff --git a/Common/src/main/java/com/almostreliable/unified/compat/GregTechModernRecipeUnifier.java b/Common/src/main/java/com/almostreliable/unified/compat/GregTechModernRecipeUnifier.java new file mode 100644 index 0000000..ee6521d --- /dev/null +++ b/Common/src/main/java/com/almostreliable/unified/compat/GregTechModernRecipeUnifier.java @@ -0,0 +1,62 @@ +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.JsonArray; +import com.google.gson.JsonElement; +import com.google.gson.JsonObject; + +import javax.annotation.Nullable; +import java.util.List; +import java.util.function.Function; + +public class GregTechModernRecipeUnifier implements RecipeUnifier { + + private static final String CONTENT = "content"; + + @Override + public void collectUnifier(RecipeUnifierBuilder builder) { + List.of( + RecipeConstants.INPUTS, + RecipeConstants.TICK_INPUTS + ).forEach(key -> + builder.put(key, (json, ctx) -> createContentReplacement(json, ctx, ctx::createIngredientReplacement)) + ); + + List.of( + RecipeConstants.OUTPUTS, + RecipeConstants.TICK_OUTPUTS + ).forEach(key -> + builder.put(key, (json, ctx) -> createContentReplacement(json, ctx, ctx::createResultReplacement)) + ); + } + + @Nullable + private JsonElement createContentReplacement(@Nullable JsonElement json, RecipeContext ctx, Function elementTransformer) { + if (json instanceof JsonObject jsonObject && + jsonObject.get(RecipeConstants.ITEM) instanceof JsonArray jsonArray) { + JsonArray result = new JsonArray(); + boolean changed = false; + + for (JsonElement element : jsonArray) { + if (element instanceof JsonObject elementObject) { + JsonElement replacement = elementTransformer.apply(elementObject.get(CONTENT)); + if (replacement != null) { + elementObject.add(CONTENT, replacement); + changed = true; + } + result.add(elementObject); + } + } + + if (changed) { + jsonObject.add(RecipeConstants.ITEM, result); + return jsonObject; + } + } + + return null; + } +} diff --git a/Fabric/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformFabric.java b/Fabric/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformFabric.java index 8d5baee..5c07663 100644 --- a/Fabric/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformFabric.java +++ b/Fabric/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformFabric.java @@ -3,6 +3,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.compat.GregTechModernRecipeUnifier; import com.almostreliable.unified.compat.ModernIndustrializationRecipeUnifier; import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory; import com.almostreliable.unified.utils.UnifyTag; @@ -47,6 +48,7 @@ public class AlmostUnifiedPlatformFabric implements AlmostUnifiedPlatform { public void bindRecipeHandlers(RecipeHandlerFactory factory) { factory.registerForMod(ModConstants.AD_ASTRA, new AdAstraRecipeUnifier()); factory.registerForMod(ModConstants.AMETHYST_IMBUEMENT, new AmethystImbuementRecipeUnifier()); + factory.registerForMod(ModConstants.GREGTECH_MODERN, new GregTechModernRecipeUnifier()); factory.registerForMod(ModConstants.MODERN_INDUSTRIALIZATION, new ModernIndustrializationRecipeUnifier()); } diff --git a/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java b/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java index b0b543f..431be59 100644 --- a/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java +++ b/Forge/src/main/java/com/almostreliable/unified/AlmostUnifiedPlatformForge.java @@ -61,6 +61,7 @@ public class AlmostUnifiedPlatformForge implements AlmostUnifiedPlatform { ).forEach(modId -> factory.registerForMod(modId, new ArsNouveauRecipeUnifier())); factory.registerForMod(ModConstants.CYCLIC, new CyclicRecipeUnifier()); factory.registerForMod(ModConstants.ENDER_IO, new EnderIORecipeUnifier()); + factory.registerForMod(ModConstants.GREGTECH_MODERN, new GregTechModernRecipeUnifier()); factory.registerForMod(ModConstants.IMMERSIVE_ENGINEERING, new ImmersiveEngineeringRecipeUnifier()); factory.registerForMod(ModConstants.MEKANISM, new MekanismRecipeUnifier()); }