Skip to content

Commit

Permalink
Let it work with PatternEncodingTermMenus
Browse files Browse the repository at this point in the history
  • Loading branch information
ramidzkh committed Oct 17, 2024
1 parent 4245511 commit f5cc940
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,27 +13,32 @@

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;
import net.minecraft.world.item.crafting.Recipe;
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.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<T extends AEBaseMenu> implements StandardRecipeHandler<T> {
Expand Down Expand Up @@ -68,6 +73,27 @@ public List<Slot> getCraftingSlots(T menu) {
return null;
}

@Override
public EmiPlayerInventory getInventory(AbstractContainerScreen<T> screen) {
var list = new ArrayList<EmiStack>();

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()) {
list.add(EmiStackHelper.toEmiStack(new GenericStack(entry.getWhat(), entry.getStoredAmount())));
}
}
}

return new EmiPlayerInventory(list);
}

@Override
public boolean canCraft(EmiRecipe recipe, EmiCraftContext<T> context) {
if (context.getType() == EmiCraftContext.Type.FILL_BUTTON) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package appeng.integration.modules.emi;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;

import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.core.NonNullList;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.CraftingBookCategory;
import net.minecraft.world.item.crafting.Ingredient;
Expand All @@ -17,14 +14,11 @@
import net.minecraft.world.item.crafting.ShapedRecipe;
import net.minecraft.world.item.crafting.ShapedRecipePattern;

import dev.emi.emi.api.recipe.EmiPlayerInventory;
import dev.emi.emi.api.recipe.EmiRecipe;
import dev.emi.emi.api.stack.EmiStack;

import appeng.api.stacks.GenericStack;
import appeng.core.localization.ItemModText;
import appeng.integration.modules.itemlists.CraftingHelper;
import appeng.menu.me.common.GridInventoryEntry;
import appeng.menu.me.items.CraftingTermMenu;

/**
Expand All @@ -47,25 +41,6 @@ public EmiUseCraftingRecipeHandler(Class<T> containerClass) {
super(containerClass);
}

@Override
public EmiPlayerInventory getInventory(AbstractContainerScreen<T> screen) {
List<EmiStack> list = new ArrayList<>();

for (Slot slot : getInputSources(screen.getMenu())) {
list.add(EmiStack.of(slot.getItem()));
}

var repo = screen.getMenu().getClientRepo();

if (repo != null) {
for (GridInventoryEntry entry : repo.getAllEntries()) {
list.add(EmiStackHelper.toEmiStack(new GenericStack(entry.getWhat(), entry.getStoredAmount())));
}
}

return new EmiPlayerInventory(list);
}

@Override
protected Result transferRecipe(T menu, RecipeHolder<?> holder, EmiRecipe emiRecipe, boolean doTransfer) {

Expand Down

0 comments on commit f5cc940

Please sign in to comment.