Handle legacy item hover events

Co-authored-by: RaphiMC <50594595+raphimc@users.noreply.github.com>
This commit is contained in:
FlorianMichael 2024-04-13 21:01:34 +02:00
parent 287678c12a
commit 4e25549682
No known key found for this signature in database
GPG Key ID: C2FB87E71C425126
2 changed files with 17 additions and 0 deletions

View File

@ -78,6 +78,7 @@ import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Enchantme
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.PotionEffects1_20_5;
import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.Potions1_20_5;
import com.viaversion.viaversion.rewriter.ComponentRewriter;
import com.viaversion.viaversion.util.ComponentUtil;
import com.viaversion.viaversion.util.Either;
import com.viaversion.viaversion.util.Key;
import com.viaversion.viaversion.util.SerializerVersion;
@ -163,6 +164,18 @@ public class ComponentRewriter1_20_5 extends ComponentRewriter<ClientboundPacket
return;
}
final Tag valueTag = hoverEventTag.remove("value");
if (valueTag != null) { // Convert legacy hover event to new format for rewriting
final CompoundTag tag = ComponentUtil.deserializeShowItem(valueTag, SerializerVersion.V1_20_3);
final CompoundTag contentsTag = new CompoundTag();
contentsTag.put("id", tag.getStringTag("id"));
contentsTag.put("count", new IntTag(tag.getByte("Count")));
if (tag.get("tag") instanceof CompoundTag) {
contentsTag.put("tag", new StringTag(SerializerVersion.V1_20_3.toSNBT(tag.getCompoundTag("tag"))));
}
hoverEventTag.put("contents", contentsTag);
}
final CompoundTag contentsTag = hoverEventTag.getCompoundTag("contents");
if (contentsTag == null) {
return;

View File

@ -163,4 +163,8 @@ public final class ComponentUtil {
public static CompoundTag deserializeLegacyShowItem(final JsonElement element, final SerializerVersion version) {
return (CompoundTag) version.toTag(version.toComponent(element).asUnformattedString());
}
public static CompoundTag deserializeShowItem(final Tag value, final SerializerVersion version) {
return (CompoundTag) version.toTag(version.toComponent(value).asUnformattedString());
}
}