1717import net .minecraftforge .items .wrapper .PlayerMainInvWrapper ;
1818
1919import it .unimi .dsi .fastutil .objects .Object2ObjectOpenHashMap ;
20+ import it .unimi .dsi .fastutil .objects .ObjectOpenHashSet ;
2021import org .jetbrains .annotations .ApiStatus ;
2122
2223import java .io .IOException ;
2324import java .util .Map ;
25+ import java .util .Set ;
2426
2527public 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 () {
0 commit comments