@@ -73,6 +73,7 @@ public final class WaypointEditScreen extends Screen
7373 private Button iconButton ;
7474
7575 private Button oppositeButton ;
76+ private boolean addOppositeOnSave ;
7677 private Button visibleButton ;
7778 private Button linesButton ;
7879 private Button beaconButton ;
@@ -172,17 +173,13 @@ protected void init()
172173 yToggles = y ;
173174 int halfGap = 10 ;
174175 int halfW = (cw - halfGap ) / 2 ;
175- oppositeButton =
176- Button
177- .builder (
178- Component .literal (
179- buttonLabel ("Opposite" , waypoint .isOpposite ())),
180- b -> {
181- waypoint .setOpposite (!waypoint .isOpposite ());
182- b .setMessage (Component .literal (buttonLabel (
183- "Opposite" , waypoint .isOpposite ())));
184- })
185- .bounds (x , y , halfW , 20 ).build ();
176+ oppositeButton = Button .builder (
177+ Component .literal (buttonLabel ("Opposite" , addOppositeOnSave )),
178+ b -> {
179+ addOppositeOnSave = !addOppositeOnSave ;
180+ b .setMessage (Component
181+ .literal (buttonLabel ("Opposite" , addOppositeOnSave )));
182+ }).bounds (x , y , halfW , 20 ).build ();
186183 addRenderableWidget (oppositeButton );
187184
188185 visibleButton = Button .builder (
@@ -196,7 +193,7 @@ protected void init()
196193 y += 28 ;
197194
198195 // Reserve space for opposite preview text, then Lines/Beacon row
199- y += 16 ;
196+ y += 28 ;
200197 int toggleWidth = (cw - halfGap ) / 2 ;
201198 linesButton = Button .builder (
202199 Component .literal (buttonLabel ("Lines" , waypoint .isLines ())),
@@ -410,6 +407,11 @@ private void saveAndBack()
410407 manager .addOrUpdate (waypoint );
411408 if (listScreen != null )
412409 listScreen .saveNow ();
410+
411+ // Create opposite-dimension waypoint if toggle was enabled
412+ if (addOppositeOnSave )
413+ createOppositeWaypoint ();
414+
413415 minecraft .setScreen (prev );
414416 }
415417
@@ -496,18 +498,16 @@ public void extractRenderState(GuiGraphicsExtractor context, int mouseX,
496498 CommonColors .GRAY );
497499 context .fill (boxX , boxY , boxX + 16 , boxY + 16 , color );
498500
499- // Opposite preview text – render below the toggles and lines rows
501+ // Opposite preview text – render below the toggles row with spacing
500502 String opp = oppositePreview ();
501503 if (!opp .isEmpty ())
502504 context .text (minecraft .font , opp , fieldsBaseX ,
503- /* directly below the opposite/visible row */
504- yToggles + 28 + 8 , 0xFFCCCCCC , false );
505+ /* below the opposite/visible row with extra gap */
506+ yToggles + 28 + 12 , 0xFFCCCCCC , false );
505507 }
506508
507509 private String oppositePreview ()
508510 {
509- if (!waypoint .isOpposite ())
510- return "" ;
511511 WaypointDimension d = WaypointDimension .values ()[dimIndex ];
512512 if (d == WaypointDimension .END )
513513 return "Opposite has no effect in the End" ;
@@ -530,11 +530,52 @@ private String oppositePreview()
530530 oz = z * 8 ;
531531 td = WaypointDimension .OVERWORLD ;
532532 }
533- return "Opposite shows in " + td .name () + " at (" + ox + ", " + y
534- + ", " + oz + ")" ;
533+ return "Opposite (" + td .name () + "): " + ox + ", " + y + ", " + oz ;
535534 }catch (Exception e )
536535 {
537536 return "" ;
538537 }
539538 }
539+
540+ private void createOppositeWaypoint ()
541+ {
542+ WaypointDimension d = WaypointDimension .values ()[dimIndex ];
543+ if (d == WaypointDimension .END )
544+ return ;
545+ try
546+ {
547+ int x = Integer .parseInt (xField .getValue ());
548+ int y = Integer .parseInt (yField .getValue ());
549+ int z = Integer .parseInt (zField .getValue ());
550+ int ox , oz ;
551+ WaypointDimension td ;
552+ if (d == WaypointDimension .OVERWORLD )
553+ {
554+ ox = Math .floorDiv (x , 8 );
555+ oz = Math .floorDiv (z , 8 );
556+ td = WaypointDimension .NETHER ;
557+ }else
558+ {
559+ ox = x * 8 ;
560+ oz = z * 8 ;
561+ td = WaypointDimension .OVERWORLD ;
562+ }
563+ Waypoint opposite = new Waypoint (java .util .UUID .randomUUID (),
564+ System .currentTimeMillis ());
565+ opposite .setName (nameField .getValue ());
566+ opposite .setPos (new BlockPos (ox , y , oz ));
567+ opposite .setDimension (td );
568+ opposite .setIcon (ICON_KEYS [iconIndex ]);
569+ opposite .setColor (colorSetting .getColorI ((int )Math .round (
570+ Math .max (1 , Math .min (100 , alphaPercent )) / 100.0 * 255 )));
571+ opposite .setVisible (waypoint .isVisible ());
572+ opposite .setLines (waypoint .isLines ());
573+ opposite .setBeaconMode (waypoint .getBeaconMode ());
574+ opposite .setOpposite (false );
575+ manager .addOrUpdate (opposite );
576+ if (listScreen != null )
577+ listScreen .saveNow ();
578+ }catch (Exception ignored )
579+ {}
580+ }
540581}
0 commit comments