From 7be713924144b4a8c56d12b3bfabb6ec0a5efe9b Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 25 Oct 2024 20:45:23 +0200 Subject: [PATCH] Handle entity type changes in show_entity hover events Fixes #4199 --- .../viaversion/api/rewriter/EntityRewriter.java | 8 ++++++++ .../viaversion/api/rewriter/ItemRewriter.java | 3 ++- .../viaversion/rewriter/ComponentRewriter.java | 5 +++++ .../viaversion/rewriter/EntityRewriter.java | 13 ++++++++++++- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/api/src/main/java/com/viaversion/viaversion/api/rewriter/EntityRewriter.java b/api/src/main/java/com/viaversion/viaversion/api/rewriter/EntityRewriter.java index d0d6e9696..136f2cf74 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/rewriter/EntityRewriter.java +++ b/api/src/main/java/com/viaversion/viaversion/api/rewriter/EntityRewriter.java @@ -58,6 +58,14 @@ public interface EntityRewriter> extends Rewriter */ int newEntityId(int id); + /** + * Returns the mapped entity (or the same if it has not changed). + * + * @param identifier unmapped entity identifier + * @return mapped entity identifier + */ + String mappedEntityIdentifier(String identifier); + /** * Handles and transforms entity data of an entity. * diff --git a/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java b/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java index c92b699fa..a70929627 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java +++ b/api/src/main/java/com/viaversion/viaversion/api/rewriter/ItemRewriter.java @@ -51,7 +51,8 @@ public interface ItemRewriter> extends Rewriter implements com.v final CompoundTag contents = hoverEventTag.getCompoundTag("contents"); if (contents != null) { processTag(connection, contents.get("name")); + + final StringTag typeTag = contents.getStringTag("type"); + if (typeTag != null && protocol.getEntityRewriter() != null) { + typeTag.setValue(protocol.getEntityRewriter().mappedEntityIdentifier(typeTag.getValue())); + } } } else if (action.equals("show_item")) { convertLegacyContents(hoverEventTag); diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java index 89ae537fd..63f0f456b 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -24,6 +24,7 @@ import com.viaversion.nbt.tag.NumberTag; import com.viaversion.nbt.tag.Tag; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.data.FullMappings; import com.viaversion.viaversion.api.data.Int2IntMapMappings; import com.viaversion.viaversion.api.data.Mappings; import com.viaversion.viaversion.api.data.ParticleMappings; @@ -60,7 +61,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; public abstract class EntityRewriter> extends RewriterBase implements com.viaversion.viaversion.api.rewriter.EntityRewriter { - private static final EntityData[] EMPTY_ARRAY = new EntityData[0]; protected final List entityDataFilters = new ArrayList<>(); protected final boolean trackMappedType; protected Mappings typeMappings; @@ -156,6 +156,17 @@ public abstract class EntityRewriter