mirror of
https://github.com/GTNewHorizons/NotEnoughItems.git
synced 2026-11-20 12:20:00 +00:00
feat(autocraft): throttle crafting with speed ramp
Crafts now run one item at a time instead of in batches of 64, with an interruptible sleep between each craft driven by CraftRampThrottle. The delay starts high and decays toward a floor as long as the same recipe keeps crafting, and resets to instant whenever the recipe changes, giving auto-craft a visible slow-start-then-speed-up feel instead of instant bulk crafting.
This commit is contained in:
1 file changed
+18
-3
@@ -29,6 +29,7 @@ public class AutoCraftingManager {
|
||||
final List<BookmarkItem> initialItems = prepareInitialItems(math, getInventoryItems(guiContainer));
|
||||
boolean processed = false;
|
||||
boolean changed = false;
|
||||
final CraftRampThrottle throttle = new CraftRampThrottle();
|
||||
|
||||
StackInfo.pauseItemDamageSound(true);
|
||||
|
||||
@@ -48,9 +49,10 @@ public class AutoCraftingManager {
|
||||
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)) {
|
||||
sleepInterruptibly(throttle.nextDelayMs(entry.getKey()), guiContainer);
|
||||
if (interrupted(guiContainer) || !handler.craft(guiContainer, 1)) break;
|
||||
multiplier -= 1;
|
||||
}
|
||||
|
||||
craft = multiplier != entry.getValue();
|
||||
@@ -86,6 +88,19 @@ public class AutoCraftingManager {
|
||||
return interrupted() || guiContainer != NEIClientUtils.getGuiContainer();
|
||||
}
|
||||
|
||||
private void sleepInterruptibly(long delayMs, GuiContainer guiContainer) {
|
||||
long remaining = delayMs;
|
||||
while (remaining > 0 && !interrupted(guiContainer)) {
|
||||
final long chunk = Math.min(20L, remaining);
|
||||
try {
|
||||
Thread.sleep(chunk);
|
||||
} catch (InterruptedException ignored) {
|
||||
return;
|
||||
}
|
||||
remaining -= chunk;
|
||||
}
|
||||
}
|
||||
|
||||
private List<BookmarkItem> prepareInitialItems(RecipeChainMath math, ItemStackAmount inventory) {
|
||||
final List<BookmarkItem> initialItems = new ArrayList<>();
|
||||
|
||||
|
||||
Reference in new issue
Block a user