49
49
import java .util .List ;
50
50
import org .checkerframework .checker .nullness .qual .Nullable ;
51
51
52
+ import static com .viaversion .viabackwards .utils .ChatUtil .fixStyle ;
52
53
import static com .viaversion .viabackwards .utils .ChatUtil .text ;
53
54
import static com .viaversion .viabackwards .utils .ChatUtil .translate ;
54
55
@@ -74,6 +75,18 @@ public void openDialog(final UserConnection connection, final Dialog dialog) {
74
75
return ;
75
76
}
76
77
78
+ // Batch text widgets following one another into a single MultiTextWidget to be display properly.
79
+ final List <Tag > texts = new ArrayList <>();
80
+ for (final Widget widget : new ArrayList <>(dialog .widgets ())) {
81
+ if (widget instanceof final TextWidget textWidget ) {
82
+ texts .add (textWidget .label ());
83
+ dialog .widgets ().remove (textWidget );
84
+ } else if (!texts .isEmpty ()) {
85
+ dialog .widgets ().add (dialog .widgets ().indexOf (widget ), new MultiTextWidget (texts .toArray (Tag []::new )));
86
+ texts .clear ();
87
+ }
88
+ }
89
+
77
90
final ChestDialogStorage previousStorage = connection .get (ChestDialogStorage .class );
78
91
final ChestDialogStorage storage = new ChestDialogStorage (this , dialog );
79
92
if (previousStorage != null ) {
@@ -252,8 +265,18 @@ protected Item getItemWidget(final ItemWidget itemWidget) {
252
265
return item ;
253
266
}
254
267
255
- protected Item getTextWidget (final UserConnection connection , final TextWidget textWidget ) {
256
- return createItem ("minecraft:paper" , handleTag (connection , textWidget .label ()));
268
+ protected Item getMultiTextWidget (final UserConnection connection , final MultiTextWidget multiTextWidget ) {
269
+ final Tag name = handleTag (connection , multiTextWidget .labels ()[0 ]);
270
+ final int length = multiTextWidget .labels ().length ;
271
+ if (length == 1 ) {
272
+ return createItem ("minecraft:paper" , name );
273
+ }
274
+
275
+ final Tag [] lore = new Tag [length - 1 ];
276
+ for (int i = 1 ; i < length ; i ++) {
277
+ lore [i - 1 ] = fixStyle (handleTag (connection , multiTextWidget .labels ()[i ]));
278
+ }
279
+ return createItem ("minecraft:paper" , name , lore );
257
280
}
258
281
259
282
protected Item getBooleanInput (final UserConnection connection , final BooleanInput booleanInput ) {
@@ -270,7 +293,7 @@ protected Item getBooleanInput(final UserConnection connection, final BooleanInp
270
293
} else {
271
294
final Tag [] lore = new Tag [label .length ];
272
295
for (int i = 1 ; i < label .length ; i ++) {
273
- lore [i - 1 ] = ChatUtil . fixStyle (handleTag (connection , label [i ]));
296
+ lore [i - 1 ] = fixStyle (handleTag (connection , label [i ]));
274
297
}
275
298
lore [lore .length - 1 ] = text ("§9Left click: §6Toggle value" );
276
299
return createItem (
@@ -445,8 +468,8 @@ protected void clickDialogButton(final UserConnection connection, final Dialog d
445
468
protected Item getItem (final UserConnection connection , final Widget widget ) {
446
469
if (widget instanceof final ItemWidget itemWidget ) {
447
470
return getItemWidget (itemWidget );
448
- } else if (widget instanceof final TextWidget textWidget ) {
449
- return getTextWidget (connection , textWidget );
471
+ } else if (widget instanceof final MultiTextWidget multiTextWidget ) {
472
+ return getMultiTextWidget (connection , multiTextWidget );
450
473
} else if (widget instanceof final BooleanInput booleanInput ) {
451
474
return getBooleanInput (connection , booleanInput );
452
475
} else if (widget instanceof final NumberRangeInput numberRangeInput ) {
@@ -529,6 +552,14 @@ protected Item[] getItems(final UserConnection connection, final ChestDialogStor
529
552
return tag ;
530
553
}
531
554
555
+ /**
556
+ * This doesn't actually exist in Minecraft but is created if multiple {@link TextWidget} follow one another in order
557
+ * to improve readability in chest inventories.
558
+ */
559
+ public record MultiTextWidget (Tag [] labels ) implements Widget {
560
+
561
+ }
562
+
532
563
// -------------------------------------------------------------------------------------
533
564
534
565
protected Item createItem (final String identifier , final Tag name ) {
0 commit comments