From dd454d56f3b47739c1c776a389ee1621abe3422b Mon Sep 17 00:00:00 2001 From: Gerrygames Date: Tue, 21 May 2019 21:50:57 +0200 Subject: [PATCH] fix display name --- .../viabackwards/api/rewriters/EntityRewriter.java | 10 +++++++++- .../packets/EntityPackets1_14.java | 3 +++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriter.java b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriter.java index 9236f03f..ae5b46c9 100644 --- a/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriter.java +++ b/core/src/main/java/nl/matsv/viabackwards/api/rewriters/EntityRewriter.java @@ -30,6 +30,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.MetaType; import us.myles.ViaVersion.api.minecraft.metadata.Metadata; import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_9; import us.myles.ViaVersion.exception.CancelException; +import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.ChatRewriter; import java.util.ArrayList; import java.util.List; @@ -51,6 +52,9 @@ public abstract class EntityRewriter extends Rewrit @Getter(AccessLevel.PROTECTED) @Setter(AccessLevel.PROTECTED) private int displayNameIndex = 2; + @Getter(AccessLevel.PROTECTED) + @Setter(AccessLevel.PROTECTED) + private boolean isDisplayNameJson = false; protected AbstractEntityType getEntityType(UserConnection connection, int id) { return getEntityTracker(connection).getEntityType(id); @@ -149,7 +153,11 @@ public abstract class EntityRewriter extends Rewrit if (entData.getMobName() != null && (data.getValue() == null || ((String) data.getValue()).isEmpty()) && data.getMetaType().getTypeID() == getDisplayNameMetaType().getTypeID()) { - data.setValue(entData.getMobName()); + String mobName = entData.getMobName(); + if (isDisplayNameJson) { + mobName = ChatRewriter.legacyTextToJson(mobName); + } + data.setValue(mobName); } } diff --git a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java index 6dc54f8a..9dd49b40 100644 --- a/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java +++ b/core/src/main/java/nl/matsv/viabackwards/protocol/protocol1_13_2to1_14/packets/EntityPackets1_14.java @@ -288,6 +288,9 @@ public class EntityPackets1_14 extends EntityRewriter { @Override protected void registerRewrites() { + setDisplayNameJson(true); + setDisplayNameMetaType(MetaType1_13_2.OptChat); + regEntType(EntityType1_14.EntityType.CAT, EntityType1_14.EntityType.OCELOT).mobName("Cat").spawnMetadata(e -> { // e.add(new Metadata(13, MetaType1_13_2.Byte, (byte) 0x4)); // Tamed cat });