Skip to content

Commit

Permalink
add GregTech Modern compat
Browse files Browse the repository at this point in the history
  • Loading branch information
rlnt committed Sep 23, 2023
1 parent b3d6589 commit 5b869b6
Show file tree
Hide file tree
Showing 5 changed files with 70 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public final class ModConstants {
public static final String ARS_NOUVEAU = "ars_nouveau";
public static final String ARS_SCALAES = "ars_scalaes";
public static final String CYCLIC = "cyclic";
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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,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";
Expand Down
Original file line number Diff line number Diff line change
@@ -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<JsonElement, JsonElement> 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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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;
Expand Down Expand Up @@ -47,6 +48,7 @@ public Path getLogPath() {
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());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public void bindRecipeHandlers(RecipeHandlerFactory factory) {
ModConstants.ARS_SCALAES
).forEach(modId -> factory.registerForMod(modId, new ArsNouveauRecipeUnifier()));
factory.registerForMod(ModConstants.CYCLIC, new CyclicRecipeUnifier());
factory.registerForMod(ModConstants.GREGTECH_MODERN, new GregTechModernRecipeUnifier());
factory.registerForMod(ModConstants.IMMERSIVE_ENGINEERING, new ImmersiveEngineeringRecipeUnifier());
factory.registerForMod(ModConstants.MEKANISM, new MekanismRecipeUnifier());
}
Expand Down

0 comments on commit 5b869b6

Please sign in to comment.