Move VV specific item handling out of component<->nbt conversion in 1.20.3->1.20.5 (#4094)

The current code backups the tag in CUSTOM_DATA inside the toStructuredItem function which in VB is used for to server packets which causes bad data, this PR moves the backup logic out to the VV specific handler and also prevents toOldItem logic for using the backup to ever get executed in VB. The counterpart PR will add proper handling for CUSTOM_DATA.

Fixes https://github.com/ViaVersion/ViaVersion/issues/4092
This commit is contained in:
EnZaXD 2024-08-14 09:31:27 +02:00 committed by GitHub
parent fcd91bb855
commit 1b03e24160
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -376,13 +376,15 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
return StructuredItem.empty();
}
// Add the original as custom data, to be re-used for creative clients as well
final CompoundTag tag = item.tag();
final Item structuredItem = toStructuredItem(connection, item);
// Add the original as custom data, to be re-used for creative clients as well
if (tag != null) {
tag.putBoolean(nbtTagName(), true);
structuredItem.dataContainer().set(StructuredDataKey.CUSTOM_DATA, tag);
}
final Item structuredItem = toStructuredItem(connection, item);
// Add data components to fix issues in older protocols
appendItemDataFixComponents(connection, structuredItem);
@ -415,7 +417,8 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
final StructuredData<CompoundTag> customData = data.getNonEmpty(StructuredDataKey.CUSTOM_DATA);
final CompoundTag tag = customData != null ? customData.value() : new CompoundTag();
final DataItem dataItem = new DataItem(item.identifier(), (byte) item.amount(), tag);
if (customData != null && tag.remove(nbtTagName()) != null) {
if (!dataConverter.backupInconvertibleData() && customData != null && tag.remove(nbtTagName()) != null) {
// Skip for VB since it's used for incoming item data
return dataItem;
}
@ -605,8 +608,6 @@ public final class BlockItemPacketRewriter1_20_5 extends ItemRewriter<Clientboun
// Restore original data components
restoreFromBackupTag(backupTag, data);
}
data.set(StructuredDataKey.CUSTOM_DATA, tag);
return item;
}