From 0c2c8400ae579644b77d629ff6ba41f7eff18a0f Mon Sep 17 00:00:00 2001 From: EnZaXD <60033407+FlorianMichael@users.noreply.github.com> Date: Wed, 10 Apr 2024 17:34:56 +0200 Subject: [PATCH] Make handling of optional block metadata more explicit in <1.19.4 (#3782) --- .../metadata/MetadataRewriter1_13_1To1_13.java | 2 +- .../metadata/MetadataRewriter1_13To1_12_2.java | 16 +++++++++------- .../metadata/MetadataRewriter1_14To1_13_2.java | 2 +- .../metadata/MetadataRewriter1_15To1_14_4.java | 2 +- .../metadata/MetadataRewriter1_16_2To1_16_1.java | 2 +- .../metadata/MetadataRewriter1_16To1_15_2.java | 2 +- .../packets/EntityPackets.java | 2 +- .../packets/EntityPackets.java | 2 +- .../packets/EntityPackets.java | 2 +- .../packets/EntityPackets.java | 2 +- .../viaversion/rewriter/EntityRewriter.java | 12 +++++++++++- 11 files changed, 29 insertions(+), 17 deletions(-) diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/metadata/MetadataRewriter1_13_1To1_13.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/metadata/MetadataRewriter1_13_1To1_13.java index 389618163..c6bf1b079 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/metadata/MetadataRewriter1_13_1To1_13.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_1to1_13/metadata/MetadataRewriter1_13_1To1_13.java @@ -32,7 +32,7 @@ public class MetadataRewriter1_13_1To1_13 extends EntityRewriter { int data = meta.value(); meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java index 1edfe1cb0..d0c28bb78 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java @@ -41,10 +41,12 @@ public class MetadataRewriter1_13To1_12_2 extends EntityRewriter Types1_13.META_TYPES.byId(typeId > 4 ? typeId + 1 : typeId)); filter().metaType(Types1_13.META_TYPES.itemType).handler(((event, meta) -> protocol.getItemRewriter().handleItemToClient(meta.value()))); filter().metaType(Types1_13.META_TYPES.blockStateType).handler(((event, meta) -> { - int oldId = meta.value(); - int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15)); - int newId = WorldPackets.toNewId(combined); - meta.setValue(newId); + final int oldId = meta.value(); + if (oldId != 0) { + final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15)); + final int newId = WorldPackets.toNewId(combined); + meta.setValue(newId); + } })); // Previously unused, now swimming @@ -66,9 +68,9 @@ public class MetadataRewriter1_13To1_12_2 extends EntityRewriter { - int oldId = meta.value(); - int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15)); - int newId = WorldPackets.toNewId(combined); + final int oldId = meta.value(); + final int combined = (((oldId & 4095) << 4) | (oldId >> 12 & 15)); + final int newId = WorldPackets.toNewId(combined); meta.setValue(newId); }); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java index 1a9c79b94..05acc1187 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_14to1_13_2/metadata/MetadataRewriter1_14To1_13_2.java @@ -45,7 +45,7 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter { int data = meta.value(); meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/metadata/MetadataRewriter1_16_2To1_16_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/metadata/MetadataRewriter1_16_2To1_16_1.java index fd6eecd8c..f4f6023e1 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/metadata/MetadataRewriter1_16_2To1_16_1.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16_2to1_16_1/metadata/MetadataRewriter1_16_2To1_16_1.java @@ -34,7 +34,7 @@ public class MetadataRewriter1_16_2To1_16_1 extends EntityRewriter { int data = meta.value(); meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/metadata/MetadataRewriter1_16To1_15_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/metadata/MetadataRewriter1_16To1_15_2.java index c3716726d..7a4bc0da3 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/metadata/MetadataRewriter1_16To1_15_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/metadata/MetadataRewriter1_16To1_15_2.java @@ -37,7 +37,7 @@ public class MetadataRewriter1_16To1_15_2 extends EntityRewriter { int data = meta.value(); meta.setValue(protocol.getMappingData().getNewBlockStateId(data)); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java index 6ee44a1ad..140694c48 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_17to1_16_4/packets/EntityPackets.java @@ -159,7 +159,7 @@ public final class EntityPackets extends EntityRewriter Types1_19_3.META_TYPES.byId(typeId >= 2 ? typeId + 1 : typeId)); // Long added - registerMetaTypeHandler(Types1_19_3.META_TYPES.itemType, Types1_19_3.META_TYPES.blockStateType, null, Types1_19_3.META_TYPES.particleType); + registerMetaTypeHandler(Types1_19_3.META_TYPES.itemType, Types1_19_3.META_TYPES.blockStateType, Types1_19_3.META_TYPES.particleType); filter().type(EntityTypes1_19_3.ENTITY).index(6).handler((event, meta) -> { // Sitting pose added diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java index 35323362f..6ad9ab3bb 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_19to1_18_2/packets/EntityPackets.java @@ -338,7 +338,7 @@ public final class EntityPackets extends EntityRewriter { // Convert to new block id 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 4f7bfd2b1..3992de7f5 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -20,7 +20,6 @@ package com.viaversion.viaversion.rewriter; import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.github.steveice10.opennbt.tag.builtin.ListTag; import com.github.steveice10.opennbt.tag.builtin.NumberTag; -import com.github.steveice10.opennbt.tag.builtin.Tag; import com.google.common.base.Preconditions; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; @@ -202,6 +201,17 @@ public abstract class EntityRewriter