Handle supported/primary items in registry data

Fixes ViaVersion/ViaBackwards#928
This commit is contained in:
Nassim Jahnke 2024-12-10 11:28:43 +01:00
parent 366675f7f8
commit f2456abd5b
No known key found for this signature in database
GPG Key ID: EF6771C01F6EF02F

View File

@ -108,7 +108,13 @@ public class RegistryDataRewriter {
continue; continue;
} }
final CompoundTag effects = ((CompoundTag) entry.tag()).getCompoundTag("effects"); final CompoundTag tag = (CompoundTag) entry.tag();
if (protocol.getMappingData().getFullItemMappings() != null) {
updateItemList(tag.getListTag("supported_items", StringTag.class));
updateItemList(tag.getListTag("primary_items", StringTag.class));
}
final CompoundTag effects = tag.getCompoundTag("effects");
if (effects == null) { if (effects == null) {
continue; continue;
} }
@ -118,8 +124,8 @@ public class RegistryDataRewriter {
if (effectEntry.getValue() instanceof final CompoundTag compoundTag) { if (effectEntry.getValue() instanceof final CompoundTag compoundTag) {
updateNestedEffect(compoundTag); updateNestedEffect(compoundTag);
} else if (effectEntry.getValue() instanceof final ListTag<?> listTag && listTag.getElementType() == CompoundTag.class) { } else if (effectEntry.getValue() instanceof final ListTag<?> listTag && listTag.getElementType() == CompoundTag.class) {
for (final Tag tag : listTag) { for (final Tag effectTag : listTag) {
updateNestedEffect((CompoundTag) tag); updateNestedEffect((CompoundTag) effectTag);
} }
} }
} }
@ -210,4 +216,20 @@ public class RegistryDataRewriter {
private boolean hasAttributeMappings() { private boolean hasAttributeMappings() {
return protocol.getMappingData() != null && protocol.getMappingData().getAttributeMappings() != null; return protocol.getMappingData() != null && protocol.getMappingData().getAttributeMappings() != null;
} }
private void updateItemList(final ListTag<StringTag> listTag) {
if (listTag == null) {
return;
}
for (final StringTag tag : listTag) {
updateItem(tag);
}
}
private void updateItem(final StringTag tag) {
final String mapped = protocol.getMappingData().getFullItemMappings().mappedIdentifier(tag.getValue());
if (mapped != null) {
tag.setValue(mapped);
}
}
} }