diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java index 0808cbecd..dcf6d7af5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataKey.java @@ -36,6 +36,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.BannerPatternLayer; import com.viaversion.viaversion.api.minecraft.item.data.Bee; import com.viaversion.viaversion.api.minecraft.item.data.BlockStateProperties; import com.viaversion.viaversion.api.minecraft.item.data.Consumable1_21_2; +import com.viaversion.viaversion.api.minecraft.item.data.CustomModelData1_21_4; import com.viaversion.viaversion.api.minecraft.item.data.DamageResistant; import com.viaversion.viaversion.api.minecraft.item.data.DeathProtection; import com.viaversion.viaversion.api.minecraft.item.data.DyedColor; @@ -63,6 +64,7 @@ import com.viaversion.viaversion.api.type.types.ArrayType; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.api.type.types.version.Types1_21; import com.viaversion.viaversion.api.type.types.version.Types1_21_2; +import com.viaversion.viaversion.api.type.types.version.Types1_21_4; import com.viaversion.viaversion.util.Unit; public record StructuredDataKey(String identifier, Type type) { @@ -82,7 +84,8 @@ public record StructuredDataKey(String identifier, Type type) { public static final StructuredDataKey CAN_BREAK = new StructuredDataKey<>("can_break", AdventureModePredicate.TYPE); public static final StructuredDataKey ATTRIBUTE_MODIFIERS1_20_5 = new StructuredDataKey<>("attribute_modifiers", AttributeModifiers1_20_5.TYPE); public static final StructuredDataKey ATTRIBUTE_MODIFIERS1_21 = new StructuredDataKey<>("attribute_modifiers", AttributeModifiers1_21.TYPE); - public static final StructuredDataKey CUSTOM_MODEL_DATA = new StructuredDataKey<>("custom_model_data", Types.VAR_INT); + public static final StructuredDataKey CUSTOM_MODEL_DATA1_20_5 = new StructuredDataKey<>("custom_model_data", Types.VAR_INT); + public static final StructuredDataKey CUSTOM_MODEL_DATA1_21_2 = new StructuredDataKey<>("custom_model_data", CustomModelData1_21_4.TYPE); public static final StructuredDataKey HIDE_ADDITIONAL_TOOLTIP = new StructuredDataKey<>("hide_additional_tooltip", Types.EMPTY); public static final StructuredDataKey HIDE_TOOLTIP = new StructuredDataKey<>("hide_tooltip", Types.EMPTY); public static final StructuredDataKey REPAIR_COST = new StructuredDataKey<>("repair_cost", Types.VAR_INT); @@ -93,7 +96,8 @@ public record StructuredDataKey(String identifier, Type type) { public static final StructuredDataKey FOOD1_21 = new StructuredDataKey<>("food", FoodProperties1_20_5.TYPE1_21); public static final StructuredDataKey FOOD1_21_2 = new StructuredDataKey<>("food", FoodProperties1_21_2.TYPE); public static final StructuredDataKey CONSUMABLE1_21_2 = new StructuredDataKey<>("consumable", Consumable1_21_2.TYPE); - public static final StructuredDataKey USE_REMAINDER = new StructuredDataKey<>("use_remainder", Types1_21_2.ITEM); + public static final StructuredDataKey USE_REMAINDER1_21_2 = new StructuredDataKey<>("use_remainder", Types1_21_2.ITEM); + public static final StructuredDataKey USE_REMAINDER1_21_4 = new StructuredDataKey<>("use_remainder", Types1_21_4.ITEM); public static final StructuredDataKey USE_COOLDOWN = new StructuredDataKey<>("use_cooldown", UseCooldown.TYPE); public static final StructuredDataKey FIRE_RESISTANT = new StructuredDataKey<>("fire_resistant", Types.EMPTY); public static final StructuredDataKey DAMAGE_RESISTANT = new StructuredDataKey<>("damage_resistant", DamageResistant.TYPE); @@ -113,15 +117,18 @@ public record StructuredDataKey(String identifier, Type type) { public static final StructuredDataKey CHARGED_PROJECTILES1_20_5 = new StructuredDataKey<>("charged_projectiles", Types1_20_5.ITEM_ARRAY); public static final StructuredDataKey CHARGED_PROJECTILES1_21 = new StructuredDataKey<>("charged_projectiles", Types1_21.ITEM_ARRAY); public static final StructuredDataKey CHARGED_PROJECTILES1_21_2 = new StructuredDataKey<>("charged_projectiles", Types1_21_2.ITEM_ARRAY); + public static final StructuredDataKey CHARGED_PROJECTILES1_21_4 = new StructuredDataKey<>("charged_projectiles", Types1_21_4.ITEM_ARRAY); public static final StructuredDataKey BUNDLE_CONTENTS1_20_5 = new StructuredDataKey<>("bundle_contents", Types1_20_5.ITEM_ARRAY); public static final StructuredDataKey BUNDLE_CONTENTS1_21 = new StructuredDataKey<>("bundle_contents", Types1_21.ITEM_ARRAY); public static final StructuredDataKey BUNDLE_CONTENTS1_21_2 = new StructuredDataKey<>("bundle_contents", Types1_21_2.ITEM_ARRAY); + public static final StructuredDataKey BUNDLE_CONTENTS1_21_4 = new StructuredDataKey<>("bundle_contents", Types1_21_4.ITEM_ARRAY); public static final StructuredDataKey POTION_CONTENTS1_20_5 = new StructuredDataKey<>("potion_contents", PotionContents.TYPE1_20_5); public static final StructuredDataKey POTION_CONTENTS1_21_2 = new StructuredDataKey<>("potion_contents", PotionContents.TYPE1_21_2); public static final StructuredDataKey SUSPICIOUS_STEW_EFFECTS = new StructuredDataKey<>("suspicious_stew_effects", SuspiciousStewEffect.ARRAY_TYPE); public static final StructuredDataKey WRITABLE_BOOK_CONTENT = new StructuredDataKey<>("writable_book_content", FilterableString.ARRAY_TYPE); public static final StructuredDataKey WRITTEN_BOOK_CONTENT = new StructuredDataKey<>("written_book_content", WrittenBook.TYPE); - public static final StructuredDataKey TRIM = new StructuredDataKey<>("trim", ArmorTrim.TYPE); + public static final StructuredDataKey TRIM1_20_5 = new StructuredDataKey<>("trim", ArmorTrim.TYPE1_20_5); + public static final StructuredDataKey TRIM1_21_4 = new StructuredDataKey<>("trim", ArmorTrim.TYPE1_21_4); public static final StructuredDataKey DEBUG_STICK_STATE = new StructuredDataKey<>("debug_stick_state", Types.COMPOUND_TAG); public static final StructuredDataKey ENTITY_DATA = new StructuredDataKey<>("entity_data", Types.COMPOUND_TAG); public static final StructuredDataKey BUCKET_ENTITY_DATA = new StructuredDataKey<>("bucket_entity_data", Types.COMPOUND_TAG); @@ -142,6 +149,7 @@ public record StructuredDataKey(String identifier, Type type) { public static final StructuredDataKey CONTAINER1_20_5 = new StructuredDataKey<>("container", Types1_20_5.ITEM_ARRAY); public static final StructuredDataKey CONTAINER1_21 = new StructuredDataKey<>("container", Types1_21.ITEM_ARRAY); public static final StructuredDataKey CONTAINER1_21_2 = new StructuredDataKey<>("container", new ArrayType<>(Types1_21_2.ITEM, 256)); + public static final StructuredDataKey CONTAINER1_21_4 = new StructuredDataKey<>("container", Types1_21_4.ITEM_ARRAY); public static final StructuredDataKey BLOCK_STATE = new StructuredDataKey<>("block_state", BlockStateProperties.TYPE); public static final StructuredDataKey BEES = new StructuredDataKey<>("bees", Bee.ARRAY_TYPE); public static final StructuredDataKey LOCK = new StructuredDataKey<>("lock", Types.TAG); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrim.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrim.java index e06e414f7..8681fe2f4 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrim.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrim.java @@ -29,10 +29,10 @@ import it.unimi.dsi.fastutil.ints.Int2IntFunction; public record ArmorTrim(Holder material, Holder pattern, boolean showInTooltip) { - public static final Type TYPE = new Type<>(ArmorTrim.class) { + public static final Type TYPE1_20_5 = new Type<>(ArmorTrim.class) { @Override public ArmorTrim read(final ByteBuf buffer) { - final Holder material = ArmorTrimMaterial.TYPE.read(buffer); + final Holder material = ArmorTrimMaterial.TYPE1_20_5.read(buffer); final Holder pattern = ArmorTrimPattern.TYPE.read(buffer); final boolean showInTooltip = buffer.readBoolean(); return new ArmorTrim(material, pattern, showInTooltip); @@ -40,7 +40,23 @@ public record ArmorTrim(Holder material, Holder TYPE1_21_4 = new Type<>(ArmorTrim.class) { + @Override + public ArmorTrim read(final ByteBuf buffer) { + final Holder material = ArmorTrimMaterial.TYPE1_21_4.read(buffer); + final Holder pattern = ArmorTrimPattern.TYPE.read(buffer); + final boolean showInTooltip = buffer.readBoolean(); + return new ArmorTrim(material, pattern, showInTooltip); + } + + @Override + public void write(final ByteBuf buffer, final ArmorTrim value) { + ArmorTrimMaterial.TYPE1_21_4.write(buffer, value.material); ArmorTrimPattern.TYPE.write(buffer, value.pattern); buffer.writeBoolean(value.showInTooltip); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java index 3e8bf4399..391b4877e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ArmorTrimMaterial.java @@ -33,7 +33,11 @@ import java.util.Map; public record ArmorTrimMaterial(String assetName, int itemId, float itemModelIndex, Map overrideArmorMaterials, Tag description) { - public static final HolderType TYPE = new HolderType<>() { + public ArmorTrimMaterial(final String assetName, final int itemId, final Map overrideArmorMaterials, final Tag description) { + this(assetName, itemId, 0F, overrideArmorMaterials, description); + } + + public static final HolderType TYPE1_20_5 = new HolderType<>() { @Override public ArmorTrimMaterial readDirect(final ByteBuf buffer) { final String assetName = Types.STRING.read(buffer); @@ -68,6 +72,39 @@ public record ArmorTrimMaterial(String assetName, int itemId, float itemModelInd } }; + public static final HolderType TYPE1_21_4 = new HolderType<>() { + @Override + public ArmorTrimMaterial readDirect(final ByteBuf buffer) { + final String assetName = Types.STRING.read(buffer); + final int item = Types.VAR_INT.readPrimitive(buffer); + + final int overrideArmorMaterialsSize = Types.VAR_INT.readPrimitive(buffer); + final Map overrideArmorMaterials = new Object2ObjectArrayMap<>(overrideArmorMaterialsSize); + for (int i = 0; i < overrideArmorMaterialsSize; i++) { + final String key = Types.STRING.read(buffer); + final String value = Types.STRING.read(buffer); + overrideArmorMaterials.put(key, value); + } + + final Tag description = Types.TAG.read(buffer); + return new ArmorTrimMaterial(assetName, item, overrideArmorMaterials, description); + } + + @Override + public void writeDirect(final ByteBuf buffer, final ArmorTrimMaterial value) { + Types.STRING.write(buffer, value.assetName()); + Types.VAR_INT.writePrimitive(buffer, value.itemId()); + + Types.VAR_INT.writePrimitive(buffer, value.overrideArmorMaterials().size()); + for (final Map.Entry entry : value.overrideArmorMaterials().entrySet()) { + Types.STRING.write(buffer, entry.getKey()); + Types.STRING.write(buffer, entry.getValue()); + } + + Types.TAG.write(buffer, value.description()); + } + }; + public ArmorTrimMaterial rewrite(final Int2IntFunction idRewriteFunction) { return new ArmorTrimMaterial(assetName, idRewriteFunction.applyAsInt(itemId), itemModelIndex, overrideArmorMaterials, description); } diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/CustomModelData1_21_4.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/CustomModelData1_21_4.java new file mode 100644 index 000000000..9aa29d140 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/CustomModelData1_21_4.java @@ -0,0 +1,49 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 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.item.data; + +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.Types; +import io.netty.buffer.ByteBuf; + +public record CustomModelData1_21_4(float[] floats, boolean[] booleans, String[] strings, int[] colors) { + + public static final Type TYPE = new Type<>(CustomModelData1_21_4.class) { + @Override + public CustomModelData1_21_4 read(final ByteBuf buffer) { + final float[] floats = Types.FLOAT_ARRAY_PRIMITIVE.read(buffer); + final boolean[] booleans = Types.BOOLEAN_ARRAY_PRIMITIVE.read(buffer); + final String[] strings = Types.STRING_ARRAY.read(buffer); + final int[] colors = Types.INT_ARRAY_PRIMITIVE.read(buffer); + return new CustomModelData1_21_4(floats, booleans, strings, colors); + } + + @Override + public void write(final ByteBuf buffer, final CustomModelData1_21_4 value) { + Types.FLOAT_ARRAY_PRIMITIVE.write(buffer, value.floats()); + Types.BOOLEAN_ARRAY_PRIMITIVE.write(buffer, value.booleans()); + Types.STRING_ARRAY.write(buffer, value.strings()); + Types.INT_ARRAY_PRIMITIVE.write(buffer, value.colors()); + } + }; +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java index 73512042b..f5f0247f5 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java +++ b/api/src/main/java/com/viaversion/viaversion/api/protocol/version/ProtocolVersion.java @@ -87,7 +87,7 @@ public class ProtocolVersion implements Comparable { public static final ProtocolVersion v1_20_5 = register(766, "1.20.5-1.20.6", new SubVersionRange("1.20", 5, 6)); public static final ProtocolVersion v1_21 = register(767, "1.21-1.21.1", new SubVersionRange("1.21", 0, 1)); public static final ProtocolVersion v1_21_2 = register(768, "1.21.2-1.21.3", new SubVersionRange("1.21", 2, 3)); - public static final ProtocolVersion v1_21_4 = register(769, 220, "1.21.4"); + public static final ProtocolVersion v1_21_4 = register(769, 221, "1.21.4"); public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null); static { diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/Types.java b/api/src/main/java/com/viaversion/viaversion/api/type/Types.java index c65b9a531..063fad8cf 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/Types.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/Types.java @@ -45,12 +45,14 @@ import com.viaversion.viaversion.api.minecraft.item.data.Enchantments; import com.viaversion.viaversion.api.minecraft.ChunkPosition; import com.viaversion.viaversion.api.type.types.ArrayType; import com.viaversion.viaversion.api.type.types.BitSetType; +import com.viaversion.viaversion.api.type.types.BooleanArrayType; import com.viaversion.viaversion.api.type.types.BooleanType; import com.viaversion.viaversion.api.type.types.ByteArrayType; import com.viaversion.viaversion.api.type.types.ByteType; import com.viaversion.viaversion.api.type.types.ComponentType; import com.viaversion.viaversion.api.type.types.DoubleType; import com.viaversion.viaversion.api.type.types.EmptyType; +import com.viaversion.viaversion.api.type.types.FloatArrayType; import com.viaversion.viaversion.api.type.types.FloatType; import com.viaversion.viaversion.api.type.types.IntArrayType; import com.viaversion.viaversion.api.type.types.IntType; @@ -115,14 +117,17 @@ public final class Types { public static final Type OPTIONAL_BYTE_ARRAY_PRIMITIVE = new ByteArrayType.OptionalByteArrayType(); public static final Type SHORT_BYTE_ARRAY = new ShortByteArrayType(); public static final Type REMAINING_BYTES = new RemainingBytesType(); - public static final Type INT_ARRAY_PRIMITIVE = new IntArrayType(); public static final ShortType SHORT = new ShortType(); public static final UnsignedShortType UNSIGNED_SHORT = new UnsignedShortType(); public static final IntType INT = new IntType(); + public static final Type INT_ARRAY_PRIMITIVE = new IntArrayType(); + public static final FloatType FLOAT = new FloatType(); public static final FloatType.OptionalFloatType OPTIONAL_FLOAT = new FloatType.OptionalFloatType(); + public static final Type FLOAT_ARRAY_PRIMITIVE = new FloatArrayType(); + public static final DoubleType DOUBLE = new DoubleType(); public static final LongType LONG = new LongType(); @@ -130,6 +135,7 @@ public final class Types { public static final BooleanType BOOLEAN = new BooleanType(); public static final BooleanType.OptionalBooleanType OPTIONAL_BOOLEAN = new BooleanType.OptionalBooleanType(); + public static final Type BOOLEAN_ARRAY_PRIMITIVE = new BooleanArrayType(); /* Other Types */ public static final Type COMPONENT = new ComponentType(); diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/BooleanArrayType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/BooleanArrayType.java new file mode 100644 index 000000000..eea9cbcf6 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/BooleanArrayType.java @@ -0,0 +1,67 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 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; + +import com.google.common.base.Preconditions; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.Types; +import io.netty.buffer.ByteBuf; + +// Ok... +public class BooleanArrayType extends Type { + + private final int length; + + public BooleanArrayType(final int length) { + super(boolean[].class); + this.length = length; + } + + public BooleanArrayType() { + super(boolean[].class); + this.length = -1; + } + + @Override + public void write(final ByteBuf buffer, final boolean[] object) { + if (this.length != -1) { + Preconditions.checkArgument(length == object.length, "Length does not match expected length"); + } else { + Types.VAR_INT.writePrimitive(buffer, object.length); + } + for (final boolean b : object) { + buffer.writeBoolean(b); + } + } + + @Override + public boolean[] read(final ByteBuf buffer) { + final int length = this.length == -1 ? Types.VAR_INT.readPrimitive(buffer) : this.length; + Preconditions.checkArgument(buffer.isReadable(length), "Length is fewer than readable bytes"); + final boolean[] array = new boolean[length]; + for (int i = 0; i < length; i++) { + array[i] = buffer.readBoolean(); + } + return array; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/FloatArrayType.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/FloatArrayType.java new file mode 100644 index 000000000..7bbdf1408 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/FloatArrayType.java @@ -0,0 +1,66 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 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; + +import com.google.common.base.Preconditions; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.Types; +import io.netty.buffer.ByteBuf; + +public class FloatArrayType extends Type { + + private final int length; + + public FloatArrayType(final int length) { + super(float[].class); + this.length = length; + } + + public FloatArrayType() { + super(float[].class); + this.length = -1; + } + + @Override + public void write(final ByteBuf buffer, final float[] object) { + if (this.length != -1) { + Preconditions.checkArgument(length == object.length, "Length does not match expected length"); + } else { + Types.VAR_INT.writePrimitive(buffer, object.length); + } + for (final float f : object) { + buffer.writeFloat(f); + } + } + + @Override + public float[] read(final ByteBuf buffer) { + final int length = this.length == -1 ? Types.VAR_INT.readPrimitive(buffer) : this.length; + Preconditions.checkArgument(buffer.isReadable(length), "Length is fewer than readable bytes"); + final float[] array = new float[length]; + for (int i = 0; i < length; i++) { + array[i] = buffer.readFloat(); + } + return array; + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java index 52970d8ae..a9c5f6ade 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/Protocol1_20_3To1_20_5.java @@ -270,13 +270,13 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol extends Co register(StructuredDataKey.CAN_PLACE_ON, this::convertCanPlaceOn); register(StructuredDataKey.CAN_BREAK, this::convertCanBreak); register(StructuredDataKey.ATTRIBUTE_MODIFIERS1_20_5, this::convertAttributeModifiers); - register(StructuredDataKey.CUSTOM_MODEL_DATA, this::convertCustomModelData); + register(StructuredDataKey.CUSTOM_MODEL_DATA1_20_5, this::convertCustomModelData); register(StructuredDataKey.HIDE_ADDITIONAL_TOOLTIP, this::convertHideAdditionalTooltip); register(StructuredDataKey.HIDE_TOOLTIP, this::convertHideTooltip); register(StructuredDataKey.REPAIR_COST, this::convertRepairCost); @@ -146,7 +146,7 @@ public class ComponentRewriter1_20_5 extends Co register(StructuredDataKey.SUSPICIOUS_STEW_EFFECTS, this::convertSuspiciousStewEffects); register(StructuredDataKey.WRITABLE_BOOK_CONTENT, this::convertWritableBookContent); register(StructuredDataKey.WRITTEN_BOOK_CONTENT, this::convertWrittenBookContent); - register(StructuredDataKey.TRIM, this::convertTrim); + register(StructuredDataKey.TRIM1_20_5, this::convertTrim); register(StructuredDataKey.DEBUG_STICK_STATE, this::convertDebugStickRate); register(StructuredDataKey.ENTITY_DATA, this::convertEntityData); register(StructuredDataKey.BUCKET_ENTITY_DATA, this::convertBucketEntityData); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java index af83494bc..f07d87f0b 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_3to1_20_5/rewriter/StructuredDataConverter.java @@ -151,7 +151,7 @@ public final class StructuredDataConverter { putHideFlag(tag, HIDE_ATTRIBUTES); } }); - register(StructuredDataKey.CUSTOM_MODEL_DATA, (data, tag) -> tag.putInt("CustomModelData", data)); + register(StructuredDataKey.CUSTOM_MODEL_DATA1_20_5, (data, tag) -> tag.putInt("CustomModelData", data)); register(StructuredDataKey.HIDE_ADDITIONAL_TOOLTIP, (data, tag) -> putHideFlag(tag, 0x20)); register(StructuredDataKey.REPAIR_COST, (data, tag) -> tag.putInt("RepairCost", data)); register(StructuredDataKey.DYED_COLOR, (data, tag) -> { @@ -513,7 +513,7 @@ public final class StructuredDataConverter { tag.putInt("map_scale_direction", 1); } }); - register(StructuredDataKey.TRIM, (connection, data, tag) -> { + register(StructuredDataKey.TRIM1_20_5, (connection, data, tag) -> { final CompoundTag trimTag = new CompoundTag(); final ArmorTrimStorage trimStorage = connection.get(ArmorTrimStorage.class); if (data.material().isDirect()) { diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java index e3aa714c7..c50c7ac86 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/Protocol1_20_5To1_21.java @@ -203,13 +203,13 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol { @@ -37,7 +38,7 @@ public final class ComponentRewriter1_21_4 extends ComponentRewriter { + wrapper.passthrough(Types.DOUBLE); // X + wrapper.passthrough(Types.DOUBLE); // Y + wrapper.passthrough(Types.DOUBLE); // Z + wrapper.passthrough(Types.FLOAT); // Yaw + wrapper.passthrough(Types.FLOAT); // Pitch + wrapper.read(Types.BOOLEAN); // On ground + }); + protocol.cancelServerbound(ServerboundPackets1_21_4.PLAYER_LOADED); } @Override diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/Protocol1_21To1_21_2.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/Protocol1_21To1_21_2.java index cef630da6..51dd1628a 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/Protocol1_21To1_21_2.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_21to1_21_2/Protocol1_21To1_21_2.java @@ -210,12 +210,12 @@ public final class Protocol1_21To1_21_2 extends AbstractProtocol { final Consumable1_21_2 consumableData = dataContainer.get(StructuredDataKey.CONSUMABLE1_21_2); - final Item useRemainderData = dataContainer.get(StructuredDataKey.USE_REMAINDER); + final Item useRemainderData = dataContainer.get(StructuredDataKey.USE_REMAINDER1_21_2); final float eatSeconds = consumableData != null ? consumableData.consumeSeconds() : 1.6F; final List foodEffects = new ArrayList<>(); if (consumableData != null) { @@ -637,7 +637,7 @@ public final class BlockItemPacketRewriter1_21_2 extends StructuredItemRewriter< dataContainer.remove(StructuredDataKey.REPAIRABLE); dataContainer.remove(StructuredDataKey.ENCHANTABLE); dataContainer.remove(StructuredDataKey.CONSUMABLE1_21_2); - dataContainer.remove(StructuredDataKey.USE_REMAINDER); + dataContainer.remove(StructuredDataKey.USE_REMAINDER1_21_2); dataContainer.remove(StructuredDataKey.USE_COOLDOWN); dataContainer.remove(StructuredDataKey.ITEM_MODEL); dataContainer.remove(StructuredDataKey.EQUIPPABLE); 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 ba7d4257c..1cf80acbd 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/ItemRewriter.java @@ -240,11 +240,11 @@ public class ItemRewriter { - String itemIdentifier = wrapper.read(Types.OPTIONAL_STRING); + String itemIdentifier = wrapper.read(Types.STRING); if (itemIdentifier != null) { itemIdentifier = mappedIdentifier(protocol.getMappingData().getFullItemMappings(), itemIdentifier); } - wrapper.write(Types.OPTIONAL_STRING, itemIdentifier); + wrapper.write(Types.STRING, itemIdentifier); }); } diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/ParticleRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/ParticleRewriter.java index 6c88f6ae6..3315d1578 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/ParticleRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/ParticleRewriter.java @@ -181,9 +181,11 @@ public class ParticleRewriter implements com.vi wrapper.passthrough(Types.DOUBLE); // X wrapper.passthrough(Types.DOUBLE); // Y wrapper.passthrough(Types.DOUBLE); // Z - wrapper.passthrough(Types.DOUBLE); // Knockback X - wrapper.passthrough(Types.DOUBLE); // Knockback Y - wrapper.passthrough(Types.DOUBLE); // Knockback Z + if (wrapper.passthrough(Types.BOOLEAN)) { + wrapper.passthrough(Types.DOUBLE); // Knockback X + wrapper.passthrough(Types.DOUBLE); // Knockback Y + wrapper.passthrough(Types.DOUBLE); // Knockback Z + } final Particle explosionParticle = wrapper.read(particleType); wrapper.write(mappedParticleType, explosionParticle); diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/StructuredItemRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/StructuredItemRewriter.java index 89a073891..3338332fe 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/StructuredItemRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/StructuredItemRewriter.java @@ -117,7 +117,7 @@ public class StructuredItemRewriter value.rewrite(itemIdRewriter)); + container.replace(StructuredDataKey.TRIM1_20_5, value -> value.rewrite(itemIdRewriter)); container.replace(StructuredDataKey.POT_DECORATIONS, value -> value.rewrite(itemIdRewriter)); container.replace(StructuredDataKey.REPAIRABLE, value -> value.rewrite(itemIdRewriter)); }