From 8e055ec71d1c6d6fab77529baf82851cc346ca78 Mon Sep 17 00:00:00 2001 From: lc-1337 <62835225+lc-1337@users.noreply.github.com> Date: Fri, 13 Feb 2026 19:13:21 +0200 Subject: [PATCH] Allow swap wand caps in arcana terminal (#107) --- .../ContainerPartArcaneCraftingTerminal.java | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/src/main/java/thaumicenergistics/common/container/ContainerPartArcaneCraftingTerminal.java b/src/main/java/thaumicenergistics/common/container/ContainerPartArcaneCraftingTerminal.java index d5e400c5..972e9499 100644 --- a/src/main/java/thaumicenergistics/common/container/ContainerPartArcaneCraftingTerminal.java +++ b/src/main/java/thaumicenergistics/common/container/ContainerPartArcaneCraftingTerminal.java @@ -161,10 +161,10 @@ public class ContainerPartArcaneCraftingTerminal extends ContainerMEMonitorable boolean hasAll = true; AspectList wandAspectList = null; ItemWandCasting wandItem = null; + AppEngInternalInventory gridInventory = this.terminal.craftingGridInventory; // Get the cost - this.requiredAspects = ArcaneRecipeHelper.INSTANCE - .getRecipeAspectCost(this.terminal.craftingGridInventory, 0, 9, forRecipe); + this.requiredAspects = ArcaneRecipeHelper.INSTANCE.getRecipeAspectCost(gridInventory, 0, 9, forRecipe); // Ensure there is a cost if (this.requiredAspects == null) { @@ -176,6 +176,12 @@ public class ContainerPartArcaneCraftingTerminal extends ContainerMEMonitorable ItemStack wand = this.terminal.wandInventory.getStackInSlot(0); + boolean wandInGrid = false; + if (wand == null) { + wand = getWandFromGridInventory(); + if (wand != null) wandInGrid = true; + } + // Do we have a wand? if (wand != null) { // Get the wand item @@ -219,7 +225,37 @@ public class ContainerPartArcaneCraftingTerminal extends ContainerMEMonitorable // Did we have all the vis required? if (hasAll) { // Get the result of the recipe. - return ArcaneRecipeHelper.INSTANCE.getRecipeOutput(this.terminal.craftingGridInventory, 0, 9, forRecipe); + if (wandInGrid) { + AppEngInternalInventory ghostGrid = new AppEngInternalInventory(null, gridInventory.getSizeInventory()); + + for (int i = 0; i < gridInventory.getSizeInventory(); i++) { + ItemStack is = gridInventory.getStackInSlot(i); + if (is != null && is.getItem() instanceof ItemWandCasting ghostWandItem) { + is = is.copy(); + ghostWandItem.consumeAllVisCrafting( + is, + this.getInventoryPlayer().player, + this.requiredAspects, + true); + } + ghostGrid.setInventorySlotContents(i, is); + } + + return ArcaneRecipeHelper.INSTANCE.getRecipeOutput(ghostGrid, 0, 9, forRecipe); + } else return ArcaneRecipeHelper.INSTANCE + .getRecipeOutput(this.terminal.craftingGridInventory, 0, 9, forRecipe); + } + + return null; + } + + private ItemStack getWandFromGridInventory() { + AppEngInternalInventory gridInventory = this.terminal.craftingGridInventory; + for (int i = 0; i < gridInventory.getSizeInventory(); i++) { + ItemStack is = gridInventory.getStackInSlot(i); + if (wandSlot.isItemValid(is)) { + return is; + } } return null; @@ -363,7 +399,7 @@ public class ContainerPartArcaneCraftingTerminal extends ContainerMEMonitorable ItemStack wand = this.terminal.wandInventory.getStackInSlot(0); if (wand != null && wand.getItem() instanceof ItemWandCasting wandItem) { wandItem.consumeAllVisCrafting(wand, player, this.requiredAspects, true); - } else { + } else if (getWandFromGridInventory() == null) { AELog.error("Failed consume vis from the wand"); return; }