Skip to content

Commit

Permalink
Optimize Chain Algorithm
Browse files Browse the repository at this point in the history
  • Loading branch information
slprime committed Jan 14, 2024
1 parent c5c798c commit b16916d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/main/java/codechicken/nei/BookmarkCraftingChain.java
Original file line number Diff line number Diff line change
Expand Up @@ -269,27 +269,23 @@ private boolean calculateShift(CraftingChainRequest request, int stackIndex) {
return false;
}

int shift = 0;
int minRecipeIndex = 0;
int minShift = 0x7fffff;
int minShift = Integer.MAX_VALUE;

for (CraftingChainItem item : request.outputs.get(stackIndex)) {
if (!request.initialItems.contains(item.recipeIndex) && item.factor > 0) {
long ingrCount = calculateCount(request, request.inputs.get(item.stackIndex));
long outputCount = calculateCount(request, request.outputs.get(item.stackIndex));
long shift = (ingrCount - outputCount) / item.factor;

while ((outputCount + item.factor * shift) < ingrCount && shift < minShift) {
shift++;
}

if (shift < minShift) {
minShift = shift;
if (shift > 0 && shift < minShift) {
minShift = (int) shift;
minRecipeIndex = item.recipeIndex;
}
}
}

if (minShift < 0x7fffff) {
if (minShift < Integer.MAX_VALUE) {
request.multiplier.put(minRecipeIndex, request.multiplier.get(minRecipeIndex) + minShift);
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/codechicken/nei/BookmarkPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -1983,7 +1983,7 @@ public void mouseUp(int mousex, int mousey, int button) {
if (this.sortableItem != null) {
this.sortableItem = null;
this.mouseDownSlot = -1;
grid.onGridChanged(); /* make sure grid redraws the new item */
grid.onItemsChanged(); /* make sure grid redraws the new item */
saveBookmarks();
} else if (this.groupingItem != null) {
final BookmarkGrid BGrid = (BookmarkGrid) grid;
Expand Down

0 comments on commit b16916d

Please sign in to comment.