From a49c395486a39849ae87c4086235417dc3863839 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 10 Nov 2021 10:30:17 +0100 Subject: [PATCH] Make changes in particles easier to handle --- .../viaversion/api/data/ParticleMappings.java | 61 ++++++-- .../api/minecraft/metadata/MetaType.java | 40 +++++ .../api/minecraft/metadata/Metadata.java | 2 +- .../metadata/types/MetaType1_13.java | 1 + .../metadata/types/MetaType1_13_2.java | 1 + .../metadata/types/MetaType1_14.java | 1 + .../metadata/types/MetaType1_16.java | 1 + .../metadata/types/MetaType1_17.java | 1 + .../metadata/types/MetaType1_18.java | 1 + .../minecraft/metadata/types/MetaTypes.java | 44 ++++++ .../metadata/types/MetaTypes1_13.java | 68 +++++++++ .../metadata/types/MetaTypes1_13_2.java | 68 +++++++++ .../metadata/types/MetaTypes1_14.java | 71 +++++++++ .../viaversion/api/type/types/Particle.java | 8 +- .../types/minecraft/AbstractParticleType.java | 1 + .../types/minecraft/Particle1_13Type.java | 1 + .../types/minecraft/Particle1_13_2Type.java | 1 + .../types/minecraft/Particle1_14Type.java | 1 + .../types/minecraft/Particle1_16Type.java | 1 + .../types/minecraft/Particle1_17Type.java | 1 + .../types/minecraft/Particle1_18Type.java | 1 + .../type/types/minecraft/ParticleType.java | 143 ++++++++++++++++++ .../type/types/version/Metadata1_13Type.java | 4 +- .../types/version/Metadata1_13_2Type.java | 4 +- .../type/types/version/Metadata1_14Type.java | 4 +- .../type/types/version/Metadata1_16Type.java | 4 +- .../type/types/version/Metadata1_17Type.java | 4 +- .../type/types/version/Metadata1_18Type.java | 4 +- .../api/type/types/version/MetadataType.java | 41 +++++ .../api/type/types/version/Types1_13.java | 23 +-- .../api/type/types/version/Types1_13_2.java | 21 +-- .../api/type/types/version/Types1_14.java | 19 +-- .../api/type/types/version/Types1_16.java | 13 +- .../api/type/types/version/Types1_17.java | 9 +- .../api/type/types/version/Types1_18.java | 9 +- .../EntityToggleGlideListener.java | 3 +- .../MetadataRewriter1_13_1To1_13.java | 8 +- .../packets/EntityPackets.java | 3 +- .../Protocol1_13To1_12_2.java | 8 + .../MetadataRewriter1_13To1_12_2.java | 18 +-- .../Protocol1_14To1_13_2.java | 14 ++ .../MetadataRewriter1_14To1_13_2.java | 24 +-- .../packets/EntityPackets.java | 9 +- .../MetadataRewriter1_15To1_14_4.java | 9 +- .../MetadataRewriter1_16_2To1_16_1.java | 8 +- .../Protocol1_16To1_15_2.java | 10 +- .../MetadataRewriter1_16To1_15_2.java | 12 +- .../Protocol1_17To1_16_4.java | 10 ++ .../packets/EntityPackets.java | 7 +- .../Protocol1_18To1_17_1.java | 14 ++ .../packets/EntityPackets.java | 7 +- .../packets/InventoryPackets.java | 4 +- .../viaversion/rewriter/EntityRewriter.java | 5 +- .../viaversion/rewriter/ItemRewriter.java | 4 +- 54 files changed, 698 insertions(+), 156 deletions(-) create mode 100644 api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes.java create mode 100644 api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13.java create mode 100644 api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13_2.java create mode 100644 api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_14.java create mode 100644 api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ParticleType.java create mode 100644 api/src/main/java/com/viaversion/viaversion/api/type/types/version/MetadataType.java diff --git a/api/src/main/java/com/viaversion/viaversion/api/data/ParticleMappings.java b/api/src/main/java/com/viaversion/viaversion/api/data/ParticleMappings.java index 33eea692a..73dcc21aa 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/data/ParticleMappings.java +++ b/api/src/main/java/com/viaversion/viaversion/api/data/ParticleMappings.java @@ -23,42 +23,71 @@ package com.viaversion.viaversion.api.data; import com.google.gson.JsonArray; +import it.unimi.dsi.fastutil.ints.IntArrayList; +import it.unimi.dsi.fastutil.ints.IntList; import it.unimi.dsi.fastutil.objects.Object2IntMap; public class ParticleMappings { + private final Object2IntMap stringToId; private final Mappings mappings; - private final int blockId; - private final int fallingDustId; - private final int blockMarkerId; - private final int itemId; + private final IntList itemParticleIds = new IntArrayList(2); + private final IntList blockParticleIds = new IntArrayList(4); public ParticleMappings(JsonArray oldMappings, Mappings mappings) { this.mappings = mappings; - Object2IntMap map = MappingDataLoader.arrayToMap(oldMappings); - blockId = map.getInt("block"); - fallingDustId = map.getInt("falling_dust"); - blockMarkerId = map.getInt("block_marker"); - itemId = map.getInt("item"); + stringToId = MappingDataLoader.arrayToMap(oldMappings); + stringToId.defaultReturnValue(-1); + addBlockParticle("block"); + addBlockParticle("falling_dust"); + addBlockParticle("block_marker"); + addItemParticle("item"); + } + + /** + * Returns the unmapped integer id for the given identifier, or -1 if not found. + * + * @param identifier unmapped string identifier + * @return unmapped int id, or -1 if not found + */ + public int id(String identifier) { + return stringToId.getInt(identifier); } public Mappings getMappings() { return mappings; } + public boolean addItemParticle(final String identifier) { + final int id = id(identifier); + return id != -1 && itemParticleIds.add(id); + } + + public boolean addBlockParticle(final String identifier) { + final int id = id(identifier); + return id != -1 && blockParticleIds.add(id); + } + + public boolean isBlockParticle(final int id) { + return blockParticleIds.contains(id); + } + + public boolean isItemParticle(final int id) { + return itemParticleIds.contains(id); + } + + @Deprecated/*(forRemoval = true)*/ public int getBlockId() { - return blockId; + return id("block"); } + @Deprecated/*(forRemoval = true)*/ public int getFallingDustId() { - return fallingDustId; - } - - public int getBlockmarkerid() { - return blockMarkerId; + return id("falling_dust"); } + @Deprecated/*(forRemoval = true)*/ public int getItemId() { - return itemId; + return id("item"); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/MetaType.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/MetaType.java index c2a90ecbd..c84316f13 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/MetaType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/MetaType.java @@ -39,4 +39,44 @@ public interface MetaType { * @return Type id as an integer */ int typeId(); + + static MetaType create(final int typeId, final Type type) { + return new MetaTypeImpl(typeId, type); + } + + final class MetaTypeImpl implements MetaType { + private final int typeId; + private final Type type; + + MetaTypeImpl(final int typeId, final Type type) { + this.typeId = typeId; + this.type = type; + } + + @Override + public int typeId() { + return typeId; + } + + @Override + public Type type() { + return type; + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + final MetaTypeImpl metaType = (MetaTypeImpl) o; + if (typeId != metaType.typeId) return false; + return type.equals(metaType.type); + } + + @Override + public int hashCode() { + int result = typeId; + result = 31 * result + type.hashCode(); + return result; + } + } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/Metadata.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/Metadata.java index 1c2677ba2..357fb3a51 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/Metadata.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/Metadata.java @@ -105,7 +105,7 @@ public final class Metadata { Preconditions.checkNotNull(metaType); if (value != null && !metaType.type().getOutputClass().isAssignableFrom(value.getClass())) { throw new IllegalArgumentException("Metadata value and metaType are incompatible. Type=" + metaType - + ", value=" + (value != null ? value + " (" + value.getClass().getSimpleName() + ")" : "null")); + + ", value=" + value + " (" + value.getClass().getSimpleName() + ")"); } return value; } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13.java index 7235e729e..1c2289a58 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13.java @@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_13; +@Deprecated/*(forRemoval = true)*/ public enum MetaType1_13 implements MetaType { Byte(0, Type.BYTE), VarInt(1, Type.VAR_INT), diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13_2.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13_2.java index 78081e52d..ad8581abc 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_13_2.java @@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_13_2; +@Deprecated/*(forRemoval = true)*/ public enum MetaType1_13_2 implements MetaType { Byte(0, Type.BYTE), VarInt(1, Type.VAR_INT), diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_14.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_14.java index 135205b2d..474bfa3d5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_14.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_14.java @@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_14; +@Deprecated/*(forRemoval = true)*/ public enum MetaType1_14 implements MetaType { Byte(0, Type.BYTE), VarInt(1, Type.VAR_INT), diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_16.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_16.java index dcc7f93c5..abc3b1722 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_16.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_16.java @@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_16; +@Deprecated/*(forRemoval = true)*/ public enum MetaType1_16 implements MetaType { BYTE(0, Type.BYTE), VAR_INT(1, Type.VAR_INT), diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_17.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_17.java index 6c66f6a6d..9e821a6f3 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_17.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_17.java @@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_17; +@Deprecated/*(forRemoval = true)*/ public enum MetaType1_17 implements MetaType { BYTE(0, Type.BYTE), VAR_INT(1, Type.VAR_INT), diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_18.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_18.java index c8183f4e8..a0e709917 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_18.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaType1_18.java @@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.minecraft.metadata.MetaType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_18; +@Deprecated/*(forRemoval = true)*/ public enum MetaType1_18 implements MetaType { BYTE(0, Type.BYTE), VAR_INT(1, Type.VAR_INT), diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes.java new file mode 100644 index 000000000..f716b901a --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes.java @@ -0,0 +1,44 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2021 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.metadata.types; + +import com.viaversion.viaversion.api.minecraft.metadata.MetaType; + +public interface MetaTypes { + + /** + * Returns the meta type by the given id. + * + * @param id type id + * @return meta type by id + * @throws IndexOutOfBoundsException if id is out of bounds + */ + MetaType byId(int id); + + /** + * Returns an array of meta types. + * + * @return array of meta types + */ + MetaType[] values(); +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13.java new file mode 100644 index 000000000..6b2c4b71a --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13.java @@ -0,0 +1,68 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2021 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.metadata.types; + +import com.viaversion.viaversion.api.minecraft.metadata.MetaType; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; + +public final class MetaTypes1_13 implements MetaTypes { + + private final MetaType[] values = new MetaType[16]; + public final MetaType byteType = add(0, Type.BYTE); + public final MetaType varIntType = add(1, Type.VAR_INT); + public final MetaType floatType = add(2, Type.FLOAT); + public final MetaType stringType = add(3, Type.STRING); + public final MetaType componentType = add(4, Type.COMPONENT); + public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT); + public final MetaType itemType = add(6, Type.FLAT_ITEM); + public final MetaType booleanType = add(7, Type.BOOLEAN); + public final MetaType rotationType = add(8, Type.ROTATION); + public final MetaType positionType = add(9, Type.POSITION); + public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION); + public final MetaType directionType = add(11, Type.VAR_INT); + public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID); + public final MetaType blockStateType = add(13, Type.VAR_INT); + public final MetaType nbtType = add(14, Type.NBT); + public final MetaType particleType; + + public MetaTypes1_13(final ParticleType particleType) { + this.particleType = add(15, particleType); + } + + @Override + public MetaType byId(final int id) { + return values[id]; + } + + @Override + public MetaType[] values() { + return values; + } + + private MetaType add(final int typeId, final Type type) { + final MetaType metaType = MetaType.create(typeId, type); + values[typeId] = metaType; + return metaType; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13_2.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13_2.java new file mode 100644 index 000000000..4495568ce --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_13_2.java @@ -0,0 +1,68 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2021 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.metadata.types; + +import com.viaversion.viaversion.api.minecraft.metadata.MetaType; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; + +public final class MetaTypes1_13_2 implements MetaTypes { + + private final MetaType[] values = new MetaType[16]; + public final MetaType byteType = add(0, Type.BYTE); + public final MetaType varIntType = add(1, Type.VAR_INT); + public final MetaType floatType = add(2, Type.FLOAT); + public final MetaType stringType = add(3, Type.STRING); + public final MetaType componentType = add(4, Type.COMPONENT); + public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT); + public final MetaType itemType = add(6, Type.FLAT_VAR_INT_ITEM); + public final MetaType booleanType = add(7, Type.BOOLEAN); + public final MetaType rotationType = add(8, Type.ROTATION); + public final MetaType positionType = add(9, Type.POSITION); + public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION); + public final MetaType directionType = add(11, Type.VAR_INT); + public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID); + public final MetaType blockStateType = add(13, Type.VAR_INT); + public final MetaType nbtType = add(14, Type.NBT); + public final MetaType particleType; + + public MetaTypes1_13_2(final ParticleType particleType) { + this.particleType = add(15, particleType); + } + + @Override + public MetaType byId(final int id) { + return values[id]; + } + + @Override + public MetaType[] values() { + return values; + } + + private MetaType add(final int typeId, final Type type) { + final MetaType metaType = MetaType.create(typeId, type); + values[typeId] = metaType; + return metaType; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_14.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_14.java new file mode 100644 index 000000000..47b12ea4e --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_14.java @@ -0,0 +1,71 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2021 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.minecraft.metadata.types; + +import com.viaversion.viaversion.api.minecraft.metadata.MetaType; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; + +public final class MetaTypes1_14 implements MetaTypes { + + private final MetaType[] values = new MetaType[19]; + public final MetaType byteType = add(0, Type.BYTE); + public final MetaType varIntType = add(1, Type.VAR_INT); + public final MetaType floatType = add(2, Type.FLOAT); + public final MetaType stringType = add(3, Type.STRING); + public final MetaType componentType = add(4, Type.COMPONENT); + public final MetaType optionalComponentType = add(5, Type.OPTIONAL_COMPONENT); + public final MetaType itemType = add(6, Type.FLAT_VAR_INT_ITEM); + public final MetaType booleanType = add(7, Type.BOOLEAN); + public final MetaType rotationType = add(8, Type.ROTATION); + public final MetaType positionType = add(9, Type.POSITION1_14); + public final MetaType optionalPositionType = add(10, Type.OPTIONAL_POSITION_1_14); + public final MetaType directionType = add(11, Type.VAR_INT); + public final MetaType optionalUUIDType = add(12, Type.OPTIONAL_UUID); + public final MetaType blockStateType = add(13, Type.VAR_INT); + public final MetaType nbtType = add(14, Type.NBT); + public final MetaType particleType; + public final MetaType villagerDatatType = add(16, Type.VILLAGER_DATA); + public final MetaType optionalVarIntType = add(17, Type.OPTIONAL_VAR_INT); + public final MetaType poseType = add(18, Type.VAR_INT); + + public MetaTypes1_14(final ParticleType particleType) { + this.particleType = add(15, particleType); + } + + @Override + public MetaType byId(final int id) { + return values[id]; + } + + @Override + public MetaType[] values() { + return values; + } + + private MetaType add(final int typeId, final Type type) { + final MetaType metaType = MetaType.create(typeId, type); + values[typeId] = metaType; + return metaType; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/Particle.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/Particle.java index 9b048f510..4d89b4c37 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/Particle.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/Particle.java @@ -24,12 +24,13 @@ package com.viaversion.viaversion.api.type.types; import com.viaversion.viaversion.api.type.Type; +import java.util.ArrayList; import java.util.LinkedList; import java.util.List; public class Particle { + private List arguments = new ArrayList<>(4); private int id; - private List arguments = new LinkedList<>(); public Particle(int id) { this.id = id; @@ -47,10 +48,15 @@ public class Particle { return arguments; } + @Deprecated/*(forRemoval = true)*/ public void setArguments(List arguments) { this.arguments = arguments; } + public void add(Type type, T value) { + arguments.add(new ParticleData(type, value)); + } + public static class ParticleData { private Type type; private Object value; diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/AbstractParticleType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/AbstractParticleType.java index f08978b6a..ed7d5fdf5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/AbstractParticleType.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/AbstractParticleType.java @@ -31,6 +31,7 @@ import io.netty.buffer.ByteBuf; import it.unimi.dsi.fastutil.ints.Int2ObjectMap; import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap; +@Deprecated/*(forRemoval = true)*/ public abstract class AbstractParticleType extends Type { protected final Int2ObjectMap readers = new Int2ObjectOpenHashMap<>(); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_13Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_13Type.java index 7c76d9d03..2fa7bf926 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_13Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_13Type.java @@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types.minecraft; import com.viaversion.viaversion.api.type.Type; +@Deprecated/*(forRemoval = true)*/ public class Particle1_13Type extends AbstractParticleType { public Particle1_13Type() { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_13_2Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_13_2Type.java index 57d832c10..f8f0d4e4e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_13_2Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_13_2Type.java @@ -26,6 +26,7 @@ import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.Particle; import io.netty.buffer.ByteBuf; +@Deprecated/*(forRemoval = true)*/ public class Particle1_13_2Type extends Type { public Particle1_13_2Type() { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_14Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_14Type.java index ebeb5e1a5..d40a892f6 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_14Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_14Type.java @@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types.minecraft; import com.viaversion.viaversion.api.type.Type; +@Deprecated/*(forRemoval = true)*/ public class Particle1_14Type extends AbstractParticleType { public Particle1_14Type() { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_16Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_16Type.java index a0dc6698a..a75eed538 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_16Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_16Type.java @@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types.minecraft; import com.viaversion.viaversion.api.type.Type; +@Deprecated/*(forRemoval = true)*/ public class Particle1_16Type extends AbstractParticleType { public Particle1_16Type() { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_17Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_17Type.java index 595b7dfe9..2ae9d7b32 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_17Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_17Type.java @@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types.minecraft; import com.viaversion.viaversion.api.type.Type; +@Deprecated/*(forRemoval = true)*/ public class Particle1_17Type extends AbstractParticleType { public Particle1_17Type() { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_18Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_18Type.java index 96f4d00de..d3d3e48e1 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_18Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/Particle1_18Type.java @@ -24,6 +24,7 @@ package com.viaversion.viaversion.api.type.types.minecraft; import com.viaversion.viaversion.api.type.Type; +@Deprecated/*(forRemoval = true)*/ public class Particle1_18Type extends AbstractParticleType { public Particle1_18Type() { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ParticleType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ParticleType.java new file mode 100644 index 000000000..f34230dfa --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/ParticleType.java @@ -0,0 +1,143 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2021 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.type.types.minecraft; + +import com.viaversion.viaversion.api.Via; +import com.viaversion.viaversion.api.data.ParticleMappings; +import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.protocol.Protocol; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.Particle; +import io.netty.buffer.ByteBuf; +import it.unimi.dsi.fastutil.ints.Int2ObjectArrayMap; +import it.unimi.dsi.fastutil.ints.Int2ObjectMap; + +public class ParticleType extends Type { + + private final Int2ObjectMap readers; + + public ParticleType(final Int2ObjectMap readers) { + super("Particle", Particle.class); + this.readers = readers; + } + + public ParticleType() { + this(new Int2ObjectArrayMap<>()); + } + + public ParticleTypeFiller filler(final Protocol protocol) { + return this.new ParticleTypeFiller(protocol); + } + + @Override + public void write(final ByteBuf buffer, final Particle object) throws Exception { + Type.VAR_INT.writePrimitive(buffer, object.getId()); + for (final Particle.ParticleData data : object.getArguments()) { + data.getType().write(buffer, data.getValue()); + } + } + + @Override + public Particle read(final ByteBuf buffer) throws Exception { + final int type = Type.VAR_INT.readPrimitive(buffer); + final Particle particle = new Particle(type); + + final ParticleReader reader = readers.get(type); + if (reader != null) { + reader.read(buffer, particle); + } + return particle; + } + + public static ParticleReader itemHandler(final Type itemType) { + return (buf, particle) -> particle.add(itemType, itemType.read(buf)); + } + + public static final class Readers { + + public static final ParticleReader BLOCK = (buf, particle) -> { + particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Flat Block + }; + public static final ParticleReader ITEM = itemHandler(Type.FLAT_ITEM); + public static final ParticleReader VAR_INT_ITEM = itemHandler(Type.FLAT_VAR_INT_ITEM); + public static final ParticleReader DUST = (buf, particle) -> { + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Red 0-1 + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green 0-1 + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue 0-1 + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Scale 0.01-4 + }; + public static final ParticleReader DUST_TRANSITION = (buf, particle) -> { + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Red 0-1 + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green 0-1 + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue 0-1 + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Scale 0.01-4 + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Red + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Green + particle.add(Type.FLOAT, Type.FLOAT.readPrimitive(buf)); // Blue + }; + public static final ParticleReader VIBRATION = (buf, particle) -> { + particle.add(Type.POSITION1_14, Type.POSITION1_14.read(buf)); // From block pos + final String resourceLocation = Type.STRING.read(buf); + if (resourceLocation.equals("block")) { + particle.add(Type.POSITION1_14, Type.POSITION1_14.read(buf)); // Target block pos + } else if (resourceLocation.equals("entity")) { + particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Target entity + } else { + Via.getPlatform().getLogger().warning("Unknown vibration path position source type: " + resourceLocation); + } + particle.add(Type.VAR_INT, Type.VAR_INT.readPrimitive(buf)); // Arrival in ticks + }; + } + + public final class ParticleTypeFiller { + + private final ParticleMappings mappings; + + private ParticleTypeFiller(final Protocol protocol) { + this.mappings = protocol.getMappingData().getParticleMappings(); + } + + public ParticleTypeFiller reader(final String identifier, final ParticleReader reader) { + readers.put(mappings.id(identifier), reader); + return this; + } + + public ParticleTypeFiller reader(final int id, final ParticleReader reader) { + readers.put(id, reader); + return this; + } + } + + @FunctionalInterface + public interface ParticleReader { + + /** + * Reads particle data from the buffer and adds it to the particle data. + * + * @param buf buffer + * @param particle particle + * @throws Exception if an error occurs during buffer reading + */ + void read(ByteBuf buf, Particle particle) throws Exception; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_13Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_13Type.java index e268c9555..1e887b1f5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_13Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_13Type.java @@ -23,12 +23,12 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.metadata.MetaType; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_13; import com.viaversion.viaversion.api.type.types.minecraft.ModernMetaType; +@Deprecated/*(forRemoval = true)*/ public class Metadata1_13Type extends ModernMetaType { @Override protected MetaType getType(final int index) { - return MetaType1_13.byId(index); + return Types1_13.META_TYPES.byId(index); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_13_2Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_13_2Type.java index 2d722a1fe..a2ad4440a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_13_2Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_13_2Type.java @@ -23,12 +23,12 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.metadata.MetaType; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_13_2; import com.viaversion.viaversion.api.type.types.minecraft.ModernMetaType; +@Deprecated/*(forRemoval = true)*/ public class Metadata1_13_2Type extends ModernMetaType { @Override protected MetaType getType(final int index) { - return MetaType1_13_2.byId(index); + return Types1_13_2.META_TYPES.byId(index); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_14Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_14Type.java index 300a9a97e..fa6a489c0 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_14Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_14Type.java @@ -23,12 +23,12 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.metadata.MetaType; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14; import com.viaversion.viaversion.api.type.types.minecraft.ModernMetaType; +@Deprecated/*(forRemoval = true)*/ public class Metadata1_14Type extends ModernMetaType { @Override protected MetaType getType(final int index) { - return MetaType1_14.byId(index); + return Types1_14.META_TYPES.byId(index); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_16Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_16Type.java index 0bceb0dd9..3016f0d79 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_16Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_16Type.java @@ -23,13 +23,13 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.metadata.MetaType; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_16; import com.viaversion.viaversion.api.type.types.minecraft.ModernMetaType; +@Deprecated/*(forRemoval = true)*/ public class Metadata1_16Type extends ModernMetaType { @Override protected MetaType getType(final int index) { - return MetaType1_16.byId(index); + return Types1_16.META_TYPES.byId(index); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_17Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_17Type.java index c6526037a..471a8d645 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_17Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_17Type.java @@ -23,13 +23,13 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.metadata.MetaType; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_17; import com.viaversion.viaversion.api.type.types.minecraft.ModernMetaType; +@Deprecated/*(forRemoval = true)*/ public class Metadata1_17Type extends ModernMetaType { @Override protected MetaType getType(final int index) { - return MetaType1_17.byId(index); + return Types1_17.META_TYPES.byId(index); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_18Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_18Type.java index 01639dbee..4fde03bdd 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_18Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Metadata1_18Type.java @@ -23,13 +23,13 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.metadata.MetaType; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_18; import com.viaversion.viaversion.api.type.types.minecraft.ModernMetaType; +@Deprecated/*(forRemoval = true)*/ public class Metadata1_18Type extends ModernMetaType { @Override protected MetaType getType(final int index) { - return MetaType1_18.byId(index); + return Types1_18.META_TYPES.byId(index); } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/MetadataType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/MetadataType.java new file mode 100644 index 000000000..b4b41cf5f --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/MetadataType.java @@ -0,0 +1,41 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2021 ViaVersion and contributors + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ +package com.viaversion.viaversion.api.type.types.version; + +import com.viaversion.viaversion.api.minecraft.metadata.MetaType; +import com.viaversion.viaversion.api.minecraft.metadata.types.MetaTypes; +import com.viaversion.viaversion.api.type.types.minecraft.ModernMetaType; + +public final class MetadataType extends ModernMetaType { + + private final MetaTypes metaTypes; + + public MetadataType(final MetaTypes metaTypes) { + this.metaTypes = metaTypes; + } + + @Override + protected MetaType getType(final int index) { + return metaTypes.byId(index); + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_13.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_13.java index f392dc4c0..ed85a9d71 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_13.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_13.java @@ -24,27 +24,18 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; +import com.viaversion.viaversion.api.minecraft.metadata.types.MetaTypes1_13; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.Particle; import com.viaversion.viaversion.api.type.types.minecraft.MetaListType; -import com.viaversion.viaversion.api.type.types.minecraft.Particle1_13Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; import java.util.List; -public class Types1_13 { - /** - * Metadata type for 1.13 - */ - public static final Type METADATA = new Metadata1_13Type(); - /** - * Metadata list type for 1.13 - */ - public static final Type> METADATA_LIST = new MetaListType(METADATA); +public final class Types1_13 { public static final Type CHUNK_SECTION = new ChunkSectionType1_13(); - - /** - * Particle type for 1.13 - */ - public static final Type PARTICLE = new Particle1_13Type(); + public static final ParticleType PARTICLE = new ParticleType(); + public static final MetaTypes1_13 META_TYPES = new MetaTypes1_13(PARTICLE); + public static final Type METADATA = new MetadataType(META_TYPES); + public static final Type> METADATA_LIST = new MetaListType(METADATA); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_13_2.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_13_2.java index fdff3e099..6bbab1567 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_13_2.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_13_2.java @@ -23,26 +23,17 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; +import com.viaversion.viaversion.api.minecraft.metadata.types.MetaTypes1_13_2; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.Particle; import com.viaversion.viaversion.api.type.types.minecraft.MetaListType; -import com.viaversion.viaversion.api.type.types.minecraft.Particle1_13_2Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; import java.util.List; -public class Types1_13_2 { +public final class Types1_13_2 { - /** - * Metadata type for 1.13 - */ - public static final Type METADATA = new Metadata1_13_2Type(); - /** - * Metadata list type for 1.13 - */ + public static final ParticleType PARTICLE = new ParticleType(); + public static final MetaTypes1_13_2 META_TYPES = new MetaTypes1_13_2(PARTICLE); + public static final Type METADATA = new MetadataType(META_TYPES); public static final Type> METADATA_LIST = new MetaListType(METADATA); - - /** - * Particle type for 1.13.2 - */ - public static final Type PARTICLE = new Particle1_13_2Type(); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_14.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_14.java index 61bfe3f69..99fd96bf0 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_14.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_14.java @@ -23,26 +23,17 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; +import com.viaversion.viaversion.api.minecraft.metadata.types.MetaTypes1_14; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.Particle; import com.viaversion.viaversion.api.type.types.minecraft.MetaListType; -import com.viaversion.viaversion.api.type.types.minecraft.Particle1_14Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; import java.util.List; public final class Types1_14 { - /** - * Metadata type for 1.14 - */ - public static final Type METADATA = new Metadata1_14Type(); - /** - * Metadata list type for 1.14 - */ + public static final ParticleType PARTICLE = new ParticleType(); + public static final MetaTypes1_14 META_TYPES = new MetaTypes1_14(PARTICLE); + public static final Type METADATA = new MetadataType(META_TYPES); public static final Type> METADATA_LIST = new MetaListType(METADATA); - - /** - * Particle type for 1.14 - */ - public static final Type PARTICLE = new Particle1_14Type(); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_16.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_16.java index e54286556..c9bf9c29c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_16.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_16.java @@ -24,21 +24,18 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.chunks.ChunkSection; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; +import com.viaversion.viaversion.api.minecraft.metadata.types.MetaTypes1_14; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.Particle; import com.viaversion.viaversion.api.type.types.minecraft.MetaListType; -import com.viaversion.viaversion.api.type.types.minecraft.Particle1_16Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; import java.util.List; public final class Types1_16 { - /** - * Chunk section type for 1.16 - */ public static final Type CHUNK_SECTION = new ChunkSectionType1_16(); - - public static final Type METADATA = new Metadata1_16Type(); + public static final ParticleType PARTICLE = new ParticleType(); // Only safe to use after protocol loading + public static final MetaTypes1_14 META_TYPES = new MetaTypes1_14(PARTICLE); + public static final Type METADATA = new MetadataType(META_TYPES); public static final Type> METADATA_LIST = new MetaListType(METADATA); - public static final Type PARTICLE = new Particle1_16Type(); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_17.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_17.java index 1e60ced11..db8619ebf 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_17.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_17.java @@ -23,16 +23,17 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; +import com.viaversion.viaversion.api.minecraft.metadata.types.MetaTypes1_14; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.Particle; import com.viaversion.viaversion.api.type.types.minecraft.MetaListType; -import com.viaversion.viaversion.api.type.types.minecraft.Particle1_17Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; import java.util.List; public final class Types1_17 { - public static final Type METADATA = new Metadata1_17Type(); + public static final ParticleType PARTICLE = new ParticleType(); // Only safe to use after protocol loading + public static final MetaTypes1_14 META_TYPES = new MetaTypes1_14(PARTICLE); + public static final Type METADATA = new MetadataType(META_TYPES); public static final Type> METADATA_LIST = new MetaListType(METADATA); - public static final Type PARTICLE = new Particle1_17Type(); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_18.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_18.java index c9c4c8d08..c94b2978f 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_18.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_18.java @@ -24,17 +24,18 @@ package com.viaversion.viaversion.api.type.types.version; import com.viaversion.viaversion.api.minecraft.blockentity.BlockEntity; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; +import com.viaversion.viaversion.api.minecraft.metadata.types.MetaTypes1_14; import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.types.Particle; import com.viaversion.viaversion.api.type.types.minecraft.MetaListType; -import com.viaversion.viaversion.api.type.types.minecraft.Particle1_18Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; import java.util.List; public final class Types1_18 { public static final Type BLOCK_ENTITY = new BlockEntityType1_18(); - public static final Type METADATA = new Metadata1_18Type(); + public static final ParticleType PARTICLE = new ParticleType(); // Only safe to use after protocol loading + public static final MetaTypes1_14 META_TYPES = new MetaTypes1_14(PARTICLE); + public static final Type METADATA = new MetadataType(META_TYPES); public static final Type> METADATA_LIST = new MetaListType(METADATA); - public static final Type PARTICLE = new Particle1_18Type(); } diff --git a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_15to1_14_4/EntityToggleGlideListener.java b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_15to1_14_4/EntityToggleGlideListener.java index 031c61669..4ae22537d 100644 --- a/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_15to1_14_4/EntityToggleGlideListener.java +++ b/bukkit/src/main/java/com/viaversion/viaversion/bukkit/listeners/protocol1_15to1_14_4/EntityToggleGlideListener.java @@ -19,7 +19,6 @@ package com.viaversion.viaversion.bukkit.listeners.protocol1_15to1_14_4; import com.viaversion.viaversion.ViaVersionPlugin; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14; import com.viaversion.viaversion.api.protocol.packet.PacketWrapper; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.version.Types1_14; @@ -83,7 +82,7 @@ public class EntityToggleGlideListener extends ViaBukkitListener { } // leave 0x80 as 0 to stop gliding - packet.write(Types1_14.METADATA_LIST, Arrays.asList(new Metadata(0, MetaType1_14.Byte, bitmask))); + packet.write(Types1_14.METADATA_LIST, Arrays.asList(new Metadata(0, Types1_14.META_TYPES.byteType, bitmask))); packet.scheduleSend(Protocol1_15To1_14_4.class); } catch (Exception e) { e.printStackTrace(); 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 cbb989300..9ed5a7971 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 @@ -22,8 +22,8 @@ import com.viaversion.viaversion.api.minecraft.entities.Entity1_13Types; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_13; import com.viaversion.viaversion.api.type.types.Particle; +import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.protocols.protocol1_13_1to1_13.Protocol1_13_1To1_13; import com.viaversion.viaversion.rewriter.EntityRewriter; @@ -38,13 +38,13 @@ public class MetadataRewriter1_13_1To1_13 extends EntityRewriter metadatas, UserConnection connection) { // 1.13 changed item to flat item (no data) - if (metadata.metaType() == MetaType1_13.Slot) { + if (metadata.metaType() == Types1_13.META_TYPES.itemType) { protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue()); - } else if (metadata.metaType() == MetaType1_13.BlockID) { + } else if (metadata.metaType() == Types1_13.META_TYPES.blockStateType) { // Convert to new block id int data = (int) metadata.getValue(); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); - } else if (metadata.metaType() == MetaType1_13.PARTICLE) { + } else if (metadata.metaType() == Types1_13.META_TYPES.particleType) { rewriteParticle((Particle) metadata.getValue()); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java index 555460472..852641636 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13_2to1_13_1/packets/EntityPackets.java @@ -18,7 +18,6 @@ package com.viaversion.viaversion.protocols.protocol1_13_2to1_13_1.packets; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_13_2; import com.viaversion.viaversion.api.protocol.Protocol; import com.viaversion.viaversion.api.protocol.remapper.PacketHandler; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; @@ -32,7 +31,7 @@ public class EntityPackets { public static void register(Protocol protocol) { final PacketHandler metaTypeHandler = wrapper -> { for (Metadata metadata : wrapper.get(Types1_13_2.METADATA_LIST, 0)) { - metadata.setMetaType(MetaType1_13_2.byId(metadata.metaType().typeId())); + metadata.setMetaType(Types1_13_2.META_TYPES.byId(metadata.metaType().typeId())); } }; diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java index 4852653c7..10c77d3e5 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_13to1_12_2/Protocol1_13To1_12_2.java @@ -37,6 +37,8 @@ import com.viaversion.viaversion.api.protocol.remapper.ValueTransformer; import com.viaversion.viaversion.api.rewriter.EntityRewriter; import com.viaversion.viaversion.api.rewriter.ItemRewriter; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; +import com.viaversion.viaversion.api.type.types.version.Types1_13; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ClientboundPackets1_12_1; import com.viaversion.viaversion.protocols.protocol1_12_1to1_12.ServerboundPackets1_12_1; @@ -1037,6 +1039,12 @@ public class Protocol1_13To1_12_2 extends AbstractProtocol metadatas, UserConnection connection) throws Exception { // Handle new MetaTypes if (metadata.metaType().typeId() > 4) { - metadata.setMetaType(MetaType1_13.byId(metadata.metaType().typeId() + 1)); + metadata.setMetaType(Types1_13.META_TYPES.byId(metadata.metaType().typeId() + 1)); } else { - metadata.setMetaType(MetaType1_13.byId(metadata.metaType().typeId())); + metadata.setMetaType(Types1_13.META_TYPES.byId(metadata.metaType().typeId())); } // Handle String -> Chat DisplayName if (metadata.id() == 2) { if (metadata.getValue() != null && !((String) metadata.getValue()).isEmpty()) { - metadata.setTypeAndValue(MetaType1_13.OptChat, ChatRewriter.legacyTextToJson((String) metadata.getValue())); + metadata.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, ChatRewriter.legacyTextToJson((String) metadata.getValue())); } else { - metadata.setTypeAndValue(MetaType1_13.OptChat, null); + metadata.setTypeAndValue(Types1_13.META_TYPES.optionalComponentType, null); } } @@ -66,10 +66,10 @@ public class MetadataRewriter1_13To1_12_2 extends EntityRewriter metadatas, UserConnection connection) throws Exception { - metadata.setMetaType(MetaType1_14.byId(metadata.metaType().typeId())); + metadata.setMetaType(Types1_14.META_TYPES.byId(metadata.metaType().typeId())); EntityTracker1_14 tracker = tracker(connection); - if (metadata.metaType() == MetaType1_14.Slot) { + if (metadata.metaType() == Types1_14.META_TYPES.itemType) { protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue()); - } else if (metadata.metaType() == MetaType1_14.BlockID) { + } else if (metadata.metaType() == Types1_14.META_TYPES.blockStateType) { // Convert to new block id int data = (int) metadata.getValue(); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); - } else if (metadata.metaType() == MetaType1_14.PARTICLE) { + } else if (metadata.metaType() == Types1_14.META_TYPES.particleType) { rewriteParticle((Particle) metadata.getValue()); } @@ -97,7 +97,7 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter 16) { metadata.setId(metadata.id() - 1); } @@ -140,12 +140,12 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter= 9) { // New piercing @@ -153,7 +153,7 @@ public class MetadataRewriter1_14To1_13_2 extends EntityRewriter metadataList = new LinkedList<>(); if (tracker.clientEntityId() != entityId) { - metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker))); + metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker))); } - metadataList.add(new Metadata(12, MetaType1_14.OptPosition, null)); + metadataList.add(new Metadata(12, Types1_14.META_TYPES.optionalPositionType, null)); metadataPacket.write(Types1_14.METADATA_LIST, metadataList); metadataPacket.scheduleSend(Protocol1_14To1_13_2.class); } @@ -209,9 +208,9 @@ public class EntityPackets { Position position = wrapper.read(Type.POSITION); List metadataList = new LinkedList<>(); - metadataList.add(new Metadata(12, MetaType1_14.OptPosition, position)); + metadataList.add(new Metadata(12, Types1_14.META_TYPES.optionalPositionType, position)); if (tracker.clientEntityId() != entityId) { - metadataList.add(new Metadata(6, MetaType1_14.Pose, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker))); + metadataList.add(new Metadata(6, Types1_14.META_TYPES.poseType, MetadataRewriter1_14To1_13_2.recalculatePlayerPose(entityId, tracker))); } wrapper.write(Types1_14.METADATA_LIST, metadataList); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/metadata/MetadataRewriter1_15To1_14_4.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/metadata/MetadataRewriter1_15To1_14_4.java index dc1a3b9e6..2e5c6b8f9 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/metadata/MetadataRewriter1_15To1_14_4.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_15to1_14_4/metadata/MetadataRewriter1_15To1_14_4.java @@ -22,9 +22,8 @@ import com.viaversion.viaversion.api.minecraft.entities.Entity1_15Types; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_13; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_14; import com.viaversion.viaversion.api.type.types.Particle; +import com.viaversion.viaversion.api.type.types.version.Types1_14; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.Protocol1_15To1_14_4; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.packets.EntityPackets; import com.viaversion.viaversion.rewriter.EntityRewriter; @@ -39,13 +38,13 @@ public class MetadataRewriter1_15To1_14_4 extends EntityRewriter metadatas, UserConnection connection) throws Exception { - if (metadata.metaType() == MetaType1_14.Slot) { + if (metadata.metaType() == Types1_14.META_TYPES.itemType) { protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue()); - } else if (metadata.metaType() == MetaType1_14.BlockID) { + } else if (metadata.metaType() == Types1_14.META_TYPES.blockStateType) { // Convert to new block id int data = (int) metadata.getValue(); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); - } else if (metadata.metaType() == MetaType1_13.PARTICLE) { + } else if (metadata.metaType() == Types1_14.META_TYPES.particleType) { rewriteParticle((Particle) metadata.getValue()); } 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 8bf9a6226..788388281 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 @@ -23,8 +23,8 @@ import com.viaversion.viaversion.api.minecraft.entities.Entity1_16_2Types; import com.viaversion.viaversion.api.minecraft.entities.EntityType; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.metadata.Metadata; -import com.viaversion.viaversion.api.minecraft.metadata.types.MetaType1_16; import com.viaversion.viaversion.api.type.types.Particle; +import com.viaversion.viaversion.api.type.types.version.Types1_16; import com.viaversion.viaversion.protocols.protocol1_16_2to1_16_1.Protocol1_16_2To1_16_1; import com.viaversion.viaversion.rewriter.EntityRewriter; @@ -39,12 +39,12 @@ public class MetadataRewriter1_16_2To1_16_1 extends EntityRewriter metadatas, UserConnection connection) throws Exception { - if (metadata.metaType() == MetaType1_16.ITEM) { + if (metadata.metaType() == Types1_16.META_TYPES.itemType) { protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue()); - } else if (metadata.metaType() == MetaType1_16.BLOCK_STATE) { + } else if (metadata.metaType() == Types1_16.META_TYPES.blockStateType) { int data = (int) metadata.getValue(); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); - } else if (metadata.metaType() == MetaType1_16.PARTICLE) { + } else if (metadata.metaType() == Types1_16.META_TYPES.particleType) { rewriteParticle((Particle) metadata.getValue()); } diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java index 5c45d7969..159bb36e2 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_16to1_15_2/Protocol1_16To1_15_2.java @@ -23,6 +23,7 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.viaversion.viaversion.api.Via; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.RegistryType; import com.viaversion.viaversion.api.minecraft.entities.Entity1_16Types; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.State; @@ -30,6 +31,8 @@ import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.rewriter.EntityRewriter; import com.viaversion.viaversion.api.rewriter.ItemRewriter; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; +import com.viaversion.viaversion.api.type.types.version.Types1_16; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.protocol1_14to1_13_2.ServerboundPackets1_14; import com.viaversion.viaversion.protocols.protocol1_15to1_14_4.ClientboundPackets1_15; @@ -41,7 +44,6 @@ import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.Inventor import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.packets.WorldPackets; import com.viaversion.viaversion.protocols.protocol1_16to1_15_2.storage.InventoryTracker1_16; import com.viaversion.viaversion.rewriter.ComponentRewriter; -import com.viaversion.viaversion.api.minecraft.RegistryType; import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; @@ -271,6 +273,12 @@ public class Protocol1_16To1_15_2 extends AbstractProtocol metadatas, UserConnection connection) throws Exception { - metadata.setMetaType(MetaType1_16.byId(metadata.metaType().typeId())); - if (metadata.metaType() == MetaType1_16.ITEM) { + metadata.setMetaType(Types1_16.META_TYPES.byId(metadata.metaType().typeId())); + if (metadata.metaType() == Types1_16.META_TYPES.itemType) { protocol.getItemRewriter().handleItemToClient((Item) metadata.getValue()); - } else if (metadata.metaType() == MetaType1_16.BLOCK_STATE) { + } else if (metadata.metaType() == Types1_16.META_TYPES.blockStateType) { int data = (int) metadata.getValue(); metadata.setValue(protocol.getMappingData().getNewBlockStateId(data)); - } else if (metadata.metaType() == MetaType1_16.PARTICLE) { + } else if (metadata.metaType() == Types1_16.META_TYPES.particleType) { rewriteParticle((Particle) metadata.getValue()); } @@ -71,7 +71,7 @@ public class MetadataRewriter1_16To1_15_2 extends EntityRewriter { @Override protected void registerRewrites() { filter().handler((event, meta) -> { - meta.setMetaType(MetaType1_17.byId(meta.metaType().typeId())); + meta.setMetaType(Types1_17.META_TYPES.byId(meta.metaType().typeId())); - if (meta.metaType() == MetaType1_17.POSE) { + if (meta.metaType() == Types1_17.META_TYPES.poseType) { int pose = meta.value(); if (pose > 5) { // Added LONG_JUMP at 6 @@ -138,7 +137,7 @@ public final class EntityPackets extends EntityRewriter { } } }); - registerMetaTypeHandler(MetaType1_17.ITEM, MetaType1_17.BLOCK_STATE, MetaType1_17.PARTICLE); + registerMetaTypeHandler(Types1_17.META_TYPES.itemType, Types1_17.META_TYPES.blockStateType, Types1_17.META_TYPES.particleType); // Ticks frozen added with id 7 filter().filterFamily(Entity1_17Types.ENTITY).addIndex(7); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/Protocol1_18To1_17_1.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/Protocol1_18To1_17_1.java index 425a8c5d9..eb15cf271 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/Protocol1_18To1_17_1.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/Protocol1_18To1_17_1.java @@ -23,6 +23,8 @@ import com.viaversion.viaversion.api.minecraft.entities.Entity1_17Types; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.remapper.PacketRemapper; import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; +import com.viaversion.viaversion.api.type.types.version.Types1_18; import com.viaversion.viaversion.data.entity.EntityTrackerBase; import com.viaversion.viaversion.protocols.protocol1_17_1to1_17.ClientboundPackets1_17_1; import com.viaversion.viaversion.protocols.protocol1_17to1_16_4.ServerboundPackets1_17; @@ -70,6 +72,18 @@ public final class Protocol1_18To1_17_1 extends AbstractProtocol { @Override protected void registerRewrites() { filter().handler((event, meta) -> { - meta.setMetaType(MetaType1_18.byId(meta.metaType().typeId())); - if (meta.metaType() == MetaType1_18.PARTICLE) { + meta.setMetaType(Types1_18.META_TYPES.byId(meta.metaType().typeId())); + if (meta.metaType() == Types1_18.META_TYPES.particleType) { Particle particle = (Particle) meta.getValue(); if (particle.getId() == 2) { // Barrier particle.setId(3); // Block marker @@ -102,7 +101,7 @@ public final class EntityPackets extends EntityRewriter { } }); - registerMetaTypeHandler(MetaType1_18.ITEM, null, null); + registerMetaTypeHandler(Types1_18.META_TYPES.itemType, null, null); /*filter().filterFamily(Entity1_17Types.MINECART_ABSTRACT).index(11).handler((event, meta) -> { //TODO check id // Convert to new block id diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/packets/InventoryPackets.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/packets/InventoryPackets.java index f9d46fd70..5cd2fbd33 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/packets/InventoryPackets.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_18to1_17_1/packets/InventoryPackets.java @@ -66,10 +66,10 @@ public final class InventoryPackets extends ItemRewriter { } ParticleMappings mappings = protocol.getMappingData().getParticleMappings(); - if (id == mappings.getBlockId() || id == mappings.getFallingDustId()) { + if (mappings.isBlockParticle(id)) { int data = wrapper.passthrough(Type.VAR_INT); wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data)); - } else if (id == mappings.getItemId()) { + } else if (mappings.isItemParticle(id)) { handleItemToClient(wrapper.passthrough(Type.FLAT_VAR_INT_ITEM)); } 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 d22c24a67..4435beb6f 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/EntityRewriter.java @@ -479,11 +479,10 @@ public abstract class EntityRewriter extends RewriterBase protected void rewriteParticle(Particle particle) { ParticleMappings mappings = protocol.getMappingData().getParticleMappings(); int id = particle.getId(); - if (id == mappings.getBlockId() || id == mappings.getFallingDustId() - || (mappings.getBlockmarkerid() != -1 && id == mappings.getBlockmarkerid())) { + if (mappings.isBlockParticle(id)) { Particle.ParticleData data = particle.getArguments().get(0); data.setValue(protocol.getMappingData().getNewBlockStateId(data.get())); - } else if (id == mappings.getItemId()) { + } else if (mappings.isItemParticle(id)) { Particle.ParticleData data = particle.getArguments().get(0); data.setValue(protocol.getMappingData().getNewItemId(data.get())); } diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java index 18ae148a2..10a7d9d26 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java @@ -329,10 +329,10 @@ public abstract class ItemRewriter extends RewriterBase i if (id == -1) return; ParticleMappings mappings = protocol.getMappingData().getParticleMappings(); - if (id == mappings.getBlockId() || id == mappings.getFallingDustId()) { + if (mappings.isBlockParticle(id)) { int data = wrapper.passthrough(Type.VAR_INT); wrapper.set(Type.VAR_INT, 0, protocol.getMappingData().getNewBlockStateId(data)); - } else if (id == mappings.getItemId()) { + } else if (mappings.isItemParticle(id)) { handleItemToClient(wrapper.passthrough(itemType)); }