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 @@ -93,6 +93,9 @@ public Protocol1_21_6To1_21_5() {
protected void registerPackets() {
super.registerPackets();

replaceClientbound(ClientboundPackets1_21_6.UPDATE_TAGS, this::updateTags);
replaceClientbound(ClientboundConfigurationPackets1_21_6.UPDATE_TAGS, this::updateTags);

appendClientbound(ClientboundPackets1_21_6.SOUND, wrapper -> {
wrapper.passthrough(Types.VAR_INT); // Source
fixSoundSource(wrapper);
Expand Down Expand Up @@ -238,34 +241,24 @@ private void fixSoundSource(final PacketWrapper wrapper) {
}

private void updateTags(final PacketWrapper wrapper) {
tagRewriter.handleGeneric(wrapper);
wrapper.resetReader();

// Store dialog tags; then call the normal rewriter which will remove them before sending to the client
final RegistryAndTags registryAndTags = wrapper.user().get(RegistryAndTags.class);
final int length = wrapper.passthrough(Types.VAR_INT);
for (int i = 0; i < length; i++) {
final String registryKey = wrapper.read(Types.STRING);
final String registryKey = wrapper.passthrough(Types.STRING);
final boolean dialog = "dialog".equals(Key.stripMinecraftNamespace(registryKey));
if (dialog) {
final int tagsSize = wrapper.read(Types.VAR_INT);
for (int j = 0; j < tagsSize; j++) {
final String key = wrapper.read(Types.STRING);
final int[] ids = wrapper.read(Types.VAR_INT_ARRAY_PRIMITIVE);
final int tagsSize = wrapper.passthrough(Types.VAR_INT);
for (int j = 0; j < tagsSize; j++) {
final String key = wrapper.passthrough(Types.STRING);
final int[] ids = wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE);
if (dialog) {
registryAndTags.storeTags(key, ids);
}
} else {
wrapper.write(Types.STRING, registryKey); // Write back
final int tagsSize = wrapper.passthrough(Types.VAR_INT);
for (int j = 0; j < tagsSize; j++) {
wrapper.passthrough(Types.STRING);
wrapper.passthrough(Types.VAR_INT_ARRAY_PRIMITIVE);
}
}
}

if (registryAndTags.tagsSent()) {
wrapper.set(Types.VAR_INT, 0, length - 1); // Dialog tags have been read, remove from size
}
wrapper.resetReader();
tagRewriter.handleGeneric(wrapper);
}

private void clearDialog(final PacketWrapper wrapper) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,23 +44,15 @@ public CompoundTag fromRegistry(final String key) {
return dialogs.get(Key.stripMinecraftNamespace(key));
}

public boolean tagsSent() {
return dialogTags != null && !dialogTags.isEmpty();
}

public void storeTags(final String key, final int[] ids) {
if (dialogTags == null) {
dialogTags = new Object2ObjectArrayMap<>();
}
dialogTags.put(Key.stripMinecraftNamespace(key), ids);
}

public int[] fromKey(final String key) {
return dialogTags.get(Key.stripMinecraftNamespace(key));
}

public CompoundTag[] fromRegistryKey(final String key) {
final int[] ids = fromKey(key);
final int[] ids = dialogTags.get(Key.stripMinecraftNamespace(key));
if (ids == null) {
return null;
}
Expand Down