Skip to content

Commit fd16c44

Browse files
Add option to disable dialog handling in 1.21.6->1.21.5 (#1116)
1 parent a37605e commit fd16c44

File tree

5 files changed

+35
-3
lines changed

5 files changed

+35
-3
lines changed

common/src/main/java/com/viaversion/viabackwards/ViaBackwardsConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public class ViaBackwardsConfig extends Config implements com.viaversion.viaback
4444
private boolean mapCustomModelData;
4545
private boolean mapDisplayEntities;
4646
private boolean suppressEmulationWarnings;
47+
private boolean dialogsViaChests;
4748
private DialogStyleConfig dialogStyleConfig;
4849

4950
public ViaBackwardsConfig(File configFile, Logger logger) {
@@ -70,6 +71,7 @@ private void loadFields() {
7071
mapCustomModelData = getBoolean("map-custom-model-data", true);
7172
mapDisplayEntities = getBoolean("map-display-entities", true);
7273
suppressEmulationWarnings = getBoolean("suppress-emulation-warnings", false);
74+
dialogsViaChests = getBoolean("dialogs-via-chests", true);
7375
dialogStyleConfig = loadDialogStyleConfig(getSection("dialog-style"));
7476
}
7577

@@ -160,6 +162,11 @@ public boolean suppressEmulationWarnings() {
160162
return suppressEmulationWarnings;
161163
}
162164

165+
@Override
166+
public boolean dialogsViaChests() {
167+
return dialogsViaChests;
168+
}
169+
163170
@Override
164171
public DialogStyleConfig dialogStyleConfig() {
165172
return dialogStyleConfig;

common/src/main/java/com/viaversion/viabackwards/api/ViaBackwardsConfig.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,13 @@ public interface ViaBackwardsConfig extends Config {
113113
*/
114114
boolean suppressEmulationWarnings();
115115

116+
/**
117+
* If enabled, dialogs will be shown via chest inventories for 1.21.5 clients on 1.21.6+ servers.
118+
*
119+
* @return true if enabled
120+
*/
121+
boolean dialogsViaChests();
122+
116123
/**
117124
* Returns the dialog style configuration.
118125
*

common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/Protocol1_21_6To1_21_5.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.viaversion.nbt.tag.CompoundTag;
2121
import com.viaversion.nbt.tag.Tag;
22+
import com.viaversion.viabackwards.ViaBackwards;
2223
import com.viaversion.viabackwards.api.BackwardsProtocol;
2324
import com.viaversion.viabackwards.api.data.BackwardsMappingData;
2425
import com.viaversion.viabackwards.api.rewriters.SoundRewriter;
@@ -149,10 +150,15 @@ public void handleArgument(final PacketWrapper wrapper, final String argumentTyp
149150
final short difficulty = wrapper.read(Types.UNSIGNED_BYTE);
150151
wrapper.write(Types.VAR_INT, (int) difficulty);
151152
});
153+
registerServerbound(ServerboundPackets1_21_5.CHAT_COMMAND, this::handleClickEvents);
154+
registerServerbound(ServerboundPackets1_21_5.CHAT_COMMAND_SIGNED, this::handleClickEvents);
152155

153156
// Are you sure you want to see this? This is your last chance to turn back.
154157
registerClientbound(ClientboundPackets1_21_6.SHOW_DIALOG, null, wrapper -> {
155158
wrapper.cancel();
159+
if (!ViaBackwards.getConfig().dialogsViaChests()) {
160+
return;
161+
}
156162

157163
final RegistryAndTags registryAndTags = wrapper.user().get(RegistryAndTags.class);
158164
final ServerLinks serverLinks = wrapper.user().get(ServerLinks.class);
@@ -169,6 +175,9 @@ public void handleArgument(final PacketWrapper wrapper, final String argumentTyp
169175
});
170176
registerClientbound(ClientboundConfigurationPackets1_21_6.SHOW_DIALOG, null, wrapper -> {
171177
wrapper.cancel();
178+
if (!ViaBackwards.getConfig().dialogsViaChests()) {
179+
return;
180+
}
172181

173182
final RegistryAndTags registryAndTags = wrapper.user().get(RegistryAndTags.class);
174183
final ServerLinks serverLinks = wrapper.user().get(ServerLinks.class);
@@ -183,9 +192,6 @@ public void handleArgument(final PacketWrapper wrapper, final String argumentTyp
183192
registerClientbound(ClientboundPackets1_21_6.SERVER_LINKS, this::storeServerLinks);
184193
registerClientbound(ClientboundConfigurationPackets1_21_6.SERVER_LINKS, this::storeServerLinks);
185194

186-
registerServerbound(ServerboundPackets1_21_5.CHAT_COMMAND, this::handleClickEvents);
187-
registerServerbound(ServerboundPackets1_21_5.CHAT_COMMAND_SIGNED, this::handleClickEvents);
188-
189195
// The ones below are specific to the chest dialog view provider
190196
registerServerbound(ServerboundPackets1_21_5.CONTAINER_CLOSE, wrapper -> {
191197
final ChestDialogStorage storage = wrapper.user().get(ChestDialogStorage.class);
@@ -290,6 +296,10 @@ private void updateTags(final PacketWrapper wrapper) {
290296

291297
private void clearDialog(final PacketWrapper wrapper) {
292298
wrapper.cancel();
299+
if (!ViaBackwards.getConfig().dialogsViaChests()) {
300+
return;
301+
}
302+
293303
final DialogViewProvider provider = Via.getManager().getProviders().get(DialogViewProvider.class);
294304
provider.closeDialog(wrapper.user());
295305
}

common/src/main/java/com/viaversion/viabackwards/protocol/v1_21_6to1_21_5/storage/ClickEvents.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import com.viaversion.nbt.tag.CompoundTag;
2121
import com.viaversion.nbt.tag.StringTag;
22+
import com.viaversion.viabackwards.ViaBackwards;
2223
import com.viaversion.viabackwards.protocol.v1_21_6to1_21_5.Protocol1_21_6To1_21_5;
2324
import com.viaversion.viabackwards.protocol.v1_21_6to1_21_5.data.Dialog;
2425
import com.viaversion.viabackwards.protocol.v1_21_6to1_21_5.provider.DialogViewProvider;
@@ -59,6 +60,10 @@ public boolean handleChatCommand(final UserConnection connection, final String c
5960
public static void handleClickEvent(final UserConnection connection, final CompoundTag clickEvent) {
6061
final String action = Key.stripMinecraftNamespace(clickEvent.getString("action"));
6162
if ("show_dialog".equals(action)) {
63+
if (!ViaBackwards.getConfig().dialogsViaChests()) {
64+
return;
65+
}
66+
6267
final RegistryAndTags registryAndTags = connection.get(RegistryAndTags.class);
6368
final ServerLinks serverLinks = connection.get(ServerLinks.class);
6469

common/src/main/resources/assets/viabackwards/config.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,9 @@ map-display-entities: true
4545
# Suppresses warnings of missing emulations for certain features that are not supported (e.g. world height in 1.17+).
4646
suppress-emulation-warnings: false
4747
#
48+
# If enabled, dialogs will be shown via chest inventories for 1.21.5 clients on 1.21.6+ servers.
49+
dialogs-via-chests: true
50+
#
4851
# Dialog styling. You can also use translation keys here.
4952
dialog-style:
5053
page-navigation-title: "&9&lPage navigation"

0 commit comments

Comments
 (0)