diff --git a/src/main/java/codechicken/nei/BookmarkPanel.java b/src/main/java/codechicken/nei/BookmarkPanel.java index 7e8410736..d2a7a96c7 100644 --- a/src/main/java/codechicken/nei/BookmarkPanel.java +++ b/src/main/java/codechicken/nei/BookmarkPanel.java @@ -1170,10 +1170,12 @@ protected void drawItem(Rectangle4i rect, int idx) { final BookmarkGroup groupMeta = this.groups.get(meta.groupId); ItemStack drawStack = realStack; - if (groupMeta.crafting != null && groupMeta.crafting.getCalculatedItems().containsKey(idx)) { + if (groupMeta.crafting != null) { ItemStack craftingItemStack = groupMeta.crafting.getCalculatedItems().get(idx); if (craftingItemStack != null) { drawStack = craftingItemStack; + } else { + drawStack = StackInfo.loadFromNBT(StackInfo.itemStackToNBT(drawStack), 0); } } @@ -2712,8 +2714,9 @@ public boolean onMouseWheel(int shift, int mousex, int mousey) { } } else { if (!overMeta.ingredient) { - if (overMeta.fluidDisplay) { - shiftMultiplier *= overMeta.factor; + Integer stackSize = StackInfo.getFluidCellSize(BGrid.getItem(slot.slotIndex)); + if (overMeta.fluidDisplay && stackSize != null) { + shiftMultiplier *= stackSize; } overMeta.requestedAmount += shift * shiftMultiplier; } diff --git a/src/main/java/codechicken/nei/bookmarks/crafts/graph/CraftingGraph.java b/src/main/java/codechicken/nei/bookmarks/crafts/graph/CraftingGraph.java index b1c42a129..99c021def 100644 --- a/src/main/java/codechicken/nei/bookmarks/crafts/graph/CraftingGraph.java +++ b/src/main/java/codechicken/nei/bookmarks/crafts/graph/CraftingGraph.java @@ -69,11 +69,10 @@ public QueueElement withNextNode(CraftingGraphNode newNode, String requestedItem public CraftingGraph(Map nodes) { this.nodes = nodes; for (CraftingGraphNode node : nodes.values()) { - if (node instanceof RecipeGraphNode) { - RecipeGraphNode recipeNode = (RecipeGraphNode) node; + if (node instanceof RecipeGraphNode recipeNode) { recipeNode.getRecipe().allIngredients.stream().flatMap(Collection::stream) .forEach(it -> itemStackDummies.put(getItemStackGUID(it), it)); - recipeNode.getRecipe().result.stream().forEach(it -> itemStackDummies.put(getItemStackGUID(it), it)); + recipeNode.getRecipe().result.forEach(it -> itemStackDummies.put(getItemStackGUID(it), it)); } } } @@ -104,8 +103,7 @@ public void dfs(List request) { String requestedKey = queueElement.requestedKey; // Handle item node. - if (node instanceof ItemGraphNode) { - ItemGraphNode itemGraphNode = (ItemGraphNode) node; + if (node instanceof ItemGraphNode itemGraphNode) { itemGraphNode.addCrafts(queueElement.requestedAmount); inputTotal.compute(requestedKey, (k, v) -> (v == null ? 0 : v) + queueElement.requestedAmount); continue; @@ -206,8 +204,7 @@ public void postProcess(Map inputTotal) { } for (CraftingGraphNode node : distinctNodes.keySet()) { - if (node instanceof RecipeGraphNode) { - RecipeGraphNode recipeNode = (RecipeGraphNode) node; + if (node instanceof RecipeGraphNode recipeNode) { for (ItemStackWithMetadata pinnedOutput : recipeNode.getPinnedOutputs()) { String key = getItemStackGUID(pinnedOutput.getStack()); int newCount = recipeNode.getRecipe().result.stream() diff --git a/src/main/java/codechicken/nei/recipe/StackInfo.java b/src/main/java/codechicken/nei/recipe/StackInfo.java index 26587ab8a..9e3dafe9c 100644 --- a/src/main/java/codechicken/nei/recipe/StackInfo.java +++ b/src/main/java/codechicken/nei/recipe/StackInfo.java @@ -1,8 +1,10 @@ package codechicken.nei.recipe; +import java.lang.reflect.Method; import java.util.ArrayList; import java.util.HashMap; import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import net.minecraft.item.ItemStack; @@ -18,6 +20,7 @@ import codechicken.nei.api.IStackStringifyHandler; import codechicken.nei.recipe.stackinfo.DefaultStackStringifyHandler; import codechicken.nei.recipe.stackinfo.GTFluidStackStringifyHandler; +import cpw.mods.fml.relauncher.ReflectionHelper; public class StackInfo { @@ -34,9 +37,21 @@ protected boolean removeEldestEntry(Map.Entry eldest) { } }; + private static Method getContainersFromFluid = null; + private static Class itemCell = null; + static { stackStringifyHandlers.add(new DefaultStackStringifyHandler()); stackStringifyHandlers.add(new GTFluidStackStringifyHandler()); + try { + final ClassLoader loader = StackInfo.class.getClassLoader(); + final Class gtUtility = ReflectionHelper + .getClass(loader, "gregtech.api.util.GTUtility", "gregtech.api.util.GT_Utility"); + getContainersFromFluid = gtUtility.getMethod("getContainersFromFluid", FluidStack.class); + itemCell = ReflectionHelper.getClass(loader, "ic2.core.item.resources.ItemCell"); + } catch (Exception e) { + // do nothing + } } public static NBTTagCompound itemStackToNBT(ItemStack stack) { @@ -107,6 +122,35 @@ public static FluidStack getFluid(ItemStack stack) { return fluid; } + public static Integer getFluidCellSize(ItemStack stack) { + FluidStack fluid = getFluid(stack); + if (fluid == null || getContainersFromFluid == null) { + return null; + } + try { + Object obj = getContainersFromFluid.invoke(null, fluid); + List containers = (List) obj; + Integer cellCapacity = null; + int fallbackCapacity = 0; + + for (ItemStack container : containers) { + if (itemCell != null && itemCell.isInstance(container.getItem())) { + cellCapacity = FluidContainerRegistry.getContainerCapacity(fluid, container); + } else { + fallbackCapacity = Math + .max(fallbackCapacity, FluidContainerRegistry.getContainerCapacity(fluid, container)); + } + } + if (cellCapacity != null) { + return cellCapacity; + } else { + return fallbackCapacity == 0 ? null : fallbackCapacity; + } + } catch (Exception e) { + return null; + } + } + public static boolean isFluidContainer(ItemStack stack) { return stack.getItem() instanceof IFluidContainerItem || FluidContainerRegistry.isContainer(stack); }