Add support for alloy forgery

This commit is contained in:
LLytho 2024-04-18 22:38:37 +02:00
parent 88b2b4fa67
commit 4ca001ddc7
3 changed files with 45 additions and 0 deletions

View file

@ -9,6 +9,7 @@ public final class ModConstants {
// custom unify handlers
public static final String AD_ASTRA = "ad_astra";
public static final String APPLIED_ENERGISTICS = "ae2";
public static final String ALLOY_FORGERY = "alloy_forgery";
public static final String AMETHYST_IMBUEMENT = "amethyst_imbuement";
public static final String ARS_CREO = "ars_creo";
public static final String ARS_ELEMENTAL = "ars_elemental";

View file

@ -44,6 +44,7 @@ public class AlmostUnifiedPlatformFabric implements AlmostUnifiedPlatform {
@Override
public void bindRecipeHandlers(RecipeHandlerFactory factory) {
factory.registerForMod(ModConstants.AD_ASTRA, new AdAstraRecipeUnifier());
factory.registerForMod(ModConstants.ALLOY_FORGERY, new AlloyForgeryRecipeUnifier());
factory.registerForMod(ModConstants.APPLIED_ENERGISTICS, new AppliedEnergisticsUnifier());
factory.registerForMod(ModConstants.AMETHYST_IMBUEMENT, new AmethystImbuementRecipeUnifier());
factory.registerForMod(ModConstants.GREGTECH_MODERN, new GregTechModernRecipeUnifier());

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.almostreliable.unified.utils.Utils;
import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import net.minecraft.resources.ResourceLocation;
import javax.annotation.Nullable;
public class AlloyForgeryRecipeUnifier implements RecipeUnifier {
@Override
public void collectUnifier(RecipeUnifierBuilder builder) {
builder.put(RecipeConstants.OUTPUT, this::replaceTagOutput);
}
@Nullable
private JsonElement replaceTagOutput(JsonElement element, RecipeContext ctx) {
if (!(element instanceof JsonObject json)) {
return null;
}
if (json.get("priority") instanceof JsonArray && json.get("default") instanceof JsonPrimitive primitive) {
ResourceLocation item = ctx.getPreferredItemForTag(Utils.toItemTag(primitive.getAsString()), $ -> true);
if (item != null) {
json.addProperty("id", item.toString());
json.remove("priority");
json.remove("default");
return element;
}
return null;
}
return ctx.createResultReplacement(element, false, "id");
}
}