mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-08 12:34:46 +00:00
Fix Autocrafting Infinity Loop (#1004)
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
This commit is contained in:
1 parent
7d4c8b82ba
commit
c4f9c54200
3 files changed
+61
-50
No files matched your search
@@ -32,43 +32,46 @@ public class AutoCraftingManager {
|
||||
|
||||
StackInfo.pauseItemDamageSound(true);
|
||||
|
||||
do {
|
||||
changed = false;
|
||||
try {
|
||||
do {
|
||||
changed = false;
|
||||
|
||||
RecipeChainIterator iterator = new RecipeChainIterator(math, initialItems);
|
||||
iterator.updateInventory(getInventoryItems(guiContainer));
|
||||
RecipeChainIterator iterator = new RecipeChainIterator(math, initialItems);
|
||||
iterator.updateInventory(getInventoryItems(guiContainer));
|
||||
|
||||
while (iterator.hasNext() && !interrupted(guiContainer)) {
|
||||
final Map<RecipeId, Long> recipes = iterator.next();
|
||||
boolean craft = false;
|
||||
while (iterator.hasNext() && !interrupted(guiContainer)) {
|
||||
final Map<RecipeId, Long> recipes = iterator.next();
|
||||
boolean craft = false;
|
||||
|
||||
for (Map.Entry<RecipeId, Long> entry : recipes.entrySet()) {
|
||||
final RecipeHandlerRef handler = RecipeHandlerRef.of(entry.getKey());
|
||||
for (Map.Entry<RecipeId, Long> entry : recipes.entrySet()) {
|
||||
final RecipeHandlerRef handler = RecipeHandlerRef.of(entry.getKey());
|
||||
|
||||
if (handler != null && handler.canCraft(guiContainer)) {
|
||||
long multiplier = entry.getValue();
|
||||
if (handler != null && handler.canCraft(guiContainer)) {
|
||||
long multiplier = entry.getValue();
|
||||
|
||||
while (multiplier > 0 && !interrupted(guiContainer)
|
||||
&& handler.craft(guiContainer, (int) Math.min(64, multiplier))) {
|
||||
multiplier -= 64;
|
||||
while (multiplier > 0 && !interrupted(guiContainer)
|
||||
&& handler.craft(guiContainer, (int) Math.min(64, multiplier))) {
|
||||
multiplier -= 64;
|
||||
}
|
||||
|
||||
craft = craft || multiplier != entry.getValue();
|
||||
}
|
||||
|
||||
craft = multiplier != entry.getValue();
|
||||
if (interrupted(guiContainer)) break;
|
||||
}
|
||||
|
||||
if (interrupted(guiContainer)) break;
|
||||
if (craft) {
|
||||
changed = true;
|
||||
processed = true;
|
||||
iterator.updateInventory(getInventoryItems(guiContainer));
|
||||
}
|
||||
}
|
||||
|
||||
if (craft) {
|
||||
changed = true;
|
||||
processed = true;
|
||||
iterator.updateInventory(getInventoryItems(guiContainer));
|
||||
}
|
||||
}
|
||||
} while (changed && !interrupted(guiContainer));
|
||||
|
||||
} while (changed && !interrupted(guiContainer));
|
||||
|
||||
StackInfo.pauseItemDamageSound(false);
|
||||
} finally {
|
||||
StackInfo.pauseItemDamageSound(false);
|
||||
}
|
||||
|
||||
if (processed && !changed && !interrupted(guiContainer)) {
|
||||
NEIClientUtils.playClickSound();
|
||||
|
||||
@@ -123,6 +123,11 @@ public class DefaultOverlayHandler implements IOverlayHandler {
|
||||
|
||||
if (craftingSlot.getHasStack() && craftingSlot.canTakeStack(firstGui.mc.thePlayer)) {
|
||||
FastTransferManager.clickSlot(firstGui, craftingSlot.slotNumber, 0, 1);
|
||||
|
||||
if (craftingSlot.getHasStack()) {
|
||||
break;
|
||||
}
|
||||
|
||||
craft = true;
|
||||
}
|
||||
|
||||
|
||||
@@ -335,40 +335,43 @@ public class RecipeChainMath {
|
||||
final boolean isPausedItemDamageSound = StackInfo.isPausedItemDamageSound();
|
||||
StackInfo.pauseItemDamageSound(true);
|
||||
|
||||
resetCalculation();
|
||||
try {
|
||||
resetCalculation();
|
||||
|
||||
if (this.outputRecipes.containsKey(ROOT_RECIPE_ID)) {
|
||||
for (BookmarkItem ingrItem : this.recipeIngredients) {
|
||||
if (ROOT_RECIPE_ID.equals(ingrItem.recipeId)
|
||||
&& ingrItem.itemStack.getItem().hasContainerItem(ingrItem.itemStack)) {
|
||||
this.containerItemsBlacklist.add(ingrItem.itemStack);
|
||||
if (this.outputRecipes.containsKey(ROOT_RECIPE_ID)) {
|
||||
for (BookmarkItem ingrItem : this.recipeIngredients) {
|
||||
if (ROOT_RECIPE_ID.equals(ingrItem.recipeId)
|
||||
&& ingrItem.itemStack.getItem().hasContainerItem(ingrItem.itemStack)) {
|
||||
this.containerItemsBlacklist.add(ingrItem.itemStack);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (BookmarkItem prefItem : this.recipeResults) {
|
||||
if (!prefItem.emptyFactor() && this.outputRecipes.containsKey(prefItem.recipeId)) {
|
||||
final long prefMultiplier = this.outputRecipes.get(prefItem.recipeId);
|
||||
for (BookmarkItem prefItem : this.recipeResults) {
|
||||
if (!prefItem.emptyFactor() && this.outputRecipes.containsKey(prefItem.recipeId)) {
|
||||
final long prefMultiplier = this.outputRecipes.get(prefItem.recipeId);
|
||||
|
||||
if (prefItem.itemStack.getItem().hasContainerItem(prefItem.itemStack)) {
|
||||
this.containerItemsBlacklist.add(prefItem.itemStack);
|
||||
if (prefItem.itemStack.getItem().hasContainerItem(prefItem.itemStack)) {
|
||||
this.containerItemsBlacklist.add(prefItem.itemStack);
|
||||
}
|
||||
|
||||
this.preferredItems.put(prefItem, prefItem);
|
||||
calculateSuitableRecipe(prefItem, prefMultiplier, new ArrayList<>(), visitor);
|
||||
this.preferredItems.remove(prefItem);
|
||||
}
|
||||
|
||||
this.preferredItems.put(prefItem, prefItem);
|
||||
calculateSuitableRecipe(prefItem, prefMultiplier, new ArrayList<>(), visitor);
|
||||
this.preferredItems.remove(prefItem);
|
||||
}
|
||||
|
||||
for (BookmarkItem prefItem : this.recipeResults) {
|
||||
if (!prefItem.emptyFactor() && this.outputRecipes.containsKey(prefItem.recipeId)
|
||||
&& this.requiredAmount.containsKey(prefItem)) {
|
||||
final long prefAmount = prefItem.getAmount(this.outputRecipes.get(prefItem.recipeId));
|
||||
this.requiredAmount.put(prefItem, this.requiredAmount.get(prefItem) - prefAmount);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
StackInfo.pauseItemDamageSound(isPausedItemDamageSound);
|
||||
}
|
||||
|
||||
for (BookmarkItem prefItem : this.recipeResults) {
|
||||
if (!prefItem.emptyFactor() && this.outputRecipes.containsKey(prefItem.recipeId)
|
||||
&& this.requiredAmount.containsKey(prefItem)) {
|
||||
final long prefAmount = prefItem.getAmount(this.outputRecipes.get(prefItem.recipeId));
|
||||
this.requiredAmount.put(prefItem, this.requiredAmount.get(prefItem) - prefAmount);
|
||||
}
|
||||
}
|
||||
|
||||
StackInfo.pauseItemDamageSound(isPausedItemDamageSound);
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user