From f341fc132ca76e77d1cc247e022f80a4fcb1170c Mon Sep 17 00:00:00 2001 From: KennyTV Date: Sat, 29 May 2021 14:56:22 +0200 Subject: [PATCH] Fix ancient client error caused by empty meta for < 1.11 Since modern versions don't immediately send metadata in spawn packets and 1.10 clients and lower have a slight oversight in the meta getting, every mob/player spawn spammed the client console with an error. Even though it is a harmless error, I figured people would like their client console not to get spammed anymore. --- .../packets/EntityPackets1_11.java | 35 ++++++++++++------- 1 file changed, 22 insertions(+), 13 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets1_11.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets1_11.java index 1fa524e3..b32bccdd 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets1_11.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_10to1_11/packets/EntityPackets1_11.java @@ -134,23 +134,25 @@ public class EntityPackets1_11 extends LegacyEntityRewriter handler(getTrackerHandler(Type.UNSIGNED_BYTE, 0)); // Rewrite entity type / metadata - handler(new PacketHandler() { - @Override - public void handle(PacketWrapper wrapper) throws Exception { - int entityId = wrapper.get(Type.VAR_INT, 0); - EntityType type = tracker(wrapper.user()).entityType(entityId); + handler(wrapper -> { + int entityId = wrapper.get(Type.VAR_INT, 0); + EntityType type = tracker(wrapper.user()).entityType(entityId); - List list = wrapper.get(Types1_9.METADATA_LIST, 0); - handleMetadata(wrapper.get(Type.VAR_INT, 0), list, wrapper.user()); + List list = wrapper.get(Types1_9.METADATA_LIST, 0); + handleMetadata(wrapper.get(Type.VAR_INT, 0), list, wrapper.user()); - EntityData entityData = entityDataForType(type); - if (entityData != null) { - wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.replacementId()); - if (entityData.hasBaseMeta()) { - entityData.defaultMeta().createMeta(new WrappedMetadata(list)); - } + EntityData entityData = entityDataForType(type); + if (entityData != null) { + wrapper.set(Type.UNSIGNED_BYTE, 0, (short) entityData.replacementId()); + if (entityData.hasBaseMeta()) { + entityData.defaultMeta().createMeta(new WrappedMetadata(list)); } } + + // Sub 1.11 clients will error if the list is empty + if (list.isEmpty()) { + list.add(new Metadata(0, MetaType1_9.Byte, (byte) 0)); + } }); } }); @@ -172,6 +174,13 @@ public class EntityPackets1_11 extends LegacyEntityRewriter map(Types1_9.METADATA_LIST); // 7 - Metadata list handler(getTrackerAndMetaHandler(Types1_9.METADATA_LIST, Entity1_11Types.EntityType.PLAYER)); + handler(wrapper -> { + // Sub 1.11 clients will cry if the list is empty + List metadata = wrapper.get(Types1_9.METADATA_LIST, 0); + if (metadata.isEmpty()) { + metadata.add(new Metadata(0, MetaType1_9.Byte, (byte) 0)); + } + }); } });