diff --git a/build.gradle b/build.gradle index 5918497..6a31728 100644 --- a/build.gradle +++ b/build.gradle @@ -37,6 +37,15 @@ repositories { } } + maven { + name = "Jared maven" + url = uri("https://maven.blamejared.com") + + content { + includeGroup("mezz.jei") + } + } + maven { name = "Local" url = file("libs").toURI() @@ -52,7 +61,17 @@ dependencies { compileOnly("mekanism:Mekanism:${minecraft_version}-${mekanism_version}:api") runtimeOnly("mekanism:Mekanism:${minecraft_version}-${mekanism_version}:all") - implementation("dev.emi:emi-neoforge:${project.emi_version}") + if (project.runtime_itemlist_mod == "emi") { + implementation("dev.emi:emi-neoforge:${project.emi_version}") + compileOnly("mezz.jei:jei-${project.minecraft_version}-neoforge:${project.jei_version}") + compileOnly("curse.maven:ae2-jei-integration-1074338:${jei_ae2_integration_id}") + } else if (project.runtime_itemlist_mod == "jei") { + compileOnly("dev.emi:emi-neoforge:${project.emi_version}") + implementation("mezz.jei:jei-${project.minecraft_version}-neoforge:${project.jei_version}") + implementation("curse.maven:ae2-jei-integration-1074338:${jei_ae2_integration_id}") + } else { + throw new GradleException("Invalid runtime_itemlist_mod value: " + project.runtime_itemlist_mod) + } compileOnly("curse.maven:jade-324717:${jade_id}") } diff --git a/gradle.properties b/gradle.properties index 3ddc5cd..7d05a80 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,9 +1,16 @@ minecraft_version=1.21.1 neoforge_version=21.1.22 -ae2_version=19.0.20-beta +ae2_version=19.0.22-beta mekanism_version=10.7.0.55 emi_version=1.1.12+1.21 jade_id=5427817 +jei_version=19.9.1.124 +jei_ae2_integration_id=5663887 + +# Dev runtime options +## Set to "jei" or "emi" to pick which tooltip mod gets picked at runtime +## for the dev environment. +runtime_itemlist_mod=emi loader_version_range=[1,) neo_version_range=[21.0,) diff --git a/src/main/java/me/ramidzkh/mekae2/integration/jei/AE2JeiIntegrationHelper.java b/src/main/java/me/ramidzkh/mekae2/integration/jei/AE2JeiIntegrationHelper.java new file mode 100644 index 0000000..f598be7 --- /dev/null +++ b/src/main/java/me/ramidzkh/mekae2/integration/jei/AE2JeiIntegrationHelper.java @@ -0,0 +1,9 @@ +package me.ramidzkh.mekae2.integration.jei; + +import tamaized.ae2jeiintegration.api.integrations.jei.IngredientConverters; + +public class AE2JeiIntegrationHelper { + public static void register() { + IngredientConverters.register(new ChemicalIngredientConverter()); + } +} diff --git a/src/main/java/me/ramidzkh/mekae2/integration/jei/AMJeiPlugin.java b/src/main/java/me/ramidzkh/mekae2/integration/jei/AMJeiPlugin.java new file mode 100644 index 0000000..5ec1bbb --- /dev/null +++ b/src/main/java/me/ramidzkh/mekae2/integration/jei/AMJeiPlugin.java @@ -0,0 +1,31 @@ +package me.ramidzkh.mekae2.integration.jei; + +import net.minecraft.resources.ResourceLocation; +import net.neoforged.fml.ModList; +import net.neoforged.fml.loading.LoadingModList; +import net.neoforged.fml.loading.moddiscovery.ModInfo; + +import me.ramidzkh.mekae2.AppliedMekanistics; +import mezz.jei.api.IModPlugin; +import mezz.jei.api.JeiPlugin; + +@JeiPlugin +public class AMJeiPlugin implements IModPlugin { + @Override + public ResourceLocation getPluginUid() { + return ResourceLocation.fromNamespaceAndPath(AppliedMekanistics.ID, "jei_plugin"); + } + + public AMJeiPlugin() { + if (isModLoaded("ae2jeiintegration")) { + AE2JeiIntegrationHelper.register(); + } + } + + private static boolean isModLoaded(String modId) { + if (ModList.get() == null) { + return LoadingModList.get().getMods().stream().map(ModInfo::getModId).anyMatch(modId::equals); + } + return ModList.get().isLoaded(modId); + } +} diff --git a/src/main/java/me/ramidzkh/mekae2/integration/jei/ChemicalIngredientConverter.java b/src/main/java/me/ramidzkh/mekae2/integration/jei/ChemicalIngredientConverter.java new file mode 100644 index 0000000..8885140 --- /dev/null +++ b/src/main/java/me/ramidzkh/mekae2/integration/jei/ChemicalIngredientConverter.java @@ -0,0 +1,45 @@ +package me.ramidzkh.mekae2.integration.jei; + +import org.jetbrains.annotations.Nullable; + +import me.ramidzkh.mekae2.ae2.MekanismKey; +import mekanism.api.IMekanismAccess; +import mekanism.api.chemical.ChemicalStack; +import mekanism.api.integration.jei.IMekanismJEIHelper; +import mezz.jei.api.ingredients.IIngredientHelper; +import mezz.jei.api.ingredients.IIngredientType; +import tamaized.ae2jeiintegration.api.integrations.jei.IngredientConverter; + +import appeng.api.stacks.GenericStack; + +public class ChemicalIngredientConverter implements IngredientConverter { + private final IIngredientType ingredientType; + + public ChemicalIngredientConverter() { + IMekanismJEIHelper mekJeiHelper = IMekanismAccess.INSTANCE.jeiHelper(); + IIngredientHelper chemicalStackHelper = mekJeiHelper.getChemicalStackHelper(); + this.ingredientType = chemicalStackHelper.getIngredientType(); + } + + @Override + public IIngredientType getIngredientType() { + return ingredientType; + } + + @Override + public @Nullable ChemicalStack getIngredientFromStack(GenericStack genericStack) { + if (genericStack.what() instanceof MekanismKey key) { + return key.withAmount(genericStack.amount()); + } + return null; + } + + @Override + public @Nullable GenericStack getStackFromIngredient(ChemicalStack chemicalStack) { + var what = MekanismKey.of(chemicalStack); + if (what == null) { + return null; + } + return new GenericStack(what, chemicalStack.getAmount()); + } +} diff --git a/src/main/java/me/ramidzkh/mekae2/integration/jei/package-info.java b/src/main/java/me/ramidzkh/mekae2/integration/jei/package-info.java new file mode 100644 index 0000000..3242e34 --- /dev/null +++ b/src/main/java/me/ramidzkh/mekae2/integration/jei/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +package me.ramidzkh.mekae2.integration.jei; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.MethodsReturnNonnullByDefault;