Skip to content

Commit 0a5035d

Browse files
More dialog emulation fixes (#1131)
Co-authored-by: FlorianMichael <florian.michael07@gmail.com>
1 parent 609b657 commit 0a5035d

File tree

3 files changed

+35
-18
lines changed

3 files changed

+35
-18
lines changed

common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/data/Button.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public Button(final Dialog dialog, final CompoundTag tag) {
7474

7575
for (final String event : CLICK_EVENTS) {
7676
if (Key.stripMinecraftNamespace(type).equals(event)) {
77-
clickEvent = actionTag;
77+
clickEvent = actionTag.copy();
7878
clickEvent.put("action", clickEvent.remove("type"));
7979
return;
8080
}

common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/data/Dialog.java

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ private void fillServerLinksDialog(final ServerLinks serverLinks, final Compound
150150
}
151151

152152
private void fillDialogList(final RegistryAndTags registryAndTags, final ServerLinks serverLinks, final CompoundTag tag) {
153-
// Hold them as either a list of inlined, a singleton inlined, a registry entry or a tag.
153+
// Hold them as either a list of inlined / singleton inlined, a list of registry entries / singleton entry or a tag.
154154
ListTag<CompoundTag> dialogsTag = tag.getListTag("dialogs", CompoundTag.class);
155155
if (dialogsTag == null) {
156156
CompoundTag dialogTag = tag.getCompoundTag("dialogs");
@@ -159,16 +159,23 @@ private void fillDialogList(final RegistryAndTags registryAndTags, final ServerL
159159
dialogsTag.add(dialogTag);
160160
}
161161

162+
ListTag<StringTag> registryDialogsTag = tag.getListTag("dialogs", StringTag.class);
162163
StringTag registryDialogTag = tag.getStringTag("dialogs");
163164
if (registryDialogTag != null) {
165+
registryDialogsTag = new ListTag<>(StringTag.class);
166+
registryDialogsTag.add(registryDialogTag);
167+
}
168+
if (registryDialogsTag != null) {
164169
dialogsTag = new ListTag<>(CompoundTag.class);
165-
final String key = registryDialogTag.getValue();
166-
if (key.startsWith("#")) {
167-
for (final CompoundTag entry : registryAndTags.fromRegistryKey(key.substring(1))) {
168-
dialogsTag.add(entry);
170+
for (final StringTag nameTag : registryDialogsTag) {
171+
final String key = nameTag.getValue();
172+
if (key.startsWith("#")) {
173+
for (final CompoundTag entry : registryAndTags.fromRegistryKey(key.substring(1))) {
174+
dialogsTag.add(entry);
175+
}
176+
} else {
177+
dialogsTag.add(registryAndTags.fromRegistry(key));
169178
}
170-
} else {
171-
dialogsTag.add(registryAndTags.fromRegistry(key));
172179
}
173180
}
174181
}

common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/provider/ChestDialogViewProvider.java

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,18 @@ public void openDialog(final UserConnection connection, final Dialog dialog) {
8585
texts.add(textWidget.label());
8686
dialog.widgets().remove(textWidget);
8787
} else if (!texts.isEmpty()) {
88+
// Flush collected texts before adding the non-text widget
8889
dialog.widgets().add(dialog.widgets().indexOf(widget), new MultiTextWidget(texts.toArray(Tag[]::new)));
8990
texts.clear();
9091
}
9192
}
9293

94+
// Flush remaining texts if any
95+
if (!texts.isEmpty()) {
96+
dialog.widgets().add(new MultiTextWidget(texts.toArray(Tag[]::new)));
97+
texts.clear();
98+
}
99+
93100
final ChestDialogStorage previousStorage = connection.get(ChestDialogStorage.class);
94101
final ChestDialogStorage storage = new ChestDialogStorage(this, dialog);
95102
if (previousStorage != null) {
@@ -210,8 +217,9 @@ public boolean clickDialog(final UserConnection connection, final int container,
210217
}
211218
}
212219

213-
// Resync inventory view if the actions above didn't close the dialog.
214-
if (connection.has(ChestDialogStorage.class) && storage.phase() == ChestDialogStorage.Phase.DIALOG_VIEW) {
220+
// Resync inventory view if the actions above didn't close the dialog nor opened another one.
221+
final ChestDialogStorage currentStorage = connection.get(ChestDialogStorage.class);
222+
if (currentStorage == storage && connection.has(ChestDialogStorage.class) && storage.phase() == ChestDialogStorage.Phase.DIALOG_VIEW) {
215223
updateDialog(connection, storage.dialog());
216224
}
217225
return true;
@@ -274,17 +282,19 @@ protected Item getItemWidget(final UserConnection connection, final ItemWidget i
274282
}
275283

276284
protected Item getMultiTextWidget(final UserConnection connection, final MultiTextWidget multiTextWidget) {
277-
final Tag name = handleTag(connection, multiTextWidget.labels()[0]);
278-
final int length = multiTextWidget.labels().length;
279-
if (length == 1) {
280-
return createItem("minecraft:paper", name);
285+
final List<Tag> lines = new ArrayList<>();
286+
for (final Tag label : multiTextWidget.labels()) {
287+
final Tag[] split = ChatUtil.split(fixStyle(label), "\n");
288+
for (final Tag line : split) {
289+
lines.add(handleTag(connection, line));
290+
}
281291
}
282292

283-
final Tag[] lore = new Tag[length - 1];
284-
for (int i = 1; i < length; i++) {
285-
lore[i - 1] = handleTag(connection, fixStyle(multiTextWidget.labels()[i]));
293+
final Tag[] lore = new Tag[lines.size() - 1];
294+
for (int i = 1; i < lines.size(); i++) {
295+
lore[i - 1] = lines.get(i);
286296
}
287-
return createItem("minecraft:paper", name, lore);
297+
return createItem("minecraft:paper", lines.get(0), lore);
288298
}
289299

290300
protected Item getBooleanInput(final UserConnection connection, final BooleanInput booleanInput) {

0 commit comments

Comments
 (0)