-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for Mek ingredients when running EMI+JEI
- Loading branch information
1 parent
aa13ca3
commit dfb2377
Showing
6 changed files
with
126 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/me/ramidzkh/mekae2/integration/emi/AMEmiPlugin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} | ||
} |
56 changes: 56 additions & 0 deletions
56
src/main/java/me/ramidzkh/mekae2/integration/emi/ChemicalIngredientConverter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
src/main/java/me/ramidzkh/mekae2/integration/emi/MekanismJemiAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
src/main/java/me/ramidzkh/mekae2/integration/emi/package-info.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
@ParametersAreNonnullByDefault | ||
@MethodsReturnNonnullByDefault | ||
package me.ramidzkh.mekae2.integration.emi; | ||
|
||
import javax.annotation.ParametersAreNonnullByDefault; | ||
|
||
import net.minecraft.MethodsReturnNonnullByDefault; |