add Integrated Dynamics compat

This commit is contained in:
rlnt 2023-11-21 14:18:14 +01:00
parent af1253cf97
commit 11427a6cc7
No known key found for this signature in database
3 changed files with 45 additions and 0 deletions

View file

@ -17,6 +17,7 @@ public final class ModConstants {
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 INTEGRATED_DYNAMICS = "integrateddynamics";
public static final String MEKANISM = "mekanism";
public static final String MODERN_INDUSTRIALIZATION = "modern_industrialization";

View file

@ -63,6 +63,7 @@ public class AlmostUnifiedPlatformForge implements AlmostUnifiedPlatform {
factory.registerForMod(ModConstants.ENDER_IO, new EnderIORecipeUnifier());
factory.registerForMod(ModConstants.GREGTECH_MODERN, new GregTechModernRecipeUnifier());
factory.registerForMod(ModConstants.IMMERSIVE_ENGINEERING, new ImmersiveEngineeringRecipeUnifier());
factory.registerForMod(ModConstants.INTEGRATED_DYNAMICS, new IntegratedDynamicsRecipeUnifier());
factory.registerForMod(ModConstants.MEKANISM, new MekanismRecipeUnifier());
}

View file

@ -0,0 +1,43 @@
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 com.google.gson.JsonPrimitive;
import javax.annotation.Nullable;
public class IntegratedDynamicsRecipeUnifier implements RecipeUnifier {
private static final String ITEMS = "items";
@Override
public void collectUnifier(RecipeUnifierBuilder builder) {
builder.put(RecipeConstants.ITEM, this::createItemReplacement);
builder.put(RecipeConstants.RESULT, this::createResultReplacement);
}
@Nullable
private JsonElement createItemReplacement(@Nullable JsonElement json, RecipeContext ctx) {
if (json instanceof JsonPrimitive jsonPrimitive) {
JsonObject jsonObject = new JsonObject();
jsonObject.add(RecipeConstants.ITEM, jsonPrimitive);
return ctx.createIngredientReplacement(jsonObject);
}
return ctx.createIngredientReplacement(json);
}
@Nullable
private JsonElement createResultReplacement(@Nullable JsonElement json, RecipeContext ctx) {
if (json instanceof JsonObject jsonObject && jsonObject.get(ITEMS) instanceof JsonArray jsonArray) {
ctx.createResultReplacement(jsonArray);
}
return null;
}
}