Handle attribute_modifiers inside container components in 1.21->1.20.5 (#829)

This commit is contained in:
EnZaXD 2024-07-24 14:33:56 +02:00 committed by GitHub
parent 136678b0b7
commit 1413bd63ef
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -37,10 +37,11 @@ public final class ComponentRewriter1_21 extends TranslatableRewriter<Clientboun
super(protocol, ReadType.NBT); super(protocol, ReadType.NBT);
} }
@Override private void convertAttributeModifiersComponent(final CompoundTag tag) {
protected void handleShowItem(final UserConnection connection, final CompoundTag componentsTag) { final CompoundTag attributeModifiers = TagUtil.getNamespacedCompoundTag(tag, "attribute_modifiers");
final CompoundTag attributeModifiers = TagUtil.getNamespacedCompoundTag(componentsTag, "attribute_modifiers"); if (attributeModifiers == null) {
if (attributeModifiers != null) { return;
}
final ListTag<CompoundTag> modifiers = attributeModifiers.getListTag("modifiers", CompoundTag.class); final ListTag<CompoundTag> modifiers = attributeModifiers.getListTag("modifiers", CompoundTag.class);
for (final CompoundTag modifier : modifiers) { for (final CompoundTag modifier : modifiers) {
final String id = modifier.getString("id"); final String id = modifier.getString("id");
@ -51,6 +52,27 @@ public final class ComponentRewriter1_21 extends TranslatableRewriter<Clientboun
} }
} }
private void handleContainerComponent(final CompoundTag tag) {
final ListTag<CompoundTag> container = TagUtil.getNamespacedCompoundTagList(tag, "container");
if (container == null) {
return;
}
for (final CompoundTag entryTag : container) {
final CompoundTag itemTag = entryTag.getCompoundTag("item");
final CompoundTag componentsTag = itemTag.getCompoundTag("components");
if (componentsTag != null) {
convertAttributeModifiersComponent(componentsTag);
handleContainerComponent(componentsTag);
}
}
}
@Override
protected void handleShowItem(final UserConnection connection, final CompoundTag componentsTag) {
convertAttributeModifiersComponent(componentsTag);
handleContainerComponent(componentsTag);
TagUtil.removeNamespaced(componentsTag, "jukebox_playable"); TagUtil.removeNamespaced(componentsTag, "jukebox_playable");
} }