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 ;
@@ -95,6 +98,11 @@ protected final UUID getOwner() {
9598 return isPrivate ? playerUUID : null ;
9699 }
97100
101+ protected boolean canAccess (UUID other ) {
102+ return this .playerUUID == null || this .playerUUID .equals (other ) ||
103+ FTBTeamHelper .isSameTeam (this .playerUUID , other );
104+ }
105+
98106 @ Override
99107 public void readCustomData (int discriminator , @ NotNull PacketBuffer buf ) {
100108 super .readCustomData (discriminator , buf );
@@ -136,25 +144,34 @@ public boolean usesMui2() {
136144
137145 @ Override
138146 public ModularPanel buildUI (SidedPosGuiData guiData , PanelSyncManager guiSyncManager ) {
139- var panel = GTGuis .createPanel (this , 176 , 192 );
140-
141- this .playerUUID = guiData .getPlayer ().getUniqueID ();
142-
143- return panel .child (CoverWithUI .createTitleRow (getPickItem ()))
147+ if (!isPrivate ()) {
148+ // if we're public, we update the player uuid
149+ // so when set to private, it'll use the latest player uuid
150+ this .playerUUID = guiData .getPlayer ().getUniqueID ();
151+ }
152+ return GTGuis .createPanel (this , 176 , 192 )
153+ .child (CoverWithUI .createTitleRow (getPickItem ()))
144154 .child (createWidgets (guiData , guiSyncManager ))
145155 .bindPlayerInventory ();
146156 }
147157
148158 protected Flow createWidgets (GuiData data , PanelSyncManager syncManager ) {
149- var name = new StringSyncValue (this ::getColorStr , this ::updateColor );
159+ StringSyncValue name ;
160+ UUID uuid = data .getPlayer ().getUniqueID ();
161+
162+ if (canAccess (uuid )) {
163+ name = new StringSyncValue (this ::getColorStr , this ::updateColor );
164+ } else {
165+ name = new StringSyncValue (this ::getColorStr );
166+ }
150167
151- var entrySelectorSH = syncManager .panel ("entry_selector" , entrySelector (getType ()), true );
168+ IPanelHandler entrySelectorSH = syncManager .panel ("entry_selector" , entrySelector (getType (), uuid ), true );
152169
153170 return Flow .column ().coverChildrenHeight ().top (24 )
154171 .margin (7 , 0 ).widthRel (1f )
155172 .child (Flow .row ().marginBottom (2 )
156173 .coverChildrenHeight ()
157- .child (createPrivateButton ())
174+ .child (createPrivateButton (uuid ))
158175 .child (createColorIcon ())
159176 .child (new TextFieldWidget ()
160177 // todo remove 'keepScrollBarInArea' when this is fixed in mui2
@@ -180,7 +197,7 @@ protected Flow createWidgets(GuiData data, PanelSyncManager syncManager) {
180197 }
181198 return true ;
182199 })))
183- .child (createIoRow ());
200+ .child (createIoRow (uuid ));
184201 }
185202
186203 protected abstract IWidget createEntrySlot ();
@@ -195,29 +212,39 @@ protected IWidget createColorIcon() {
195212 .marginRight (2 );
196213 }
197214
198- protected IWidget createPrivateButton () {
215+ protected IWidget createPrivateButton (UUID uniqueID ) {
216+ BooleanSyncValue syncValue ;
217+ if (canAccess (uniqueID ))
218+ syncValue = new BooleanSyncValue (this ::isPrivate , this ::setPrivate );
219+ else {
220+ syncValue = new BooleanSyncValue (this ::isPrivate );
221+ }
199222 return new ToggleButton ()
200- .value (new BooleanSyncValue (this ::isPrivate , this ::setPrivate ))
201- .tooltip (tooltip -> tooltip .setAutoUpdate (true ))
223+ .value (syncValue )
202224 .background (GTGuiTextures .PRIVATE_MODE_BUTTON [0 ])
203225 .hoverBackground (GTGuiTextures .PRIVATE_MODE_BUTTON [0 ])
204226 .selectedBackground (GTGuiTextures .PRIVATE_MODE_BUTTON [1 ])
205227 .selectedHoverBackground (GTGuiTextures .PRIVATE_MODE_BUTTON [1 ])
206- .tooltipBuilder (tooltip -> tooltip .addLine (IKey .lang (this .isPrivate ?
207- "cover.ender_fluid_link.private.tooltip.enabled" :
208- "cover.ender_fluid_link.private.tooltip.disabled" )))
228+ .addTooltip (true , IKey .lang ("cover.ender_fluid_link.private.tooltip.enabled" ))
229+ .addTooltip (false , IKey .lang ("cover.ender_fluid_link.private.tooltip.disabled" ))
209230 .marginRight (2 );
210231 }
211232
212- protected IWidget createIoRow () {
233+ protected IWidget createIoRow (UUID uuid ) {
234+ BooleanSyncValue syncValue ;
235+ if (canAccess (uuid )) {
236+ syncValue = new BooleanSyncValue (this ::isIoEnabled , this ::setIoEnabled );
237+ } else {
238+ syncValue = new BooleanSyncValue (this ::isIoEnabled );
239+ }
213240 return Flow .row ().marginBottom (2 )
214241 .coverChildrenHeight ()
215242 .child (new ToggleButton ()
216- .value (new BooleanSyncValue ( this :: isIoEnabled , this :: setIoEnabled ) )
217- .overlay (IKey .lang (() -> this . ioEnabled ?
218- "behaviour.soft_hammer.enabled" :
219- "behaviour.soft_hammer.disabled" )
220- .color (Color .WHITE .darker ( 1 ) ))
243+ .value (syncValue )
244+ .overlay (true , IKey .lang ("behaviour.soft_hammer.enabled" )
245+ . color ( Color . WHITE . main ))
246+ . overlay ( false , IKey . lang ( "behaviour.soft_hammer.disabled" )
247+ .color (Color .WHITE .main ))
221248 .widthRel (0.6f )
222249 .left (0 ));
223250 }
@@ -253,13 +280,15 @@ private void setPrivate(boolean isPrivate) {
253280 @ Override
254281 public void writeInitialSyncData (PacketBuffer packetBuffer ) {
255282 packetBuffer .writeString (this .playerUUID == null ? "null" : this .playerUUID .toString ());
283+ packetBuffer .writeBoolean (this .isPrivate );
256284 }
257285
258286 @ Override
259287 public void readInitialSyncData (PacketBuffer packetBuffer ) {
260288 // does client even need uuid info? just in case
261289 String uuidStr = packetBuffer .readString (36 );
262290 this .playerUUID = uuidStr .equals ("null" ) ? null : UUID .fromString (uuidStr );
291+ this .isPrivate = packetBuffer .readBoolean ();
263292 }
264293
265294 @ Override
@@ -284,11 +313,11 @@ public void writeToNBT(@NotNull NBTTagCompound nbt) {
284313 nbt .setInteger ("Frequency" , activeEntry .getColor ());
285314 }
286315
287- protected PanelSyncHandler .IPanelBuilder entrySelector (EntryTypes <T > type ) {
316+ protected PanelSyncHandler .IPanelBuilder entrySelector (EntryTypes <T > type , UUID uuid ) {
288317 return (syncManager , syncHandler ) -> {
289318 List <IWidget > rows = new ArrayList <>();
290319 for (String name : VirtualEnderRegistry .getEntryNames (getOwner (), type )) {
291- rows .add (createRow (name , syncManager , type ));
320+ rows .add (createRow (name , syncManager , type , uuid ));
292321 }
293322 return GTGuis .createPopupPanel ("entry_selector" , 168 , 112 , true )
294323 .child (IKey .lang ("cover.generic.ender.known_channels" )
@@ -298,7 +327,6 @@ protected PanelSyncHandler.IPanelBuilder entrySelector(EntryTypes<T> type) {
298327 .left (4 ))
299328 .child (new ListWidget <>()
300329 .children (rows )
301- // .builder(names, name -> createRow(name, syncManager, type))
302330 .background (GTGuiTextures .DISPLAY .asIcon ()
303331 .width (168 - 8 )
304332 .height (112 - 20 ))
@@ -341,13 +369,15 @@ protected PanelSyncHandler.IPanelBuilder entryDescription(String key, T entry) {
341369 };
342370 }
343371
344- protected IWidget createRow (final String name , final PanelSyncManager syncManager , final EntryTypes <T > type ) {
345- final T entry = VirtualEnderRegistry .getEntry (getOwner (), type , name );
346- var key = String .format ("entry#%s_description" , entry .getColorStr ());
347- var syncKey = PanelSyncManager .makeSyncKey (key , isPrivate ? 1 : 0 );
348- final var panelHandler = (PanelSyncHandler ) syncManager .panel (syncKey ,
372+ protected IWidget createRow (String name , PanelSyncManager syncManager ,
373+ EntryTypes <T > type , UUID uuid ) {
374+ T entry = VirtualEnderRegistry .getEntry (getOwner (), type , name );
375+ String key = String .format ("entry#%s_description" , entry .getColorStr ());
376+ String syncKey = PanelSyncManager .makeSyncKey (key , isPrivate ? 1 : 0 );
377+ IPanelHandler panelHandler = syncManager .panel (syncKey ,
349378 entryDescription (key , entry ), true );
350- final var syncHandler = new EnderCoverSyncHandler ();
379+
380+ EnderCoverSyncHandler syncHandler = new EnderCoverSyncHandler ();
351381 syncManager .syncValue (key + "_handler" , syncHandler );
352382
353383 return Flow .row ()
@@ -363,8 +393,13 @@ protected IWidget createRow(final String name, final PanelSyncManager syncManage
363393 .size (16 )
364394 .background (GTGuiTextures .SLOT .asIcon ().size (18 ))
365395 .top (1 ))
366- .child (new InteractableText <>(entry , this ::updateColor )
367- .tooltip (tooltip -> tooltip .setAutoUpdate (true ))
396+ .child (new InteractableText <>(entry , str -> {
397+ if (canAccess (uuid )) {
398+ updateColor (str );
399+ return true ;
400+ }
401+ return false ;
402+ }).tooltipAutoUpdate (true )
368403 .tooltipBuilder (tooltip -> {
369404 String desc = entry .getDescription ();
370405 if (!desc .isEmpty ()) tooltip .add (desc );
@@ -377,6 +412,8 @@ protected IWidget createRow(final String name, final PanelSyncManager syncManage
377412 .overlay (GuiTextures .GEAR )
378413 .addTooltipLine (IKey .lang ("cover.generic.ender.set_description.tooltip" ))
379414 .onMousePressed (i -> {
415+ if (!canAccess (uuid )) return false ;
416+
380417 // open entry settings
381418 if (panelHandler .isPanelOpen ()) {
382419 panelHandler .closePanel ();
@@ -391,6 +428,8 @@ protected IWidget createRow(final String name, final PanelSyncManager syncManage
391428 .setEnabledIf (w -> !Objects .equals (entry .getColor (), activeEntry .getColor ()))
392429 .addTooltipLine (IKey .lang ("cover.generic.ender.delete_entry" ))
393430 .onMousePressed (i -> {
431+ if (!canAccess (uuid )) return false ;
432+
394433 // todo option to force delete, maybe as a popup?
395434 deleteEntry (getOwner (), name );
396435 syncHandler .syncToServer (1 , buffer -> {
0 commit comments