From 948c615622e979d49e7f02ded55ac7902ea50fd5 Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Mon, 22 Apr 2024 23:30:15 +0200 Subject: [PATCH 1/2] Replace LegacyEntityRewriter#getObjectTypeFromId with existing method (#723) --- .../viabackwards/api/rewriters/LegacyEntityRewriter.java | 6 +----- .../protocol1_10to1_11/packets/EntityPackets1_11.java | 2 +- .../protocol1_11_1to1_12/packets/EntityPackets1_12.java | 2 +- .../protocol1_11to1_11_1/packets/EntityPackets1_11_1.java | 2 +- .../protocol1_12_2to1_13/packets/EntityPackets1_13.java | 2 +- .../protocol1_13to1_13_1/packets/EntityPackets1_13_1.java | 2 +- .../protocol1_9_4to1_10/packets/EntityPackets1_10.java | 2 +- 7 files changed, 7 insertions(+), 11 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java index e995b821..ea9c401b 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java @@ -132,7 +132,7 @@ public abstract class LegacyEntityRewriter addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), getObjectTypeFromId(wrapper.get(Type.BYTE, 0))); + return wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), objectTypeFromId(wrapper.get(Type.BYTE, 0))); } protected PacketHandler getTrackerAndMetaHandler(Type> metaType, EntityType entityType) { @@ -161,10 +161,6 @@ public abstract class LegacyEntityRewriter Date: Tue, 23 Apr 2024 10:45:12 +0200 Subject: [PATCH 2/2] Add mob spawn rewriter function for pre 1.11 (#724) --- .../api/rewriters/LegacyEntityRewriter.java | 18 +++++++++++++-- .../packets/EntityPackets1_11.java | 23 +++++-------------- .../packets/EntityPackets1_12.java | 2 +- .../packets/EntityPackets1_11_1.java | 2 +- .../packets/EntityPackets1_13.java | 2 +- .../packets/EntityPackets1_14.java | 2 +- 6 files changed, 26 insertions(+), 23 deletions(-) diff --git a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java index ea9c401b..53a6bb71 100644 --- a/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java +++ b/common/src/main/java/com/viaversion/viabackwards/api/rewriters/LegacyEntityRewriter.java @@ -113,7 +113,7 @@ public abstract class LegacyEntityRewriter> metaType) { + protected PacketHandler getMobSpawnRewriter(Type> metaType, IdSetter idSetter) { return wrapper -> { int entityId = wrapper.get(Type.VAR_INT, 0); EntityType type = tracker(wrapper.user()).entityType(entityId); @@ -123,7 +123,7 @@ public abstract class LegacyEntityRewriter> metaType) { + return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Type.UNSIGNED_BYTE, 0, (short) id)); + } + + public PacketHandler getMobSpawnRewriter1_11(Type> metaType) { + return getMobSpawnRewriter(metaType, (wrapper, id) -> wrapper.set(Type.VAR_INT, 1, id)); + } + protected PacketHandler getObjectTrackerHandler() { return wrapper -> addTrackedEntity(wrapper, wrapper.get(Type.VAR_INT, 0), objectTypeFromId(wrapper.get(Type.BYTE, 0))); } @@ -165,4 +173,10 @@ public abstract class LegacyEntityRewriter { - 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()); - - 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)); + List metadata = wrapper.get(Types1_9.METADATA_LIST, 0); + if (metadata.isEmpty()) { + metadata.add(new Metadata(0, MetaType1_9.Byte, (byte) 0)); } }); } diff --git a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java index 4123d40c..753ea278 100644 --- a/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java +++ b/common/src/main/java/com/viaversion/viabackwards/protocol/protocol1_11_1to1_12/packets/EntityPackets1_12.java @@ -89,7 +89,7 @@ public class EntityPackets1_12 extends LegacyEntityRewriter