mirror of
https://github.com/AlmostReliable/almostunified.git
synced 2024-11-14 19:25:13 -05:00
Add support for ad astra (#24)
This commit is contained in:
parent
7ec34987bb
commit
9478dacbef
6 changed files with 37 additions and 6 deletions
|
@ -4,6 +4,7 @@ package com.almostreliable.unified.api;
|
||||||
public final class ModConstants {
|
public final class ModConstants {
|
||||||
public static final String IE = "immersiveengineering";
|
public static final String IE = "immersiveengineering";
|
||||||
public static final String AMETHYST_IMBUEMENT = "amethyst_imbuement";
|
public static final String AMETHYST_IMBUEMENT = "amethyst_imbuement";
|
||||||
|
public static final String AD_ASTRA = "ad_astra";
|
||||||
|
|
||||||
private ModConstants() {}
|
private ModConstants() {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,9 @@ public interface RecipeContext {
|
||||||
@Nullable
|
@Nullable
|
||||||
JsonElement createResultReplacement(@Nullable JsonElement element);
|
JsonElement createResultReplacement(@Nullable JsonElement element);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
JsonElement createResultReplacement(@Nullable JsonElement element, boolean includeTagCheck, String... lookupKeys);
|
||||||
|
|
||||||
ResourceLocation getType();
|
ResourceLocation getType();
|
||||||
|
|
||||||
boolean hasProperty(String property);
|
boolean hasProperty(String property);
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package com.almostreliable.unified.compat;
|
||||||
|
|
||||||
|
import com.almostreliable.unified.api.recipe.RecipeConstants;
|
||||||
|
import com.almostreliable.unified.api.recipe.RecipeUnifier;
|
||||||
|
import com.almostreliable.unified.api.recipe.RecipeUnifierBuilder;
|
||||||
|
|
||||||
|
public class AdAstraRecipeUnifier implements RecipeUnifier {
|
||||||
|
@Override
|
||||||
|
public void collectUnifier(RecipeUnifierBuilder builder) {
|
||||||
|
builder.put("output", (json, ctx) -> {
|
||||||
|
return ctx.createResultReplacement(json, false, RecipeConstants.ITEM, "id");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
|
@ -94,16 +94,22 @@ public class RecipeContextImpl implements RecipeContext {
|
||||||
@Override
|
@Override
|
||||||
@Nullable
|
@Nullable
|
||||||
public JsonElement createResultReplacement(@Nullable JsonElement element) {
|
public JsonElement createResultReplacement(@Nullable JsonElement element) {
|
||||||
|
return createResultReplacement(element, true, RecipeConstants.ITEM);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
@Nullable
|
||||||
|
public JsonElement createResultReplacement(@Nullable JsonElement element, boolean includeTagCheck, String... lookupKeys) {
|
||||||
if (element == null) {
|
if (element == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
JsonElement copy = element.deepCopy();
|
JsonElement copy = element.deepCopy();
|
||||||
JsonElement result = tryCreateResultReplacement(copy);
|
JsonElement result = tryCreateResultReplacement(copy, includeTagCheck, lookupKeys);
|
||||||
return element.equals(result) ? null : result;
|
return element.equals(result) ? null : result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private JsonElement tryCreateResultReplacement(JsonElement element) {
|
public JsonElement tryCreateResultReplacement(JsonElement element, boolean lookupForTag, String... keys) {
|
||||||
if (element instanceof JsonPrimitive primitive) {
|
if (element instanceof JsonPrimitive primitive) {
|
||||||
ResourceLocation item = ResourceLocation.tryParse(primitive.getAsString());
|
ResourceLocation item = ResourceLocation.tryParse(primitive.getAsString());
|
||||||
ResourceLocation replacement = getReplacementForItem(item);
|
ResourceLocation replacement = getReplacementForItem(item);
|
||||||
|
@ -113,17 +119,20 @@ public class RecipeContextImpl implements RecipeContext {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof JsonArray array && JsonUtils.replaceOn(array, this::tryCreateResultReplacement)) {
|
if (element instanceof JsonArray array &&
|
||||||
|
JsonUtils.replaceOn(array, j -> tryCreateResultReplacement(j, lookupForTag, keys))) {
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (element instanceof JsonObject object) {
|
if (element instanceof JsonObject object) {
|
||||||
if (JsonUtils.replaceOn(object, RecipeConstants.ITEM, this::tryCreateResultReplacement)) {
|
for (String key : keys) {
|
||||||
return element;
|
if (JsonUtils.replaceOn(object, key, j -> tryCreateResultReplacement(j, lookupForTag, keys))) {
|
||||||
|
return element;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Some mods have tags for results instead of items. We replace those with the preferred item.
|
// Some mods have tags for results instead of items. We replace those with the preferred item.
|
||||||
if (object.get(RecipeConstants.TAG) instanceof JsonPrimitive primitive) {
|
if (lookupForTag && object.get(RecipeConstants.TAG) instanceof JsonPrimitive primitive) {
|
||||||
ResourceLocation item = getPreferredItemForTag(Utils.toItemTag(primitive.getAsString()), $ -> true);
|
ResourceLocation item = getPreferredItemForTag(Utils.toItemTag(primitive.getAsString()), $ -> true);
|
||||||
if (item != null) {
|
if (item != null) {
|
||||||
object.remove(RecipeConstants.TAG);
|
object.remove(RecipeConstants.TAG);
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.almostreliable.unified;
|
package com.almostreliable.unified;
|
||||||
|
|
||||||
import com.almostreliable.unified.api.ModConstants;
|
import com.almostreliable.unified.api.ModConstants;
|
||||||
|
import com.almostreliable.unified.compat.AdAstraRecipeUnifier;
|
||||||
import com.almostreliable.unified.compat.AmethystImbuementRecipeUnifier;
|
import com.almostreliable.unified.compat.AmethystImbuementRecipeUnifier;
|
||||||
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
||||||
import com.almostreliable.unified.utils.UnifyTag;
|
import com.almostreliable.unified.utils.UnifyTag;
|
||||||
|
@ -48,6 +49,7 @@ public class AlmostUnifiedPlatformFabric implements AlmostUnifiedPlatform {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindRecipeHandlers(RecipeHandlerFactory factory) {
|
public void bindRecipeHandlers(RecipeHandlerFactory factory) {
|
||||||
|
factory.registerForMod(ModConstants.AD_ASTRA, new AdAstraRecipeUnifier());
|
||||||
factory.registerForMod(ModConstants.AMETHYST_IMBUEMENT, new AmethystImbuementRecipeUnifier());
|
factory.registerForMod(ModConstants.AMETHYST_IMBUEMENT, new AmethystImbuementRecipeUnifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.almostreliable.unified;
|
package com.almostreliable.unified;
|
||||||
|
|
||||||
import com.almostreliable.unified.api.ModConstants;
|
import com.almostreliable.unified.api.ModConstants;
|
||||||
|
import com.almostreliable.unified.compat.AdAstraRecipeUnifier;
|
||||||
import com.almostreliable.unified.compat.IERecipeUnifier;
|
import com.almostreliable.unified.compat.IERecipeUnifier;
|
||||||
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
import com.almostreliable.unified.recipe.unifier.RecipeHandlerFactory;
|
||||||
import com.almostreliable.unified.utils.UnifyTag;
|
import com.almostreliable.unified.utils.UnifyTag;
|
||||||
|
@ -57,6 +58,7 @@ public class AlmostUnifiedPlatformForge implements AlmostUnifiedPlatform {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void bindRecipeHandlers(RecipeHandlerFactory factory) {
|
public void bindRecipeHandlers(RecipeHandlerFactory factory) {
|
||||||
|
factory.registerForMod(ModConstants.AD_ASTRA, new AdAstraRecipeUnifier());
|
||||||
factory.registerForMod(ModConstants.IE, new IERecipeUnifier());
|
factory.registerForMod(ModConstants.IE, new IERecipeUnifier());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue