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

Add support for Chemicals to ae2jeiintegration #66

Merged
merged 2 commits into from
Aug 26, 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
21 changes: 20 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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}")
}
Expand Down
9 changes: 8 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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,)
Expand Down
Original file line number Diff line number Diff line change
@@ -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());
}
}
31 changes: 31 additions & 0 deletions src/main/java/me/ramidzkh/mekae2/integration/jei/AMJeiPlugin.java
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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<ChemicalStack> {
private final IIngredientType<ChemicalStack> ingredientType;

public ChemicalIngredientConverter() {
IMekanismJEIHelper mekJeiHelper = IMekanismAccess.INSTANCE.jeiHelper();
IIngredientHelper<ChemicalStack> chemicalStackHelper = mekJeiHelper.getChemicalStackHelper();
this.ingredientType = chemicalStackHelper.getIngredientType();
}

@Override
public IIngredientType<ChemicalStack> 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());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package me.ramidzkh.mekae2.integration.jei;

import javax.annotation.ParametersAreNonnullByDefault;

import net.minecraft.MethodsReturnNonnullByDefault;