diff --git a/src/main/java/appeng/core/AEConfig.java b/src/main/java/appeng/core/AEConfig.java index 4ff15161955..a1b419f63ef 100644 --- a/src/main/java/appeng/core/AEConfig.java +++ b/src/main/java/appeng/core/AEConfig.java @@ -228,6 +228,10 @@ public boolean isEnableFacadeRecipesInRecipeViewer() { return client.enableFacadeRecipesInRecipeViewer.getAsBoolean(); } + public boolean isExposeNetworkInventoryToEmi() { + return client.exposeNetworkInventoryToEmi.getAsBoolean(); + } + public int getCraftingCalculationTimePerTick() { return common.craftingCalculationTimePerTick.get(); } @@ -424,6 +428,7 @@ private static class ClientConfig { public final BooleanValue disableColoredCableRecipesInRecipeViewer; public final BooleanValue enableFacadesInRecipeViewer; public final BooleanValue enableFacadeRecipesInRecipeViewer; + public final BooleanValue exposeNetworkInventoryToEmi; public final EnumValue selectedPowerUnit; public final BooleanValue debugGuiOverlays; public final BooleanValue showPlacementPreview; @@ -458,6 +463,8 @@ public ClientConfig() { "Show facades in REI/JEI/EMI item list"); this.enableFacadeRecipesInRecipeViewer = define(builder, "enableFacadeRecipesInRecipeViewer", true, "Show facade recipes in REI/JEI/EMI for supported blocks"); + this.exposeNetworkInventoryToEmi = define(builder, "provideNetworkInventoryToEmi", false, + "Expose the full network inventory to EMI, which might cause performance problems."); builder.pop(); builder.push("client"); diff --git a/src/main/java/appeng/integration/modules/emi/AbstractRecipeHandler.java b/src/main/java/appeng/integration/modules/emi/AbstractRecipeHandler.java index 5e5df2ee678..62815932913 100644 --- a/src/main/java/appeng/integration/modules/emi/AbstractRecipeHandler.java +++ b/src/main/java/appeng/integration/modules/emi/AbstractRecipeHandler.java @@ -13,6 +13,7 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.GuiGraphics; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; import net.minecraft.client.gui.screens.inventory.tooltip.ClientTooltipComponent; import net.minecraft.network.chat.Component; import net.minecraft.world.inventory.Slot; @@ -20,20 +21,25 @@ import net.minecraft.world.item.crafting.RecipeHolder; import net.minecraft.world.level.Level; +import dev.emi.emi.api.recipe.EmiPlayerInventory; import dev.emi.emi.api.recipe.EmiRecipe; import dev.emi.emi.api.recipe.VanillaEmiRecipeCategories; import dev.emi.emi.api.recipe.handler.EmiCraftContext; import dev.emi.emi.api.recipe.handler.StandardRecipeHandler; import dev.emi.emi.api.stack.EmiIngredient; +import dev.emi.emi.api.stack.EmiStack; import dev.emi.emi.api.widget.Bounds; import dev.emi.emi.api.widget.SlotWidget; import dev.emi.emi.api.widget.Widget; import appeng.api.stacks.AEKey; +import appeng.api.stacks.GenericStack; +import appeng.core.AEConfig; import appeng.integration.modules.itemlists.EncodingHelper; import appeng.integration.modules.itemlists.TransferHelper; import appeng.menu.AEBaseMenu; import appeng.menu.SlotSemantics; +import appeng.menu.me.common.MEStorageMenu; import appeng.menu.me.items.CraftingTermMenu; abstract class AbstractRecipeHandler implements StandardRecipeHandler { @@ -51,6 +57,7 @@ public List getInputSources(T menu) { var slots = new ArrayList(); slots.addAll(menu.getSlots(SlotSemantics.PLAYER_INVENTORY)); slots.addAll(menu.getSlots(SlotSemantics.PLAYER_HOTBAR)); + slots.addAll(menu.getSlots(SlotSemantics.CRAFTING_GRID)); return slots; } @@ -67,6 +74,34 @@ public List getCraftingSlots(T menu) { return null; } + @Override + public EmiPlayerInventory getInventory(AbstractContainerScreen screen) { + if (!AEConfig.instance().isExposeNetworkInventoryToEmi()) { + return StandardRecipeHandler.super.getInventory(screen); + } + + var list = new ArrayList(); + + for (Slot slot : getInputSources(screen.getMenu())) { + list.add(EmiStack.of(slot.getItem())); + } + + if (screen.getMenu() instanceof MEStorageMenu menu) { + var repo = menu.getClientRepo(); + + if (repo != null) { + for (var entry : repo.getAllEntries()) { + if (entry.getStoredAmount() <= 0) { + continue; // Skip items that are only craftable + } + list.add(EmiStackHelper.toEmiStack(new GenericStack(entry.getWhat(), entry.getStoredAmount()))); + } + } + } + + return new EmiPlayerInventory(list); + } + @Override public boolean canCraft(EmiRecipe recipe, EmiCraftContext context) { if (context.getType() == EmiCraftContext.Type.FILL_BUTTON) {