Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public Button(final Dialog dialog, final CompoundTag tag) {

for (final String event : CLICK_EVENTS) {
if (Key.stripMinecraftNamespace(type).equals(event)) {
clickEvent = actionTag;
clickEvent = actionTag.copy();
clickEvent.put("action", clickEvent.remove("type"));
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private void fillServerLinksDialog(final ServerLinks serverLinks, final Compound
}

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

ListTag<StringTag> registryDialogsTag = tag.getListTag("dialogs", StringTag.class);
StringTag registryDialogTag = tag.getStringTag("dialogs");
if (registryDialogTag != null) {
registryDialogsTag = new ListTag<>(StringTag.class);
registryDialogsTag.add(registryDialogTag);
}
if (registryDialogsTag != null) {
dialogsTag = new ListTag<>(CompoundTag.class);
final String key = registryDialogTag.getValue();
if (key.startsWith("#")) {
for (final CompoundTag entry : registryAndTags.fromRegistryKey(key.substring(1))) {
dialogsTag.add(entry);
for (final StringTag nameTag : registryDialogsTag) {
final String key = nameTag.getValue();
if (key.startsWith("#")) {
for (final CompoundTag entry : registryAndTags.fromRegistryKey(key.substring(1))) {
dialogsTag.add(entry);
}
} else {
dialogsTag.add(registryAndTags.fromRegistry(key));
}
} else {
dialogsTag.add(registryAndTags.fromRegistry(key));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,18 @@ public void openDialog(final UserConnection connection, final Dialog dialog) {
texts.add(textWidget.label());
dialog.widgets().remove(textWidget);
} else if (!texts.isEmpty()) {
// Flush collected texts before adding the non-text widget
dialog.widgets().add(dialog.widgets().indexOf(widget), new MultiTextWidget(texts.toArray(Tag[]::new)));
texts.clear();
}
}

// Flush remaining texts if any
if (!texts.isEmpty()) {
dialog.widgets().add(new MultiTextWidget(texts.toArray(Tag[]::new)));
texts.clear();
}

final ChestDialogStorage previousStorage = connection.get(ChestDialogStorage.class);
final ChestDialogStorage storage = new ChestDialogStorage(this, dialog);
if (previousStorage != null) {
Expand Down Expand Up @@ -210,8 +217,9 @@ public boolean clickDialog(final UserConnection connection, final int container,
}
}

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

protected Item getMultiTextWidget(final UserConnection connection, final MultiTextWidget multiTextWidget) {
final Tag name = handleTag(connection, multiTextWidget.labels()[0]);
final int length = multiTextWidget.labels().length;
if (length == 1) {
return createItem("minecraft:paper", name);
final List<Tag> lines = new ArrayList<>();
for (final Tag label : multiTextWidget.labels()) {
final Tag[] split = ChatUtil.split(fixStyle(label), "\n");
for (final Tag line : split) {
lines.add(handleTag(connection, line));
}
}

final Tag[] lore = new Tag[length - 1];
for (int i = 1; i < length; i++) {
lore[i - 1] = handleTag(connection, fixStyle(multiTextWidget.labels()[i]));
final Tag[] lore = new Tag[lines.size() - 1];
for (int i = 1; i < lines.size(); i++) {
lore[i - 1] = lines.get(i);
}
return createItem("minecraft:paper", name, lore);
return createItem("minecraft:paper", lines.get(0), lore);
}

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