Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Native EMI support with Mekanism #59

Merged
merged 1 commit into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 11 additions & 35 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
plugins {
id("net.neoforged.gradle.userdev") version "7.0.57"
id("net.neoforged.gradle.userdev") version "7.0.80"
id("com.matthewprenger.cursegradle") version "1.4.0"
id("com.diffplug.spotless") version "6.23.3"
id("com.diffplug.spotless") version "6.25.0"
id("com.modrinth.minotaur") version "2.8.7"
}

Expand All @@ -22,34 +22,26 @@ repositories {
exclusiveContent {
forRepository {
maven {
name = "Jared maven"
url = uri("https://maven.blamejared.com")
name = "CurseForge"
url = uri("https://www.cursemaven.com")
}
}

filter {
includeGroup("mezz.jei")
includeGroup("mezz.jei")
includeGroup("curse.maven")
}
}

exclusiveContent {
forRepository {
maven {
name = "CurseForge"
url = uri("https://www.cursemaven.com")
name = "TerraformersMC"
url = uri("https://maven.terraformersmc.com/")
}
}

filter {
includeGroup("curse.maven")
}
}

maven {
url "https://maven.terraformersmc.com"
content {
includeGroup "dev.emi"
includeGroup("dev.emi")
}
}

Expand All @@ -72,23 +64,7 @@ dependencies {
exclude(group: "com.blamejared.crafttweaker")
}

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)
}
implementation("dev.emi:emi-neoforge:${project.emi_version}+${project.minecraft_version}")

compileOnly("curse.maven:jade-324717:${jade_id}")
}
Expand Down Expand Up @@ -119,11 +95,11 @@ runs {
}

server {
programArgument '--nogui'
programArgument("--nogui")
}

data {
programArguments.addAll "--mod", "appmek", "--all", "--output", file("src/generated/resources/").getAbsolutePath(), "--existing", file("src/main/resources/").getAbsolutePath()
programArguments.addAll("--mod", "appmek", "--all", "--output", file("src/generated/resources/").getAbsolutePath(), "--existing", file("src/main/resources/").getAbsolutePath())
}
}

Expand Down
16 changes: 5 additions & 11 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
minecraft_version=1.20.4
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
neoforge_version=20.4.210
ae2_version=17.12.0-beta
mekanism_version=10.5.10.32
emi_version=1.1.4
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)
mekanism_version_range=[10.5.0,11-)
mekanism_version_range=[10.5.10,11-)

org.gradle.caching=true
org.gradle.parallel=true
Expand Down
15 changes: 5 additions & 10 deletions src/main/java/me/ramidzkh/mekae2/integration/emi/AMEmiPlugin.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,16 @@
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;

import appeng.api.integrations.emi.EmiStackConverters;

@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();
}
@Override
public void register(EmiRegistry registry) {
EmiStackConverters.register(new ChemicalIngredientConverter());
}
}
Original file line number Diff line number Diff line change
@@ -1,22 +1,16 @@
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.IMekanismAccess;
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() {
Expand All @@ -26,31 +20,25 @@ public Class<?> getKeyType() {

@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);
if (stack.what() instanceof MekanismKey key) {
return IMekanismAccess.INSTANCE.emiHelper().createEmiStack(key.getStack().getType(), stack.amount());
Technici4n marked this conversation as resolved.
Show resolved Hide resolved
}

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());
}
}
var chemical = IMekanismAccess.INSTANCE.emiHelper().asChemicalStack(stack).orElse(null);

if (chemical != null) {
var what = MekanismKey.of(chemical);

if (what != null) {
return new GenericStack(what, stack.getAmount());
}
} catch (Exception e) { // catch error in case JEMI internals change
LOGGER.error("Failed to convert EmiStack to GenericStack", e);
}

return null;
}
}

This file was deleted.

This file was deleted.

Loading