mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-30 11:27:15 -05:00
add GregTech Modern compat
This commit is contained in:
parent
485d707c86
commit
3c3a4786c3
5 changed files with 70 additions and 0 deletions
|
@ -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";
|
||||
|
|
|
@ -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";
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
|
@ -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());
|
||||
}
|
||||
|
||||
|
|
|
@ -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());
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue