From 2f8114abb135469f7fadd1b65bfc231d8bcf2d80 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Mon, 18 Dec 2023 17:14:24 +0100 Subject: [PATCH] Finish 23w51a, maybe --- .../viaversion/api/data/MappingData.java | 4 +++ .../viaversion/api/data/MappingDataBase.java | 10 ++++++ .../data/MappingData.java | 2 +- .../packets/EntityPackets.java | 2 +- .../packets/InventoryPackets.java | 4 +-- .../data/AttributeMappings.java | 32 +++++++++++++++--- .../rewriter/EntityPacketRewriter1_20_5.java | 29 ++++++---------- .../viaversion/data/identifiers-1.20.5.nbt | Bin 0 -> 3377 bytes .../data/mappings-1.20.3to1.20.5.nbt | Bin 0 -> 413 bytes 9 files changed, 57 insertions(+), 26 deletions(-) create mode 100644 common/src/main/resources/assets/viaversion/data/identifiers-1.20.5.nbt create mode 100644 common/src/main/resources/assets/viaversion/data/mappings-1.20.3to1.20.5.nbt diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/MappingData.java b/api/src/main/java/com/viaversion/viaversion/api/data/MappingData.java index 03265fced..6ccfc1b9f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/MappingData.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/MappingData.java @@ -79,6 +79,8 @@ public interface MappingData { */ int getNewParticleId(int id); + int getNewAttributeId(int id); + /** * Returns a list of tags to send if present. * @@ -105,6 +107,8 @@ public interface MappingData { @Nullable Mappings getEnchantmentMappings(); + @Nullable Mappings getAttributeMappings(); + @Nullable FullMappings getEntityMappings(); @Nullable FullMappings getArgumentTypeMappings(); diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java index e01b9256a..3a13067b1 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/MappingDataBase.java @@ -166,6 +166,11 @@ public class MappingDataBase implements MappingData { return checkValidity(id, particleMappings.getNewId(id), "particles"); } + @Override + public int getNewAttributeId(final int id) { + return checkValidity(id, attributeMappings.getNewId(id), "attributes"); + } + @Override public @Nullable List getTags(final RegistryType type) { return tags != null ? tags.get(type) : null; @@ -216,6 +221,11 @@ public class MappingDataBase implements MappingData { return enchantmentMappings; } + @Override + public @Nullable Mappings getAttributeMappings() { + return attributeMappings; + } + @Override public @Nullable FullMappings getEntityMappings() { return entityMappings; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/data/MappingData.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/data/MappingData.java index 45baf1c7f..44ef9aba8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/data/MappingData.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/data/MappingData.java @@ -44,7 +44,7 @@ public class MappingData extends MappingDataBase { attributeMappings.put("generic.armorToughness", "minecraft:generic.armor_toughness"); } - public BiMap getAttributeMappings() { + public BiMap attributeIdentifierMappings() { return attributeMappings; } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java index 1895f5eb2..0c3f5fcd8 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/EntityPackets.java @@ -236,7 +236,7 @@ public class EntityPackets { for (int i = 0; i < size; i++) { // Attributes have been renamed and are now namespaced identifiers String key = wrapper.read(Type.STRING); - String attributeIdentifier = protocol.getMappingData().getAttributeMappings().get(key); + String attributeIdentifier = protocol.getMappingData().attributeIdentifierMappings().get(key); if (attributeIdentifier == null) { attributeIdentifier = Key.namespaced(key); if (!Key.isValid(attributeIdentifier)) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java index 3e2db6041..6188b4bea 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/packets/InventoryPackets.java @@ -244,8 +244,8 @@ public class InventoryPackets extends ItemRewriter STRING_TO_ID = new Object2IntOpenHashMap<>(); static { - + for (int i = 0; i < ATTRIBUTES.length; i++) { + STRING_TO_ID.put(ATTRIBUTES[i], i); + } } - public @Nullable String attribute(final int id) { + public static @Nullable String attribute(final int id) { return id >= 0 && id < ATTRIBUTES.length ? ATTRIBUTES[id] : null; } - public int id(final String attribute) { + public static int id(final String attribute) { + return STRING_TO_ID.getOrDefault(attribute, -1); } } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java index 39b2a0251..c8325ca9c 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_20_5to1_20_3/rewriter/EntityPacketRewriter1_20_5.java @@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.type.types.version.Types1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundConfigurationPackets1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_3to1_20_2.packet.ClientboundPackets1_20_3; import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.Protocol1_20_5To1_20_3; +import com.viaversion.viaversion.protocols.protocol1_20_5to1_20_3.data.AttributeMappings; import com.viaversion.viaversion.rewriter.EntityRewriter; import com.viaversion.viaversion.util.Key; @@ -37,9 +38,8 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { - wrapper.passthrough(Type.VAR_INT); // Entity id - wrapper.passthrough(Type.VAR_INT); // Effect id + wrapper.passthrough(Type.VAR_INT); // Entity ID + wrapper.passthrough(Type.VAR_INT); // Effect ID wrapper.passthrough(Type.BYTE); // Amplifier wrapper.passthrough(Type.VAR_INT); // Duration wrapper.passthrough(Type.BYTE); // Flags @@ -88,17 +88,19 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { - wrapper.passthrough(Type.VAR_INT); // Entity id + wrapper.passthrough(Type.VAR_INT); // Entity ID final int size = wrapper.passthrough(Type.VAR_INT); for (int i = 0; i < size; i++) { - final String attributeIdentifier = Key.namespaced(wrapper.read(Type.STRING)); - wrapper.write(Type.VAR_INT, protocol.getMappingData()); + // From a string to a registry int ID + final String attributeIdentifier = Key.stripMinecraftNamespace(wrapper.read(Type.STRING)); + final int id = AttributeMappings.id(attributeIdentifier); + wrapper.write(Type.VAR_INT, protocol.getMappingData().getNewAttributeId(id)); wrapper.passthrough(Type.DOUBLE); // Base final int modifierSize = wrapper.passthrough(Type.VAR_INT); for (int j = 0; j < modifierSize; j++) { - wrapper.passthrough(Type.UUID); // Id + wrapper.passthrough(Type.UUID); // ID wrapper.passthrough(Type.DOUBLE); // Amount wrapper.passthrough(Type.BYTE); // Operation } @@ -108,15 +110,6 @@ public final class EntityPacketRewriter1_20_5 extends EntityRewriter { - int id = meta.metaType().typeId(); - if (id >= SomeAddedIndex) { - id++; - } - meta.setMetaType(Types1_20_3.META_TYPES.byId(id)); - });*/ - registerMetaTypeHandler( Types1_20_3.META_TYPES.itemType, Types1_20_3.META_TYPES.blockStateType, diff --git a/common/src/main/resources/assets/viaversion/data/identifiers-1.20.5.nbt b/common/src/main/resources/assets/viaversion/data/identifiers-1.20.5.nbt new file mode 100644 index 0000000000000000000000000000000000000000..9261c9ba6a8a115a826daea3857911fe361e5646 GIT binary patch literal 3377 zcmZuz+mhlo5bde~gMk4iTeF+*NZ#@@D%qB81=&(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