From 0070485d2e3873b45623ad4eecb8ff7f3b4ea638 Mon Sep 17 00:00:00 2001 From: RaphiMC <50594595+RaphiMC@users.noreply.github.com> Date: Tue, 25 Aug 2020 15:43:21 +0200 Subject: [PATCH 1/2] fixed 1.9 -> 1.8 enderman held item metadata translation --- .../MetadataRewriter1_13To1_12_2.java | 8 ++++++ .../protocol1_9to1_8/metadata/MetaIndex.java | 4 +-- .../metadata/MetadataRewriter1_9To1_8.java | 25 +++++++++---------- 3 files changed, 22 insertions(+), 15 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java index c63234010..4e648f65e 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_13to1_12_2/metadata/MetadataRewriter1_13To1_12_2.java @@ -43,6 +43,14 @@ public class MetadataRewriter1_13To1_12_2 extends MetadataRewriter { } } + // Remap held block to match new format for remapping to flat block + if (type == Entity1_13Types.EntityType.ENDERMAN && metadata.getId() == 12) { + int stateId = (int) metadata.getValue(); + int id = stateId & 4095; + int data = stateId >> 12 & 15; + metadata.setValue((id << 4) | (data & 0xF)); + } + // 1.13 changed item to flat item (no data) if (metadata.getMetaType() == MetaType1_13.Slot) { metadata.setMetaType(MetaType1_13.Slot); diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java index 2c5c19c2a..1769c6a8f 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetaIndex.java @@ -68,8 +68,8 @@ public enum MetaIndex { // villager VILLAGER_PROFESSION(VILLAGER, 16, MetaType1_8.Int, 12, MetaType1_9.VarInt), // enderman - ENDERMAN_BLOCK(ENDERMAN, 16, MetaType1_8.Short, 11, MetaType1_9.BlockID), // special case - ENDERMAN_BLOCKDATA(ENDERMAN, 17, MetaType1_8.Byte, 11, MetaType1_9.BlockID), // special case + ENDERMAN_BLOCKSTATE(ENDERMAN, 16, MetaType1_8.Short, 11, MetaType1_9.BlockID), + ENDERMAN_BLOCKDATA(ENDERMAN, 17, MetaType1_8.Byte, MetaType1_9.Discontinued), //always 0 when sent, never read by the client ENDERMAN_ISSCREAMING(ENDERMAN, 18, MetaType1_8.Byte, 12, MetaType1_9.Boolean), // zombie ZOMBIE_ISCHILD(ZOMBIE, 12, MetaType1_8.Byte, 11, MetaType1_9.Boolean), diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java index 94d4a5b09..aba9d59a9 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java @@ -39,19 +39,6 @@ public class MetadataRewriter1_9To1_8 extends MetadataRewriter { metadata.setId(metaIndex.getNewIndex()); metadata.setMetaType(metaIndex.getNewType()); - if (type == Entity1_10Types.EntityType.ENDERMAN && metaIndex.getNewType() == MetaType1_9.BlockID) { - if (metaIndex.getOldType() == MetaType1_8.Short) { - int id = (Short) metadata.getValue(); - Metadata meta = getMetaByIndex(17, metadatas); - int data = meta != null ? (Byte) meta.getValue() : 0; - int combined = (id << 4) | (data & 0xF); - metadata.setValue(combined); - } else { - metadatas.remove(metadata); - } - return; - } - Object value = metadata.getValue(); switch (metaIndex.getNewType()) { case Byte: @@ -124,6 +111,18 @@ public class MetadataRewriter1_9To1_8 extends MetadataRewriter { value = Protocol1_9To1_8.fixJson(value.toString()); metadata.setValue(value); break; + case BlockID: + // convert from int, short, byte + if (metaIndex.getOldType() == MetaType1_8.Byte) { + metadata.setValue(((Byte) value).intValue()); + } + if (metaIndex.getOldType() == MetaType1_8.Short) { + metadata.setValue(((Short) value).intValue()); + } + if (metaIndex.getOldType() == MetaType1_8.Int) { + metadata.setValue(value); + } + break; default: metadatas.remove(metadata); throw new Exception("Unhandled MetaDataType: " + metaIndex.getNewType()); From cae5122d044f36ff3d206f281c3fa859f3710212 Mon Sep 17 00:00:00 2001 From: RK_01 <50594595+RaphiMC@users.noreply.github.com> Date: Tue, 25 Aug 2020 15:53:58 +0200 Subject: [PATCH 2/2] Applied suggestions for PR Co-authored-by: Nassim --- .../metadata/MetadataRewriter1_9To1_8.java | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java index aba9d59a9..4fab7b1cb 100644 --- a/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java +++ b/common/src/main/java/us/myles/ViaVersion/protocols/protocol1_9to1_8/metadata/MetadataRewriter1_9To1_8.java @@ -112,16 +112,8 @@ public class MetadataRewriter1_9To1_8 extends MetadataRewriter { metadata.setValue(value); break; case BlockID: - // convert from int, short, byte - if (metaIndex.getOldType() == MetaType1_8.Byte) { - metadata.setValue(((Byte) value).intValue()); - } - if (metaIndex.getOldType() == MetaType1_8.Short) { - metadata.setValue(((Short) value).intValue()); - } - if (metaIndex.getOldType() == MetaType1_8.Int) { - metadata.setValue(value); - } + // Convert from int, short, byte + metadata.setValue(((Number) value).intValue()); break; default: metadatas.remove(metadata);