diff --git a/build.gradle b/build.gradle index abfb0ff..2d26d85 100644 --- a/build.gradle +++ b/build.gradle @@ -46,6 +46,13 @@ repositories { } } + maven { + url "https://maven.terraformersmc.com" + content { + includeGroup "dev.emi" + } + } + maven { name = "Local" url = file("libs").toURI() @@ -65,8 +72,23 @@ dependencies { exclude(group: "com.blamejared.crafttweaker") } - compileOnly("mezz.jei:jei-${minecraft_version}-common-api:${jei_version}") - runtimeOnly("mezz.jei:jei-${minecraft_version}-neoforge:${jei_version}") + if (project.runtime_itemlist_mod == "jei") { + implementation "mezz.jei:jei-${project.minecraft_version}-neoforge:${project.jei_version}" + } else { + compileOnly "mezz.jei:jei-${project.minecraft_version}-neoforge:${project.jei_version}" + } + + if (project.runtime_itemlist_mod == "emi") { + implementation "dev.emi:emi-neoforge:${project.emi_version}+${project.minecraft_version}" + // Add JEI so that we can use EMI's builtin compat layer + runtimeOnly "mezz.jei:jei-${project.minecraft_version}-neoforge:${project.jei_version}" + } else { + compileOnly "dev.emi:emi-neoforge:${project.emi_version}+${project.minecraft_version}" + } + + if (!(project.runtime_itemlist_mod in ["jei", "emi"])) { + 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 d6e4add..e5af8e3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -3,8 +3,14 @@ neoforge_version=20.4.173 ae2_version=17.0.5-beta mekanism_version=10.5.0.22 jei_version=17.0.0.30 +emi_version=1.1.0 jade_id=4980188 +# 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=[2,) neo_version_range=[20.4,) ae2_version_range=[17.0.0,18.0.0) diff --git a/src/main/java/me/ramidzkh/mekae2/integration/emi/AMEmiPlugin.java b/src/main/java/me/ramidzkh/mekae2/integration/emi/AMEmiPlugin.java new file mode 100644 index 0000000..b2314a3 --- /dev/null +++ b/src/main/java/me/ramidzkh/mekae2/integration/emi/AMEmiPlugin.java @@ -0,0 +1,21 @@ +package me.ramidzkh.mekae2.integration.emi; + +import net.neoforged.fml.ModList; + +import dev.emi.emi.api.EmiEntrypoint; +import dev.emi.emi.api.EmiPlugin; +import dev.emi.emi.api.EmiRegistry; + +@EmiEntrypoint +public class AMEmiPlugin implements EmiPlugin { + @Override + public void register(EmiRegistry emiRegistry) { + } + + static { + if (ModList.get().isLoaded("jei")) { + // We need both EMI and JEI to do anything! + MekanismJemiAdapter.init(); + } + } +} diff --git a/src/main/java/me/ramidzkh/mekae2/integration/emi/ChemicalIngredientConverter.java b/src/main/java/me/ramidzkh/mekae2/integration/emi/ChemicalIngredientConverter.java new file mode 100644 index 0000000..51764dd --- /dev/null +++ b/src/main/java/me/ramidzkh/mekae2/integration/emi/ChemicalIngredientConverter.java @@ -0,0 +1,56 @@ +package me.ramidzkh.mekae2.integration.emi; + +import com.mojang.logging.LogUtils; + +import org.jetbrains.annotations.Nullable; +import org.slf4j.Logger; + +import dev.emi.emi.api.stack.EmiStack; +import dev.emi.emi.jemi.JemiStack; +import dev.emi.emi.jemi.JemiUtil; +import me.ramidzkh.mekae2.ae2.MekanismKey; +import mekanism.api.chemical.Chemical; +import mekanism.api.chemical.ChemicalStack; + +import appeng.api.integrations.emi.EmiStackConverter; +import appeng.api.stacks.GenericStack; + +public final class ChemicalIngredientConverter implements EmiStackConverter { + private static final Logger LOGGER = LogUtils.getLogger(); + + @Override + public Class getKeyType() { + // It doesn't really matter, AE2 only checks that no two converters have the same type. + return Chemical.class; + } + + @Override + public @Nullable EmiStack toEmiStack(GenericStack stack) { + try { + if (stack.what() instanceof MekanismKey key) { + return JemiUtil.getStack(key.withAmount(Math.max(1, stack.amount()))); + } + } catch (Exception e) { // catch error in case JEMI internals change + LOGGER.error("Failed to convert GenericStack to EmiStack", e); + } + return null; + } + + @Override + public @Nullable GenericStack toGenericStack(EmiStack stack) { + try { + if (stack instanceof JemiStack jemiStack) { + var ing = jemiStack.ingredient; + if (ing instanceof ChemicalStack chemicalStack) { + var mekKey = MekanismKey.of(chemicalStack); + if (mekKey != null) { + return new GenericStack(mekKey, stack.getAmount()); + } + } + } + } catch (Exception e) { // catch error in case JEMI internals change + LOGGER.error("Failed to convert EmiStack to GenericStack", e); + } + return null; + } +} diff --git a/src/main/java/me/ramidzkh/mekae2/integration/emi/MekanismJemiAdapter.java b/src/main/java/me/ramidzkh/mekae2/integration/emi/MekanismJemiAdapter.java new file mode 100644 index 0000000..635b8df --- /dev/null +++ b/src/main/java/me/ramidzkh/mekae2/integration/emi/MekanismJemiAdapter.java @@ -0,0 +1,12 @@ +package me.ramidzkh.mekae2.integration.emi; + +import appeng.api.integrations.emi.EmiStackConverters; + +public final class MekanismJemiAdapter { + private MekanismJemiAdapter() { + } + + public static void init() { + EmiStackConverters.register(new ChemicalIngredientConverter()); + } +} diff --git a/src/main/java/me/ramidzkh/mekae2/integration/emi/package-info.java b/src/main/java/me/ramidzkh/mekae2/integration/emi/package-info.java new file mode 100644 index 0000000..5bc29e2 --- /dev/null +++ b/src/main/java/me/ramidzkh/mekae2/integration/emi/package-info.java @@ -0,0 +1,7 @@ +@ParametersAreNonnullByDefault +@MethodsReturnNonnullByDefault +package me.ramidzkh.mekae2.integration.emi; + +import javax.annotation.ParametersAreNonnullByDefault; + +import net.minecraft.MethodsReturnNonnullByDefault;