Skip to content

Commit 94cce77

Browse files
committed
fix: skip ResearchTreeScreen graph rebuild when registry is unchanged
buildGraph() was called unconditionally every 20 ticks (once per second), performing a full teardown and reconstruction even when no data had changed. A graphDirty flag now gates rebuilds; the flag is only set when ResearchRegistry.size() changes (e.g. on datapack reload).
1 parent e6d4af8 commit 94cce77

1 file changed

Lines changed: 10 additions & 0 deletions

File tree

src/main/java/com/researchcube/client/screen/ResearchTreeScreen.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@ private record Dependency(ResourceLocation sourceId, EdgeStyle style) {}
100100
private int graphMaxX;
101101
private int graphMaxY;
102102
private int refreshTicks = 0;
103+
private int lastRegistrySize = -1;
104+
private boolean graphDirty = true;
103105

104106
public ResearchTreeScreen(ResearchTableMenu menu, Inventory playerInv, Component title) {
105107
super(menu, playerInv, title);
@@ -142,6 +144,14 @@ public void containerTick() {
142144
super.containerTick();
143145
refreshTicks++;
144146
if (refreshTicks % 20 == 0) {
147+
int currentSize = ResearchRegistry.size();
148+
if (currentSize != lastRegistrySize) {
149+
graphDirty = true;
150+
lastRegistrySize = currentSize;
151+
}
152+
}
153+
if (graphDirty) {
154+
graphDirty = false;
145155
buildGraph();
146156
clampPan();
147157
}

0 commit comments

Comments
 (0)