2121 */
2222public final class PanelSyncHandler extends SyncHandler implements IPanelHandler {
2323
24+ public static final int SYNC_NOTIFY_OPEN = 0 ;
25+ public static final int SYNC_OPEN = 1 ;
26+ public static final int SYNC_CLOSE = 2 ;
27+ public static final int SYNC_DISPOSE = 3 ;
28+
2429 private final IPanelBuilder panelBuilder ;
2530 private final boolean subPanel ;
2631 private String panelName ;
@@ -51,7 +56,7 @@ private void openPanel(boolean syncToServer) {
5156 if (isPanelOpen ()) return ;
5257 boolean client = getSyncManager ().isClient ();
5358 if (syncToServer && client ) {
54- syncToServer (0 );
59+ syncToServer (SYNC_NOTIFY_OPEN );
5560 return ;
5661 }
5762 if (this .syncManager != null && this .syncManager .getModularSyncManager () != getSyncManager ().getModularSyncManager ()) {
@@ -94,7 +99,7 @@ public void closePanel() {
9499 this .openedPanel .closeIfOpen ();
95100 }
96101 } else {
97- syncToClient (2 );
102+ syncToClient (SYNC_CLOSE );
98103 }
99104 }
100105
@@ -109,15 +114,14 @@ public void closePanelInternal() {
109114 getSyncManager ().getModularSyncManager ().close (this .panelName );
110115 this .open = false ;
111116 if (getSyncManager ().isClient ()) {
112- syncToServer (2 );
117+ syncToServer (SYNC_CLOSE );
113118 }
114119 }
115120
116121 @ Override
117122 public void deleteCachedPanel () {
118123 if (openedPanel == null || isPanelOpen ()) return ;
119124 boolean canDispose = WidgetTree .foreachChild (openedPanel , iWidget -> {
120- if (!iWidget .isValid ()) return false ;
121125 if (iWidget instanceof ISynced <?> synced && synced .isSynced ()) {
122126 return !(synced .getSyncHandler () instanceof ItemSlotSH );
123127 }
@@ -126,12 +130,12 @@ public void deleteCachedPanel() {
126130
127131 // This is because we can't guarantee that the sync handlers of the new panel are the same.
128132 // Dynamic sync handler changing is very error-prone.
129- if (!canDispose )
133+ if (!canDispose ) {
130134 throw new UnsupportedOperationException ("Can't delete cached panel if it's still open or has ItemSlot Sync Handlers!" );
135+ }
131136
132137 disposePanel ();
133-
134- sync (3 );
138+ sync (SYNC_DISPOSE );
135139 }
136140
137141 private void disposePanel () {
@@ -152,23 +156,23 @@ public boolean isPanelOpen() {
152156
153157 @ Override
154158 public void readOnClient (int i , PacketBuffer packetBuffer ) throws IOException {
155- if (i == 1 ) {
159+ if (i == SYNC_OPEN ) {
156160 openPanel (false );
157- } else if (i == 2 ) {
161+ } else if (i == SYNC_CLOSE ) {
158162 closePanel ();
159- } else if (i == 3 ) {
163+ } else if (i == SYNC_DISPOSE ) {
160164 disposePanel ();
161165 }
162166 }
163167
164168 @ Override
165169 public void readOnServer (int i , PacketBuffer packetBuffer ) throws IOException {
166- if (i == 0 ) {
170+ if (i == SYNC_NOTIFY_OPEN ) {
167171 openPanel (false );
168- syncToClient (1 );
169- } else if (i == 2 ) {
172+ syncToClient (SYNC_OPEN );
173+ } else if (i == SYNC_CLOSE ) {
170174 closePanelInternal ();
171- } else if (i == 3 ) {
175+ } else if (i == SYNC_DISPOSE ) {
172176 disposePanel ();
173177 }
174178 }
0 commit comments