Skip to content

Commit

Permalink
Bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Meegooo committed Sep 29, 2024
1 parent 7a46409 commit b84e99b
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 10 deletions.
9 changes: 6 additions & 3 deletions src/main/java/codechicken/nei/BookmarkPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1173,10 +1173,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);
}
}

Expand Down Expand Up @@ -2715,8 +2717,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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,10 @@ public QueueElement withNextNode(CraftingGraphNode newNode, String requestedItem
public CraftingGraph(Map<String, CraftingGraphNode> 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));
}
}
}
Expand Down Expand Up @@ -104,8 +103,7 @@ public void dfs(List<ItemStackWithMetadata> 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;
Expand Down Expand Up @@ -206,8 +204,7 @@ public void postProcess(Map<String, Integer> 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()
Expand Down
44 changes: 44 additions & 0 deletions src/main/java/codechicken/nei/recipe/StackInfo.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 {

Expand All @@ -34,9 +37,21 @@ protected boolean removeEldestEntry(Map.Entry<ItemStack, FluidStack> 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) {
Expand Down Expand Up @@ -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<ItemStack> containers = (List<ItemStack>) 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);
}
Expand Down

0 comments on commit b84e99b

Please sign in to comment.