3
0
Mirror von https://github.com/ViaVersion/ViaVersion.git synchronisiert 2024-11-16 04:50:08 +01:00

Hotfix item id changes in item hover events

Dieser Commit ist enthalten in:
Nassim Jahnke 2024-08-07 17:36:42 +02:00
Ursprung 274f98c24e
Commit cc1c88001f
Es konnte kein GPG-Schlüssel zu dieser Signatur gefunden werden
GPG-Schlüssel-ID: EF6771C01F6EF02F
2 geänderte Dateien mit 40 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -48,26 +48,12 @@ public final class ComponentRewriter1_21 extends ComponentRewriter<ClientboundPa
} }
} }
private void handleContainerComponent(final CompoundTag tag) {
final ListTag<CompoundTag> container = TagUtil.getNamespacedCompoundTagList(tag, "minecraft: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 @Override
protected void handleShowItem(final UserConnection connection, final CompoundTag componentsTag) { protected void handleShowItem(final UserConnection connection, final CompoundTag itemTag, final CompoundTag componentsTag) {
convertAttributeModifiersComponent(componentsTag); super.handleShowItem(connection, itemTag, componentsTag);
handleContainerComponent(componentsTag); if (componentsTag != null) {
convertAttributeModifiersComponent(componentsTag);
}
} }
@Override @Override

Datei anzeigen

@ -38,6 +38,7 @@ import com.viaversion.viaversion.api.type.Types;
import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets; import com.viaversion.viaversion.protocols.base.ClientboundLoginPackets;
import com.viaversion.viaversion.util.ComponentUtil; import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.SerializerVersion; import com.viaversion.viaversion.util.SerializerVersion;
import com.viaversion.viaversion.util.TagUtil;
import org.checkerframework.checker.nullness.qual.Nullable; import org.checkerframework.checker.nullness.qual.Nullable;
/** /**
@ -316,15 +317,46 @@ public class ComponentRewriter<C extends ClientboundPacketType> implements com.v
return; return;
} }
// Until they're properly parsed
final CompoundTag componentsTag = contentsTag.getCompoundTag("components"); final CompoundTag componentsTag = contentsTag.getCompoundTag("components");
handleShowItem(connection, contentsTag, componentsTag);
if (componentsTag != null) { if (componentsTag != null) {
handleShowItem(connection, componentsTag); handleContainerContents(connection, componentsTag);
handleItemArrayContents(connection, componentsTag, "bundle_contents");
handleItemArrayContents(connection, componentsTag, "charged_projectiles");
} }
} }
} }
protected void handleShowItem(final UserConnection connection, final CompoundTag componentsTag) { protected void handleShowItem(final UserConnection connection, final CompoundTag itemTag, @Nullable final CompoundTag componentsTag) {
// To override if needed final StringTag idTag = itemTag.getStringTag("id");
final String mappedId = protocol.getMappingData().getFullItemMappings().mappedIdentifier(idTag.getValue());
if (mappedId != null) {
idTag.setValue(mappedId);
}
}
protected void handleContainerContents(final UserConnection connection, final CompoundTag tag) {
final ListTag<CompoundTag> container = TagUtil.getNamespacedCompoundTagList(tag, "minecraft:container");
if (container == null) {
return;
}
for (final CompoundTag entryTag : container) {
final CompoundTag itemTag = entryTag.getCompoundTag("item");
handleShowItem(connection, itemTag, itemTag.getCompoundTag("components"));
}
}
protected void handleItemArrayContents(final UserConnection connection, final CompoundTag tag, final String key) {
final ListTag<CompoundTag> container = TagUtil.getNamespacedCompoundTagList(tag, key);
if (container == null) {
return;
}
for (final CompoundTag itemTag : container) {
handleShowItem(connection, itemTag, itemTag.getCompoundTag("components"));
}
} }
protected SerializerVersion inputSerializerVersion() { protected SerializerVersion inputSerializerVersion() {