add TerraFirmaCraft compat (#69)

Co-authored-by: rlnt <relentless@rlnt.dev>
This commit is contained in:
pietro-lopes 2024-03-01 19:32:47 -03:00 committed by GitHub
parent 3ddac08979
commit 7ff762b998
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 121 additions and 6 deletions

View file

@ -20,6 +20,11 @@ public final class ModConstants {
public static final String INTEGRATED_DYNAMICS = "integrateddynamics";
public static final String MEKANISM = "mekanism";
public static final String MODERN_INDUSTRIALIZATION = "modern_industrialization";
public static final String WOODENCOG = "woodencog";
public static final String TERRAFIRMACRAFT = "tfc";
public static final String ADVANCED_TFC_TECH = "advancedtfctech";
public static final String FIRMALIFE = "firmalife";
public static final String TFC_WATER_FLASKS = "waterflasks";
private ModConstants() {}
}

View file

@ -51,5 +51,20 @@ public final class RecipeConstants {
// cyclic
public static final String BONUS = "bonus";
// terrafirmacraft
public static final String STACK = "stack";
public static final String EXTRA_PRODUCTS = "extra_products";
public static final String FIRST_INPUT = "first_input";
public static final String SECOND_INPUT = "second_input";
public static final String INPUT_ITEM = "input_item";
public static final String OUTPUT_ITEM = "input_item";
public static final String EXTRA_DROP = "extra_drop";
public static final String BATCH = "batch";
public static final String RESULT_ITEM = "result_item";
public static final String MOLD = "mold";
public static final String PRIMARY_INGREDIENT = "primary_ingredient";
public static final String SECONDARY_INPUT = "secondary_input";
public static final String BASE_INGREDIENT = "base_ingredient";
private RecipeConstants() {}
}

View file

@ -22,6 +22,9 @@ public interface RecipeContext {
@Nullable
JsonElement createIngredientReplacement(@Nullable JsonElement element);
@Nullable
JsonElement createIngredientReplacement(@Nullable JsonElement element, String... lookupKeys);
@Nullable
JsonElement createResultReplacement(@Nullable JsonElement element);

View file

@ -60,26 +60,37 @@ public class RecipeContextImpl implements RecipeContext {
@Nullable
@Override
public JsonElement createIngredientReplacement(@Nullable JsonElement element) {
return createIngredientReplacement(
element,
RecipeConstants.VALUE,
RecipeConstants.BASE,
RecipeConstants.INGREDIENT
);
}
@Nullable
@Override
public JsonElement createIngredientReplacement(@Nullable JsonElement element, String... lookupKeys) {
if (element == null) {
return null;
}
JsonElement copy = element.deepCopy();
tryCreateIngredientReplacement(copy);
tryCreateIngredientReplacement(copy, lookupKeys);
return element.equals(copy) ? null : copy;
}
private void tryCreateIngredientReplacement(@Nullable JsonElement element) {
private void tryCreateIngredientReplacement(@Nullable JsonElement element, String... lookupKeys) {
if (element instanceof JsonArray array) {
for (JsonElement e : array) {
tryCreateIngredientReplacement(e);
tryCreateIngredientReplacement(e, lookupKeys);
}
}
if (element instanceof JsonObject object) {
tryCreateIngredientReplacement(object.get(RecipeConstants.VALUE));
tryCreateIngredientReplacement(object.get(RecipeConstants.BASE));
tryCreateIngredientReplacement(object.get(RecipeConstants.INGREDIENT));
for (String key : lookupKeys) {
tryCreateIngredientReplacement(object.get(key), lookupKeys);
}
if (object.get(RecipeConstants.TAG) instanceof JsonPrimitive primitive) {
UnifyTag<Item> tag = Utils.toItemTag(primitive.getAsString());

View file

@ -65,6 +65,13 @@ public class AlmostUnifiedPlatformForge implements AlmostUnifiedPlatform {
factory.registerForMod(ModConstants.IMMERSIVE_ENGINEERING, new ImmersiveEngineeringRecipeUnifier());
factory.registerForMod(ModConstants.INTEGRATED_DYNAMICS, new IntegratedDynamicsRecipeUnifier());
factory.registerForMod(ModConstants.MEKANISM, new MekanismRecipeUnifier());
List.of(
ModConstants.TERRAFIRMACRAFT,
ModConstants.ADVANCED_TFC_TECH,
ModConstants.FIRMALIFE,
ModConstants.TFC_WATER_FLASKS,
ModConstants.WOODENCOG
).forEach(modId -> factory.registerForMod(modId, new TerraFirmaCraftRecipeUnifier()));
}
@Override

View file

@ -0,0 +1,74 @@
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.JsonElement;
import javax.annotation.Nullable;
import java.util.List;
public class TerraFirmaCraftRecipeUnifier implements RecipeUnifier {
public static final String ITEM_OUTPUT = "item_output";
@Override
public void collectUnifier(RecipeUnifierBuilder builder) {
List.of(
// barrel_sealed, vat
RecipeConstants.INPUT_ITEM,
// blast_furnace, bloomery
RecipeConstants.CATALYST,
// casting
RecipeConstants.MOLD,
// advanced shapeless crafting
RecipeConstants.PRIMARY_INGREDIENT,
// glassworking
RecipeConstants.BATCH,
// power_loom
RecipeConstants.INPUTS,
RecipeConstants.SECONDARY_INPUT,
// welding
RecipeConstants.FIRST_INPUT,
RecipeConstants.SECOND_INPUT
).forEach(key -> builder.put(key, (json, ctx) -> ctx.createIngredientReplacement(
json,
RecipeConstants.VALUE,
RecipeConstants.BASE,
RecipeConstants.INGREDIENT,
RecipeConstants.BASE_INGREDIENT
)));
List.of(
// beamhouse, advanced shapeless crafting, fleshing_machine, grist_mill, thresher
RecipeConstants.RESULT,
// filling
RecipeConstants.RESULTS,
// barrel_sealed, mixing_bowl, vat
RecipeConstants.OUTPUT_ITEM,
// chisel, scraping
RecipeConstants.EXTRA_DROP,
// heating, oven
RecipeConstants.RESULT_ITEM,
// pot
ITEM_OUTPUT,
// power_loom, thresher
RecipeConstants.SECONDARIES,
// extra products shapeless crafting
RecipeConstants.EXTRA_PRODUCTS
).forEach(key -> builder.put(key, this::createResultReplacement));
}
@Nullable
private JsonElement createResultReplacement(JsonElement json, RecipeContext ctx) {
return ctx.createResultReplacement(
json,
false,
RecipeConstants.ITEM,
RecipeConstants.STACK,
RecipeConstants.OUTPUT,
RecipeConstants.BASE_INGREDIENT
);
}
}