![stacc-api](https://media.forgecdn.net/avatars/thumbnails/769/674/256/256/638107262164848436.png)
Crafting large numbers of items at once freezes the game
James103 opened this issue ยท 11 comments
Minecraft 1.16.1
Stacc 1.16.1 4
In 1.15.2, I tried crafting 100,000 Stone Pickaxes and it caused the server to freeze for about 30 seconds. Then I tried crafting 1,000,000 Iron Blocks and it caused the server to freeze for a few minutes.
In 1.16.1, I tried crafting 100,000 Oak Logs and it caused the server to freeze for about 25 seconds (24544ms
from the log).
These freezes are most likely because the game rescans the entire recipe registry for each and every item to be crafted, instead of caching and first checking the most recently used recipe (similar to how FastWorkbench and FastFurnace does it).
By similar logic, the following also holds true:
-
Repairing a diamond helmet with a very large negative durability with a maxed-out stack of diamonds freezes the game for a few minutes. To reproduce:
/give @p diamond_helmet{Damage:1000000000)
and/give @p diamond 1000000000
-
Large numbers of trades at once may freeze the game for a few seconds to minutes. To reproduce:
summon villager ~ ~ ~ {VillagerData:{level:99,profession:"minecraft:armorer",type:"minecraft:desert"},Offers:{Recipes:[{maxUses:2147483647,priceMultiplier:0f,buy:{id:"minecraft:stone",Count:1b},sell:{id:"minecraft:dirt",Count:1b}}]}}
and/give @p stone 1000000000
With FastBench for Fabric on a vanilla crafting table, I get the following results:
- Crafting 100,000 Iron Blocks causes the client to freeze for less than a second.
- Crafting 1,000,000 Iron Blocks causes the client to freeze for a few seconds.
- Crafting 10,000,000 Iron Blocks causes the client to freeze for a few more seconds. The server also outputs a log entry saying that it was running about 5 seconds behind.
- Crafting 100,000,000 Iron Blocks causes the client to freeze for a couple minutes. The server also outputs a log entry saying that it was running about 50 seconds behind.
- Crafting 1 billion Iron Blocks will most likely crash the server due to the watchdog, if enabled.
not sure how to practically fix this without breaking a bunch of mods, either iitemstack will do it or a fapi addition is gonna need to be added
The problem is that fixing this would require rewriting a good portion of the crafting system and would be extremely likely to break mods.
yeah what I would do is prevent items from stacking over a certain number in the crafting table
small amendment
@Mixin(CraftingInventory.class)
public abstract class CraftingInventoryMixin_LimitStackSize implements Inventory {
private static final int STACC_SIZE_LIMIT;
static {
if(FabricLoader.getInstance().isModLoaded("fastbench")) {
STACC_SIZE_LIMIT = 1_000_000;
} else {
STACC_SIZE_LIMIT = 1_000;
}
}
@Override
public int getMaxCountPerStack() {
return STACC_SIZE_LIMIT;
}
}