Skip to content

Commit

Permalink
Add support for alloy forgery
Browse files Browse the repository at this point in the history
  • Loading branch information
LLytho committed Apr 18, 2024
1 parent 88b2b4f commit 4ca001d
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public Path getLogPath() {
@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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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");
}
}

0 comments on commit 4ca001d

Please sign in to comment.