Skip to content

Commit

Permalink
feat: recipe mod integration for jei and emi
Browse files Browse the repository at this point in the history
Ghost dragging support.
  • Loading branch information
raoulvdberge committed Nov 30, 2024
1 parent 035e0ff commit 4ed86ba
Show file tree
Hide file tree
Showing 8 changed files with 114 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
- Chemical support in the Importer.
- Chemical support in the Exporter.
- Chemical support in the External Storage.
- Ghost dragging support for chemicals in JEI and EMI.
10 changes: 10 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ repositories {
name = "JEI"
url = uri("https://maven.blamejared.com/")
}
maven {
name = "EMI"
url = uri("https://maven.terraformersmc.com/")
}
}

refinedarchitect {
Expand All @@ -40,12 +44,16 @@ base {
}

val refinedstorageVersion: String by project
val refinedstorageJeiIntegrationVersion: String by project
val minecraftVersion: String by project
val mekanismVersion: String by project
val jeiVersion: String by project
val emiVersion: String by project

dependencies {
api("com.refinedmods.refinedstorage:refinedstorage-neoforge:${refinedstorageVersion}")
runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-jei-integration-neoforge:${refinedstorageJeiIntegrationVersion}")
// runtimeOnly("com.refinedmods.refinedstorage:refinedstorage-emi-integration-neoforge:0.5.0")
compileOnlyApi("mekanism:Mekanism:${minecraftVersion}-${mekanismVersion}:api")
runtimeOnly("mekanism:Mekanism:${minecraftVersion}-${mekanismVersion}:all") {
exclude(group = "com.blamejared.crafttweaker")
Expand All @@ -54,5 +62,7 @@ dependencies {
compileOnlyApi("mezz.jei:jei-${minecraftVersion}-common-api:${jeiVersion}")
testCompileOnly("mezz.jei:jei-${minecraftVersion}-common:${jeiVersion}")
compileOnlyApi("mezz.jei:jei-${minecraftVersion}-neoforge-api:${jeiVersion}")
// runtimeOnly("dev.emi:emi-neoforge:${emiVersion}")
compileOnlyApi("dev.emi:emi-neoforge:${emiVersion}")
}

2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
refinedarchitectVersion=0.20.0
refinedstorageVersion=2.0.0-milestone.4.10
refinedstorageJeiIntegrationVersion=0.6.0
# https://www.curseforge.com/minecraft/mc-mods/mekanism/files/all
mekanismVersion=10.7.7.64
jeiVersion=19.20.0.241
emiVersion=1.1.11+1.21
minecraftVersion=1.21.1
# Gradle
org.gradle.jvmargs=-Xmx1G
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
import com.refinedmods.refinedstorage.mekanism.grid.ChemicalGridExtractionStrategy;
import com.refinedmods.refinedstorage.mekanism.grid.ChemicalGridInsertionStrategy;
import com.refinedmods.refinedstorage.mekanism.importer.ChemicalImporterTransferStrategyFactory;
import com.refinedmods.refinedstorage.mekanism.recipemod.EmiChemicalResourceModIngredientConverter;
import com.refinedmods.refinedstorage.mekanism.recipemod.JeiChemicalRecipeModIngredientConverter;
import com.refinedmods.refinedstorage.mekanism.storage.ChemicalStorageDiskItem;
import com.refinedmods.refinedstorage.mekanism.storage.ChemicalStorageVariant;
import com.refinedmods.refinedstorage.mekanism.storagemonitor.ChemicalStorageMonitorInsertionStrategy;
Expand All @@ -22,6 +24,7 @@
import net.minecraft.world.item.crafting.RecipeSerializer;
import net.neoforged.api.distmarker.Dist;
import net.neoforged.bus.api.IEventBus;
import net.neoforged.fml.ModList;
import net.neoforged.fml.common.Mod;
import net.neoforged.fml.event.lifecycle.FMLCommonSetupEvent;
import net.neoforged.fml.loading.FMLEnvironment;
Expand Down Expand Up @@ -97,6 +100,11 @@ private void setup(final FMLCommonSetupEvent e) {
RefinedStorageApi.INSTANCE.addExternalStorageProviderFactory(
new ChemicalPlatformExternalStorageProviderFactory()
);
if (ModList.get().isLoaded("emi")) {
RefinedStorageApi.INSTANCE.addIngredientConverter(new EmiChemicalResourceModIngredientConverter());
} else if (ModList.get().isLoaded("jei")) {
RefinedStorageApi.INSTANCE.addIngredientConverter(new JeiChemicalRecipeModIngredientConverter());
}
}

private void registerCreativeModeTabListener(final BuildCreativeModeTabContentsEvent e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ public Optional<ExternalStorageProvider> create(final ServerLevel level,

@Override
public int getPriority() {
return -2;
return -1;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package com.refinedmods.refinedstorage.mekanism.recipemod;

import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey;
import com.refinedmods.refinedstorage.common.api.support.resource.RecipeModIngredientConverter;
import com.refinedmods.refinedstorage.mekanism.ChemicalResource;

import java.util.Optional;

import dev.emi.emi.api.stack.EmiStack;
import mekanism.api.IMekanismAccess;
import mekanism.api.chemical.Chemical;
import net.neoforged.neoforge.fluids.FluidType;

import static com.refinedmods.refinedstorage.mekanism.ChemicalResource.ofChemicalStack;

public class EmiChemicalResourceModIngredientConverter implements RecipeModIngredientConverter {
@Override
public Optional<PlatformResourceKey> convertToResource(final Object ingredient) {
if (ingredient instanceof EmiStack emiStack) {
return IMekanismAccess.INSTANCE.emiHelper()
.asChemicalStack(emiStack)
.map(ChemicalResource::ofChemicalStack);
}
return Optional.empty();
}

@Override
public Optional<ResourceAmount> convertToResourceAmount(final Object ingredient) {
if (ingredient instanceof EmiStack emiStack) {
return IMekanismAccess.INSTANCE.emiHelper()
.asChemicalStack(emiStack)
.map(chemical -> new ResourceAmount(ofChemicalStack(chemical), emiStack.getAmount()));
}
return Optional.empty();
}

@Override
public Optional<Object> convertToIngredient(final PlatformResourceKey resourceKey) {
if (resourceKey instanceof ChemicalResource(Chemical chemical)) {
return Optional.of(IMekanismAccess.INSTANCE.emiHelper().createEmiStack(chemical, FluidType.BUCKET_VOLUME));
}
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.refinedmods.refinedstorage.mekanism.recipemod;

import com.refinedmods.refinedstorage.api.resource.ResourceAmount;
import com.refinedmods.refinedstorage.common.api.support.resource.PlatformResourceKey;
import com.refinedmods.refinedstorage.common.api.support.resource.RecipeModIngredientConverter;
import com.refinedmods.refinedstorage.mekanism.ChemicalResource;

import java.util.Optional;

import mekanism.api.chemical.Chemical;
import mekanism.api.chemical.ChemicalStack;
import net.neoforged.neoforge.fluids.FluidType;

import static com.refinedmods.refinedstorage.mekanism.ChemicalResource.ofChemicalStack;

public class JeiChemicalRecipeModIngredientConverter implements RecipeModIngredientConverter {
@Override
public Optional<PlatformResourceKey> convertToResource(final Object ingredient) {
if (ingredient instanceof ChemicalStack stack) {
return Optional.of(ofChemicalStack(stack));
}
return Optional.empty();
}

@Override
public Optional<ResourceAmount> convertToResourceAmount(final Object ingredient) {
if (ingredient instanceof ChemicalStack stack) {
return Optional.of(new ResourceAmount(ofChemicalStack(stack), stack.getAmount()));
}
return Optional.empty();
}

@Override
public Optional<Object> convertToIngredient(final PlatformResourceKey resourceKey) {
if (resourceKey instanceof ChemicalResource(Chemical chemical)) {
return Optional.of(new ChemicalStack(chemical, FluidType.BUCKET_VOLUME));
}
return Optional.empty();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@FieldsAndMethodsAreNonnullByDefault
package com.refinedmods.refinedstorage.mekanism.recipemod;

import com.refinedmods.refinedstorage.api.core.FieldsAndMethodsAreNonnullByDefault;

import javax.annotation.ParametersAreNonnullByDefault;

0 comments on commit 4ed86ba

Please sign in to comment.