From dd189411e6074e39469f5c8750fb6100533eb81c Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Wed, 6 Apr 2022 20:16:00 +0200 Subject: [PATCH] New meta types (oh no) --- .../api/minecraft/GlobalPosition.java | 83 +++++++++++++++++++ .../metadata/types/MetaTypes1_19.java | 58 +++++++++++++ .../viaversion/viaversion/api/type/Type.java | 3 + .../minecraft/OptionalGlobalPositionType.java | 48 +++++++++++ .../api/type/types/version/Types1_19.java | 4 +- .../packets/EntityPackets.java | 1 + 6 files changed, 195 insertions(+), 2 deletions(-) create mode 100644 api/src/main/java/com/viaversion/viaversion/api/minecraft/GlobalPosition.java create mode 100644 api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_19.java create mode 100644 api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/OptionalGlobalPositionType.java diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/GlobalPosition.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/GlobalPosition.java new file mode 100644 index 000000000..c7790ef64 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/GlobalPosition.java @@ -0,0 +1,83 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2022 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; + +public final class GlobalPosition { + private final String dimension; + private final int x; + private final int y; + private final int z; + + public GlobalPosition(final String dimension, final int x, final int y, final int z) { + this.dimension = dimension; + this.x = x; + this.y = y; + this.z = z; + } + + public int x() { + return x; + } + + public int y() { + return y; + } + + public int z() { + return z; + } + + public String dimension() { + return dimension; + } + + @Override + public boolean equals(final Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + final GlobalPosition position = (GlobalPosition) o; + if (x != position.x) return false; + if (y != position.y) return false; + if (z != position.z) return false; + return dimension.equals(position.dimension); + } + + @Override + public int hashCode() { + int result = dimension.hashCode(); + result = 31 * result + x; + result = 31 * result + y; + result = 31 * result + z; + return result; + } + + @Override + public String toString() { + return "GlobalPosition{" + + "dimension='" + dimension + '\'' + + ", x=" + x + + ", y=" + y + + ", z=" + z + + '}'; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_19.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_19.java new file mode 100644 index 000000000..de893883c --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/metadata/types/MetaTypes1_19.java @@ -0,0 +1,58 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2022 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_19 extends AbstractMetaTypes { + + 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 final MetaType catVariantType = add(19, Type.VAR_INT); + public final MetaType frogVariantType = add(20, Type.VAR_INT); + public final MetaType optionalGlobalPosition = add(21, Type.OPTIONAL_GLOBAL_POSITION); + + public MetaTypes1_19(final ParticleType particleType) { + super(22); + this.particleType = add(15, particleType); + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java index 5986c39f8..6423c3267 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/Type.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/Type.java @@ -27,6 +27,7 @@ import com.github.steveice10.opennbt.tag.builtin.CompoundTag; import com.google.gson.JsonElement; import com.viaversion.viaversion.api.minecraft.BlockChangeRecord; import com.viaversion.viaversion.api.minecraft.EulerAngle; +import com.viaversion.viaversion.api.minecraft.GlobalPosition; import com.viaversion.viaversion.api.minecraft.Position; import com.viaversion.viaversion.api.minecraft.Vector; import com.viaversion.viaversion.api.minecraft.VillagerData; @@ -66,6 +67,7 @@ import com.viaversion.viaversion.api.type.types.minecraft.OptPosition1_14Type; import com.viaversion.viaversion.api.type.types.minecraft.OptPositionType; import com.viaversion.viaversion.api.type.types.minecraft.OptUUIDType; import com.viaversion.viaversion.api.type.types.minecraft.OptionalComponentType; +import com.viaversion.viaversion.api.type.types.minecraft.OptionalGlobalPositionType; import com.viaversion.viaversion.api.type.types.minecraft.OptionalVarIntType; import com.viaversion.viaversion.api.type.types.minecraft.Position1_14Type; import com.viaversion.viaversion.api.type.types.minecraft.PositionType; @@ -154,6 +156,7 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public static final Type OPTIONAL_POSITION = new OptPositionType(); public static final Type OPTIONAL_POSITION_1_14 = new OptPosition1_14Type(); + public static final Type OPTIONAL_GLOBAL_POSITION = new OptionalGlobalPositionType(); public static final Type BLOCK_CHANGE_RECORD = new BlockChangeRecordType(); public static final Type BLOCK_CHANGE_RECORD_ARRAY = new ArrayType<>(Type.BLOCK_CHANGE_RECORD); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/OptionalGlobalPositionType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/OptionalGlobalPositionType.java new file mode 100644 index 000000000..aa4c423b4 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/minecraft/OptionalGlobalPositionType.java @@ -0,0 +1,48 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2022 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.minecraft.GlobalPosition; +import com.viaversion.viaversion.api.type.Type; +import io.netty.buffer.ByteBuf; + +public class OptionalGlobalPositionType extends Type { + + public OptionalGlobalPositionType() { + super(GlobalPosition.class); + } + + @Override + public GlobalPosition read(ByteBuf buffer) throws Exception { + boolean present = buffer.readBoolean(); + return present ? Type.OPTIONAL_GLOBAL_POSITION.read(buffer) : null; + } + + @Override + public void write(ByteBuf buffer, GlobalPosition object) throws Exception { + buffer.writeBoolean(object != null); + if (object != null) { + Type.OPTIONAL_GLOBAL_POSITION.write(buffer, object); + } + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_19.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_19.java index 871eb42a9..24e0d2151 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_19.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_19.java @@ -23,7 +23,7 @@ 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.minecraft.metadata.types.MetaTypes1_19; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.minecraft.MetaListType; import com.viaversion.viaversion.api.type.types.minecraft.ParticleType; @@ -33,7 +33,7 @@ import java.util.List; public final class Types1_19 { 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 MetaTypes1_19 META_TYPES = new MetaTypes1_19(PARTICLE); public static final Type METADATA = new MetadataType(META_TYPES); public static final Type> METADATA_LIST = new MetaListType(METADATA); } 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 324f828df..2fc64500c 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 @@ -141,6 +141,7 @@ public final class EntityPackets extends EntityRewriter { }); filter().type(Entity1_19Types.PLAYER).addIndex(19); // Last death location + filter().type(Entity1_19Types.CAT).index(19).handler((event, meta) -> meta.setMetaType(Types1_19.META_TYPES.catVariantType)); } @Override