1212import gregtech .api .util .virtualregistry .VirtualEnderRegistry ;
1313import gregtech .api .util .virtualregistry .VirtualEntry ;
1414import gregtech .common .mui .widget .InteractableText ;
15+ import gregtech .integration .ftb .utility .FTBTeamHelper ;
1516
1617import net .minecraft .entity .player .EntityPlayer ;
1718import net .minecraft .entity .player .EntityPlayerMP ;
2425import net .minecraft .util .ITickable ;
2526
2627import codechicken .lib .raytracer .CuboidRayTraceResult ;
28+ import com .cleanroommc .modularui .api .IPanelHandler ;
2729import com .cleanroommc .modularui .api .drawable .IKey ;
30+ import com .cleanroommc .modularui .api .value .IBoolValue ;
2831import com .cleanroommc .modularui .api .widget .IWidget ;
2932import com .cleanroommc .modularui .drawable .DynamicDrawable ;
3033import com .cleanroommc .modularui .drawable .GuiTextures ;
@@ -96,6 +99,11 @@ protected final UUID getOwner() {
9699 return isPrivate ? playerUUID : null ;
97100 }
98101
102+ protected boolean canAccess (UUID other ) {
103+ return this .playerUUID == null || this .playerUUID .equals (other ) ||
104+ FTBTeamHelper .isSameTeam (this .playerUUID , other );
105+ }
106+
99107 @ Override
100108 public void readCustomData (int discriminator , @ NotNull PacketBuffer buf ) {
101109 super .readCustomData (discriminator , buf );
@@ -137,25 +145,34 @@ public boolean usesMui2() {
137145
138146 @ Override
139147 public ModularPanel buildUI (SidedPosGuiData guiData , PanelSyncManager guiSyncManager , UISettings settings ) {
140- var panel = GTGuis .createPanel (this , 176 , 192 );
141-
142- this .playerUUID = guiData .getPlayer ().getUniqueID ();
143-
144- return panel .child (CoverWithUI .createTitleRow (getPickItem ()))
148+ if (!isPrivate ()) {
149+ // if we're public, we update the player uuid
150+ // so when set to private, it'll use the latest player uuid
151+ this .playerUUID = guiData .getPlayer ().getUniqueID ();
152+ }
153+ return GTGuis .createPanel (this , 176 , 192 )
154+ .child (CoverWithUI .createTitleRow (getPickItem ()))
145155 .child (createWidgets (guiData , guiSyncManager ))
146156 .bindPlayerInventory ();
147157 }
148158
149159 protected Flow createWidgets (GuiData data , PanelSyncManager syncManager ) {
150- var name = new StringSyncValue (this ::getColorStr , this ::updateColor );
160+ StringSyncValue name ;
161+ UUID uuid = data .getPlayer ().getUniqueID ();
162+
163+ if (canAccess (uuid )) {
164+ name = new StringSyncValue (this ::getColorStr , this ::updateColor );
165+ } else {
166+ name = new StringSyncValue (this ::getColorStr );
167+ }
151168
152- var entrySelectorSH = syncManager .panel ("entry_selector" , entrySelector (getType ()), true );
169+ IPanelHandler entrySelectorSH = syncManager .panel ("entry_selector" , entrySelector (getType (), uuid ), true );
153170
154171 return Flow .column ().coverChildrenHeight ().top (24 )
155172 .margin (7 , 0 ).widthRel (1f )
156173 .child (Flow .row ().marginBottom (2 )
157174 .coverChildrenHeight ()
158- .child (createPrivateButton ())
175+ .child (createPrivateButton (uuid ))
159176 .child (createColorIcon ())
160177 .child (new TextFieldWidget ()
161178 // todo remove 'keepScrollBarInArea' when this is fixed in mui2
@@ -181,7 +198,7 @@ protected Flow createWidgets(GuiData data, PanelSyncManager syncManager) {
181198 }
182199 return true ;
183200 })))
184- .child (createIoRow ());
201+ .child (createIoRow (uuid ));
185202 }
186203
187204 protected abstract IWidget createEntrySlot ();
@@ -196,29 +213,39 @@ protected IWidget createColorIcon() {
196213 .marginRight (2 );
197214 }
198215
199- protected IWidget createPrivateButton () {
216+ protected IWidget createPrivateButton (UUID uniqueID ) {
217+ BooleanSyncValue syncValue ;
218+ if (canAccess (uniqueID ))
219+ syncValue = new BooleanSyncValue (this ::isPrivate , this ::setPrivate );
220+ else {
221+ syncValue = new BooleanSyncValue (this ::isPrivate );
222+ }
200223 return new ToggleButton ()
201- .value (new BooleanSyncValue (this ::isPrivate , this ::setPrivate ))
202- .tooltip (tooltip -> tooltip .setAutoUpdate (true ))
224+ .value (syncValue )
203225 .background (GTGuiTextures .PRIVATE_MODE_BUTTON [0 ])
204226 .hoverBackground (GTGuiTextures .PRIVATE_MODE_BUTTON [0 ])
205227 .selectedBackground (GTGuiTextures .PRIVATE_MODE_BUTTON [1 ])
206228 .selectedHoverBackground (GTGuiTextures .PRIVATE_MODE_BUTTON [1 ])
207- .tooltipBuilder (tooltip -> tooltip .addLine (IKey .lang (this .isPrivate ?
208- "cover.ender_fluid_link.private.tooltip.enabled" :
209- "cover.ender_fluid_link.private.tooltip.disabled" )))
229+ .addTooltip (true , IKey .lang ("cover.ender_fluid_link.private.tooltip.enabled" ))
230+ .addTooltip (false , IKey .lang ("cover.ender_fluid_link.private.tooltip.disabled" ))
210231 .marginRight (2 );
211232 }
212233
213- protected IWidget createIoRow () {
234+ protected IWidget createIoRow (UUID uuid ) {
235+ BooleanSyncValue syncValue ;
236+ if (canAccess (uuid )) {
237+ syncValue = new BooleanSyncValue (this ::isIoEnabled , this ::setIoEnabled );
238+ } else {
239+ syncValue = new BooleanSyncValue (this ::isIoEnabled );
240+ }
214241 return Flow .row ().marginBottom (2 )
215242 .coverChildrenHeight ()
216243 .child (new ToggleButton ()
217- .value (new BooleanSyncValue ( this :: isIoEnabled , this :: setIoEnabled ) )
218- .overlay (IKey .lang (() -> this . ioEnabled ?
219- "behaviour.soft_hammer.enabled" :
220- "behaviour.soft_hammer.disabled" )
221- .color (Color .WHITE .darker ( 1 ) ))
244+ .value (syncValue )
245+ .overlay (true , IKey .lang ("behaviour.soft_hammer.enabled" )
246+ . color ( Color . WHITE . main ))
247+ . overlay ( false , IKey . lang ( "behaviour.soft_hammer.disabled" )
248+ .color (Color .WHITE .main ))
222249 .widthRel (0.6f )
223250 .left (0 ));
224251 }
@@ -254,13 +281,15 @@ private void setPrivate(boolean isPrivate) {
254281 @ Override
255282 public void writeInitialSyncData (PacketBuffer packetBuffer ) {
256283 packetBuffer .writeString (this .playerUUID == null ? "null" : this .playerUUID .toString ());
284+ packetBuffer .writeBoolean (this .isPrivate );
257285 }
258286
259287 @ Override
260288 public void readInitialSyncData (PacketBuffer packetBuffer ) {
261289 // does client even need uuid info? just in case
262290 String uuidStr = packetBuffer .readString (36 );
263291 this .playerUUID = uuidStr .equals ("null" ) ? null : UUID .fromString (uuidStr );
292+ this .isPrivate = packetBuffer .readBoolean ();
264293 }
265294
266295 @ Override
@@ -285,11 +314,11 @@ public void writeToNBT(@NotNull NBTTagCompound nbt) {
285314 nbt .setInteger ("Frequency" , activeEntry .getColor ());
286315 }
287316
288- protected PanelSyncHandler .IPanelBuilder entrySelector (EntryTypes <T > type ) {
317+ protected PanelSyncHandler .IPanelBuilder entrySelector (EntryTypes <T > type , UUID uuid ) {
289318 return (syncManager , syncHandler ) -> {
290319 List <IWidget > rows = new ArrayList <>();
291320 for (String name : VirtualEnderRegistry .getEntryNames (getOwner (), type )) {
292- rows .add (createRow (name , syncManager , type ));
321+ rows .add (createRow (name , syncManager , type , uuid ));
293322 }
294323 return GTGuis .createPopupPanel ("entry_selector" , 168 , 112 , true )
295324 .child (IKey .lang ("cover.generic.ender.known_channels" )
@@ -299,7 +328,6 @@ protected PanelSyncHandler.IPanelBuilder entrySelector(EntryTypes<T> type) {
299328 .left (4 ))
300329 .child (new ListWidget <>()
301330 .children (rows )
302- // .builder(names, name -> createRow(name, syncManager, type))
303331 .background (GTGuiTextures .DISPLAY .asIcon ()
304332 .width (168 - 8 )
305333 .height (112 - 20 ))
@@ -342,13 +370,15 @@ protected PanelSyncHandler.IPanelBuilder entryDescription(String key, T entry) {
342370 };
343371 }
344372
345- protected IWidget createRow (final String name , final PanelSyncManager syncManager , final EntryTypes <T > type ) {
346- final T entry = VirtualEnderRegistry .getEntry (getOwner (), type , name );
347- var key = String .format ("entry#%s_description" , entry .getColorStr ());
348- var syncKey = PanelSyncManager .makeSyncKey (key , isPrivate ? 1 : 0 );
349- final var panelHandler = (PanelSyncHandler ) syncManager .panel (syncKey ,
373+ protected IWidget createRow (String name , PanelSyncManager syncManager ,
374+ EntryTypes <T > type , UUID uuid ) {
375+ T entry = VirtualEnderRegistry .getEntry (getOwner (), type , name );
376+ String key = String .format ("entry#%s_description" , entry .getColorStr ());
377+ String syncKey = PanelSyncManager .makeSyncKey (key , isPrivate ? 1 : 0 );
378+ IPanelHandler panelHandler = syncManager .panel (syncKey ,
350379 entryDescription (key , entry ), true );
351- final var syncHandler = new EnderCoverSyncHandler ();
380+
381+ EnderCoverSyncHandler syncHandler = new EnderCoverSyncHandler ();
352382 syncManager .syncValue (key + "_handler" , syncHandler );
353383
354384 return Flow .row ()
@@ -364,8 +394,13 @@ protected IWidget createRow(final String name, final PanelSyncManager syncManage
364394 .size (16 )
365395 .background (GTGuiTextures .SLOT .asIcon ().size (18 ))
366396 .top (1 ))
367- .child (new InteractableText <>(entry , this ::updateColor )
368- .tooltipAutoUpdate (true )
397+ .child (new InteractableText <>(entry , str -> {
398+ if (canAccess (uuid )) {
399+ updateColor (str );
400+ return true ;
401+ }
402+ return false ;
403+ }).tooltipAutoUpdate (true )
369404 .tooltipBuilder (tooltip -> {
370405 String desc = entry .getDescription ();
371406 if (!desc .isEmpty ()) tooltip .add (desc );
@@ -378,6 +413,8 @@ protected IWidget createRow(final String name, final PanelSyncManager syncManage
378413 .overlay (GuiTextures .GEAR )
379414 .addTooltipLine (IKey .lang ("cover.generic.ender.set_description.tooltip" ))
380415 .onMousePressed (i -> {
416+ if (!canAccess (uuid )) return false ;
417+
381418 // open entry settings
382419 if (panelHandler .isPanelOpen ()) {
383420 panelHandler .closePanel ();
@@ -392,6 +429,8 @@ protected IWidget createRow(final String name, final PanelSyncManager syncManage
392429 .setEnabledIf (w -> !Objects .equals (entry .getColor (), activeEntry .getColor ()))
393430 .addTooltipLine (IKey .lang ("cover.generic.ender.delete_entry" ))
394431 .onMousePressed (i -> {
432+ if (!canAccess (uuid )) return false ;
433+
395434 // todo option to force delete, maybe as a popup?
396435 deleteEntry (getOwner (), name );
397436 syncHandler .syncToServer (1 , buffer -> {
0 commit comments