mirror of
https://github.com/ViaVersion/ViaVersion.git
synced 2024-11-25 11:35:18 +01:00
Handle legacy item hover events
Co-authored-by: RaphiMC <50594595+raphimc@users.noreply.github.com>
This commit is contained in:
parent
287678c12a
commit
4e25549682
@ -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;
|
||||
|
@ -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());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user