Handle translatables in 1.14/1.15 entity display names

This commit is contained in:
Nassim Jahnke 2023-03-18 12:23:14 +01:00
parent 587a5e487f
commit eb6e9e016a
No known key found for this signature in database
GPG Key ID: 6BE3B555EBC5982B
3 changed files with 5 additions and 15 deletions

View File

@ -175,7 +175,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
}
}
public void registerMetaTypeHandler(@Nullable MetaType itemType, @Nullable MetaType blockType, @Nullable MetaType particleType, @Nullable MetaType optChatType) {
public void registerMetaTypeHandler(@Nullable MetaType itemType, @Nullable MetaType blockType, @Nullable MetaType particleType, @Nullable MetaType optionalComponentType) {
filter().handler((event, meta) -> {
MetaType type = meta.metaType();
if (itemType != null && type == itemType) {
@ -185,7 +185,7 @@ public abstract class EntityRewriterBase<C extends ClientboundPacketType, T exte
meta.setValue(protocol.getMappingData().getNewBlockStateId(data));
} else if (particleType != null && type == particleType) {
rewriteParticle(meta.value());
} else if (optChatType != null && type == optChatType) {
} else if (optionalComponentType != null && type == optionalComponentType) {
JsonElement text = meta.value();
if (text != null) {
protocol.getTranslatableRewriter().processText(text);

View File

@ -31,8 +31,6 @@ import com.viaversion.viaversion.api.minecraft.VillagerData;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types;
import com.viaversion.viaversion.api.minecraft.entities.Entity1_14Types;
import com.viaversion.viaversion.api.minecraft.entities.EntityType;
import com.viaversion.viaversion.api.minecraft.item.Item;
import com.viaversion.viaversion.api.minecraft.metadata.MetaType;
import com.viaversion.viaversion.api.minecraft.metadata.Metadata;
import com.viaversion.viaversion.api.protocol.packet.PacketWrapper;
import com.viaversion.viaversion.api.protocol.remapper.PacketHandlers;
@ -348,18 +346,10 @@ public class EntityPackets1_14 extends LegacyEntityRewriter<ClientboundPackets1_
if (typeId <= 15) {
meta.setMetaType(Types1_13_2.META_TYPES.byId(typeId));
}
MetaType type = meta.metaType();
if (type == Types1_13_2.META_TYPES.itemType) {
Item item = (Item) meta.getValue();
meta.setValue(protocol.getItemRewriter().handleItemToClient(item));
} else if (type == Types1_13_2.META_TYPES.blockStateType) {
int blockstate = meta.value();
meta.setValue(protocol.getMappingData().getNewBlockStateId(blockstate));
}
});
registerMetaTypeHandler(Types1_13_2.META_TYPES.itemType, Types1_13_2.META_TYPES.blockStateType, null, Types1_13_2.META_TYPES.optionalComponentType);
filter().type(Entity1_14Types.PILLAGER).cancel(15);
filter().type(Entity1_14Types.FOX).cancel(15);

View File

@ -192,7 +192,7 @@ public class EntityPackets1_15 extends EntityRewriter<ClientboundPackets1_15, Pr
@Override
protected void registerRewrites() {
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.blockStateType, Types1_14.META_TYPES.particleType, null);
registerMetaTypeHandler(Types1_14.META_TYPES.itemType, Types1_14.META_TYPES.blockStateType, Types1_14.META_TYPES.particleType, Types1_14.META_TYPES.optionalComponentType);
filter().filterFamily(Entity1_15Types.LIVINGENTITY).removeIndex(12);