Skip to content

Commit 0dd7ee9

Browse files
committed
fix sync issues
1 parent e1ad7eb commit 0dd7ee9

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

src/main/java/com/cleanroommc/modularui/value/sync/ModularSyncManager.java

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717
import net.minecraftforge.items.wrapper.PlayerMainInvWrapper;
1818

1919
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
20+
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
2021
import org.jetbrains.annotations.ApiStatus;
2122

2223
import java.io.IOException;
2324
import java.util.Map;
25+
import java.util.Set;
2426

2527
public class ModularSyncManager {
2628

@@ -29,6 +31,9 @@ public class ModularSyncManager {
2931
private static final String CURSOR_KEY = makeSyncKey("cursor_slot", 255255);
3032

3133
private final Map<String, PanelSyncManager> panelSyncManagerMap = new Object2ObjectOpenHashMap<>();
34+
// A set of all panels which have been opened during the ui. May also contain closed panels.
35+
// This is used to detect if
36+
private final Set<String> panelHistory = new ObjectOpenHashSet<>();
3237
private PanelSyncManager mainPSM;
3338
private final ModularContainer container;
3439
private final CursorSlotSyncHandler cursorSlotSyncHandler = new CursorSlotSyncHandler();
@@ -88,6 +93,7 @@ public void setCursorItem(ItemStack item) {
8893

8994
public void open(String name, PanelSyncManager syncManager) {
9095
this.panelSyncManagerMap.put(name, syncManager);
96+
this.panelHistory.add(name);
9197
syncManager.initialize(name, this);
9298
}
9399

@@ -101,7 +107,14 @@ public boolean isOpen(String panelName) {
101107
}
102108

103109
public void receiveWidgetUpdate(String panelName, String mapKey, int id, PacketBuffer buf) throws IOException {
104-
getPanelSyncManager(panelName).receiveWidgetUpdate(mapKey, id, buf);
110+
PanelSyncManager psm = this.panelSyncManagerMap.get(panelName);
111+
if (psm != null) {
112+
psm.receiveWidgetUpdate(mapKey, id, buf);
113+
} else if (!this.panelHistory.contains(panelName)) {
114+
ModularUI.LOGGER.throwing(new IllegalStateException("A packet was send to panel '" + panelName + "' which was not opened yet!."));
115+
}
116+
// else the panel was open at some point
117+
// we simply discard the packet silently and assume the packet was correctly send, but the panel closed earlier
105118
}
106119

107120
public EntityPlayer getPlayer() {

src/main/java/com/cleanroommc/modularui/value/sync/PanelSyncHandler.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,24 @@ private void openPanel(boolean syncToServer) {
6969
if (client) {
7070
ModularScreen screen = getSyncManager().getContainer().getScreen();
7171
if (!screen.isPanelOpen(this.openedPanel.getName())) {
72+
openInModularSyncManager();
7273
screen.getPanelManager().openPanel(this.openedPanel, this);
7374
} else {
7475
// this was not supposed to happen
7576
// make sure server side also closes the panel
7677
closePanelInternal();
7778
return;
7879
}
80+
} else {
81+
openInModularSyncManager();
7982
}
80-
getSyncManager().getModularSyncManager().open(this.panelName, this.syncManager);
8183
this.open = true;
8284
}
8385

86+
private void openInModularSyncManager() {
87+
getSyncManager().getModularSyncManager().open(this.panelName, this.syncManager);
88+
}
89+
8490
@Override
8591
public void closePanel() {
8692
if (getSyncManager().isClient()) {

0 commit comments

Comments
 (0)