diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataContainer.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataContainer.java index 6e6b66770..2c5446f7e 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataContainer.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/data/StructuredDataContainer.java @@ -106,9 +106,19 @@ public final class StructuredDataContainer { } public void replaceKey(final StructuredDataKey key, final StructuredDataKey toKey) { + replace(key, toKey, Function.identity()); + } + + public void replace(final StructuredDataKey key, final StructuredDataKey toKey, final Function valueMapper) { final StructuredData data = remove(key); - if (data != null) { - set(toKey, data.value()); + if (data == null) { + return; + } + + if (data.isPresent()) { + set(toKey, valueMapper.apply(data.value())); + } else { + addEmpty(toKey); } } 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 1b09be417..0944c5d55 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 @@ -29,7 +29,8 @@ import com.viaversion.viaversion.api.minecraft.Holder; import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.data.AdventureModePredicate; import com.viaversion.viaversion.api.minecraft.item.data.ArmorTrim; -import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers; +import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers1_20_5; +import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers1_21; 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; @@ -40,6 +41,7 @@ import com.viaversion.viaversion.api.minecraft.item.data.FireworkExplosion; import com.viaversion.viaversion.api.minecraft.item.data.Fireworks; import com.viaversion.viaversion.api.minecraft.item.data.FoodProperties; import com.viaversion.viaversion.api.minecraft.item.data.Instrument; +import com.viaversion.viaversion.api.minecraft.item.data.JukeboxPlayable; import com.viaversion.viaversion.api.minecraft.item.data.LodestoneTracker; import com.viaversion.viaversion.api.minecraft.item.data.PotDecorations; import com.viaversion.viaversion.api.minecraft.item.data.PotionContents; @@ -66,7 +68,8 @@ public record StructuredDataKey(String identifier, Type type) { public static final StructuredDataKey ENCHANTMENTS = new StructuredDataKey<>("enchantments", Enchantments.TYPE); public static final StructuredDataKey CAN_PLACE_ON = new StructuredDataKey<>("can_place_on", AdventureModePredicate.TYPE); public static final StructuredDataKey CAN_BREAK = new StructuredDataKey<>("can_break", AdventureModePredicate.TYPE); - public static final StructuredDataKey ATTRIBUTE_MODIFIERS = new StructuredDataKey<>("attribute_modifiers", AttributeModifiers.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 HIDE_ADDITIONAL_TOOLTIP = new StructuredDataKey<>("hide_additional_tooltip", Types.EMPTY); public static final StructuredDataKey HIDE_TOOLTIP = new StructuredDataKey<>("hide_tooltip", Types.EMPTY); @@ -97,6 +100,7 @@ public record StructuredDataKey(String identifier, Type type) { public static final StructuredDataKey BLOCK_ENTITY_DATA = new StructuredDataKey<>("block_entity_data", Types.COMPOUND_TAG); public static final StructuredDataKey> INSTRUMENT = new StructuredDataKey<>("instrument", Instrument.TYPE); public static final StructuredDataKey OMINOUS_BOTTLE_AMPLIFIER = new StructuredDataKey<>("ominous_bottle_amplifier", Types.VAR_INT); + public static final StructuredDataKey JUKEBOX_PLAYABLE = new StructuredDataKey<>("jukebox_playable", JukeboxPlayable.TYPE); public static final StructuredDataKey RECIPES = new StructuredDataKey<>("recipes", Types.TAG); public static final StructuredDataKey LODESTONE_TRACKER = new StructuredDataKey<>("lodestone_tracker", LodestoneTracker.TYPE); public static final StructuredDataKey FIREWORK_EXPLOSION = new StructuredDataKey<>("firework_explosion", FireworkExplosion.TYPE); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifier.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifier.java deleted file mode 100644 index b6f9dfd48..000000000 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifier.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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 com.viaversion.viaversion.api.type.types.ArrayType; -import io.netty.buffer.ByteBuf; - -public record AttributeModifier(int attribute, ModifierData modifier, int slotType) { - - public static final Type TYPE = new Type<>(AttributeModifier.class) { - @Override - public AttributeModifier read(final ByteBuf buffer) { - final int attribute = Types.VAR_INT.readPrimitive(buffer); - final ModifierData modifier = ModifierData.TYPE.read(buffer); - final int slot = Types.VAR_INT.readPrimitive(buffer); - return new AttributeModifier(attribute, modifier, slot); - } - - @Override - public void write(final ByteBuf buffer, final AttributeModifier value) { - Types.VAR_INT.writePrimitive(buffer, value.attribute); - ModifierData.TYPE.write(buffer, value.modifier); - Types.VAR_INT.writePrimitive(buffer, value.slotType); - } - }; - public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); - -} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers.java deleted file mode 100644 index 85fec4c8b..000000000 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * 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 io.netty.buffer.ByteBuf; - -public record AttributeModifiers(AttributeModifier[] modifiers, boolean showInTooltip) { - - public static final Type TYPE = new Type<>(AttributeModifiers.class) { - @Override - public AttributeModifiers read(final ByteBuf buffer) { - final AttributeModifier[] modifiers = AttributeModifier.ARRAY_TYPE.read(buffer); - final boolean showInTooltip = buffer.readBoolean(); - return new AttributeModifiers(modifiers, showInTooltip); - } - - @Override - public void write(final ByteBuf buffer, final AttributeModifiers value) { - AttributeModifier.ARRAY_TYPE.write(buffer, value.modifiers()); - buffer.writeBoolean(value.showInTooltip()); - } - }; - -} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers1_20_5.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers1_20_5.java new file mode 100644 index 000000000..d80c26a1c --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers1_20_5.java @@ -0,0 +1,90 @@ +/* + * 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 com.viaversion.viaversion.api.type.types.ArrayType; +import io.netty.buffer.ByteBuf; +import java.util.UUID; + +public record AttributeModifiers1_20_5(AttributeModifier[] modifiers, boolean showInTooltip) { + + public static final Type TYPE = new Type<>(AttributeModifiers1_20_5.class) { + @Override + public AttributeModifiers1_20_5 read(final ByteBuf buffer) { + final AttributeModifier[] modifiers = AttributeModifier.ARRAY_TYPE.read(buffer); + final boolean showInTooltip = buffer.readBoolean(); + return new AttributeModifiers1_20_5(modifiers, showInTooltip); + } + + @Override + public void write(final ByteBuf buffer, final AttributeModifiers1_20_5 value) { + AttributeModifier.ARRAY_TYPE.write(buffer, value.modifiers()); + buffer.writeBoolean(value.showInTooltip()); + } + }; + + public record AttributeModifier(int attribute, ModifierData modifier, int slotType) { + + public static final Type TYPE = new Type<>(AttributeModifier.class) { + @Override + public AttributeModifier read(final ByteBuf buffer) { + final int attribute = Types.VAR_INT.readPrimitive(buffer); + final ModifierData modifier = ModifierData.TYPE.read(buffer); + final int slot = Types.VAR_INT.readPrimitive(buffer); + return new AttributeModifier(attribute, modifier, slot); + } + + @Override + public void write(final ByteBuf buffer, final AttributeModifier value) { + Types.VAR_INT.writePrimitive(buffer, value.attribute); + ModifierData.TYPE.write(buffer, value.modifier); + Types.VAR_INT.writePrimitive(buffer, value.slotType); + } + }; + public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); + } + + public record ModifierData(UUID uuid, String name, double amount, int operation) { + + public static final Type TYPE = new Type<>(ModifierData.class) { + @Override + public ModifierData read(final ByteBuf buffer) { + final UUID uuid = Types.UUID.read(buffer); + final String name = Types.STRING.read(buffer); + final double amount = buffer.readDouble(); + final int operation = Types.VAR_INT.readPrimitive(buffer); + return new ModifierData(uuid, name, amount, operation); + } + + @Override + public void write(final ByteBuf buffer, final ModifierData value) { + Types.UUID.write(buffer, value.uuid); + Types.STRING.write(buffer, value.name); + buffer.writeDouble(value.amount); + Types.VAR_INT.writePrimitive(buffer, value.operation); + } + }; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers1_21.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers1_21.java new file mode 100644 index 000000000..8c095452c --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/AttributeModifiers1_21.java @@ -0,0 +1,87 @@ +/* + * 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 com.viaversion.viaversion.api.type.types.ArrayType; +import io.netty.buffer.ByteBuf; + +public record AttributeModifiers1_21(AttributeModifier[] modifiers, boolean showInTooltip) { + + public static final Type TYPE = new Type<>(AttributeModifiers1_21.class) { + @Override + public AttributeModifiers1_21 read(final ByteBuf buffer) { + final AttributeModifier[] modifiers = AttributeModifier.ARRAY_TYPE.read(buffer); + final boolean showInTooltip = buffer.readBoolean(); + return new AttributeModifiers1_21(modifiers, showInTooltip); + } + + @Override + public void write(final ByteBuf buffer, final AttributeModifiers1_21 value) { + AttributeModifier.ARRAY_TYPE.write(buffer, value.modifiers()); + buffer.writeBoolean(value.showInTooltip()); + } + }; + + public record AttributeModifier(int attribute, ModifierData modifier, int slotType) { + + public static final Type TYPE = new Type<>(AttributeModifier.class) { + @Override + public AttributeModifier read(final ByteBuf buffer) { + final int attribute = Types.VAR_INT.readPrimitive(buffer); + final ModifierData modifier = ModifierData.TYPE.read(buffer); + final int slot = Types.VAR_INT.readPrimitive(buffer); + return new AttributeModifier(attribute, modifier, slot); + } + + @Override + public void write(final ByteBuf buffer, final AttributeModifier value) { + Types.VAR_INT.writePrimitive(buffer, value.attribute); + ModifierData.TYPE.write(buffer, value.modifier); + Types.VAR_INT.writePrimitive(buffer, value.slotType); + } + }; + public static final Type ARRAY_TYPE = new ArrayType<>(TYPE); + } + + public record ModifierData(String id, double amount, int operation) { + + public static final Type TYPE = new Type<>(ModifierData.class) { + @Override + public ModifierData read(final ByteBuf buffer) { + final String id = Types.STRING.read(buffer); + final double amount = buffer.readDouble(); + final int operation = Types.VAR_INT.readPrimitive(buffer); + return new ModifierData(id, amount, operation); + } + + @Override + public void write(final ByteBuf buffer, final ModifierData value) { + Types.STRING.write(buffer, value.id); + buffer.writeDouble(value.amount); + Types.VAR_INT.writePrimitive(buffer, value.operation); + } + }; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/JukeboxPlayable.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/JukeboxPlayable.java new file mode 100644 index 000000000..8c47ba650 --- /dev/null +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/JukeboxPlayable.java @@ -0,0 +1,73 @@ +/* + * 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.nbt.tag.Tag; +import com.viaversion.viaversion.api.minecraft.Holder; +import com.viaversion.viaversion.api.minecraft.SoundEvent; +import com.viaversion.viaversion.api.type.Type; +import com.viaversion.viaversion.api.type.Types; +import com.viaversion.viaversion.api.type.types.misc.HolderType; +import com.viaversion.viaversion.util.Either; +import io.netty.buffer.ByteBuf; + +public record JukeboxPlayable(Either, String> song, boolean showInTooltip) { + + public static final Type TYPE = new Type<>(JukeboxPlayable.class) { + @Override + public JukeboxPlayable read(final ByteBuf buffer) { + final Either, String> position = Type.readEither(buffer, JukeboxSong.TYPE, Types.STRING); + final boolean showInTooltip = buffer.readBoolean(); + return new JukeboxPlayable(position, showInTooltip); + } + + @Override + public void write(final ByteBuf buffer, final JukeboxPlayable value) { + Type.writeEither(buffer, value.song, JukeboxSong.TYPE, Types.STRING); + buffer.writeBoolean(value.showInTooltip); + } + }; + + public record JukeboxSong(Holder soundEvent, Tag description, + float lengthInSeconds, int comparatorOutput) { + + public static final HolderType TYPE = new HolderType<>() { + @Override + public JukeboxSong readDirect(final ByteBuf buffer) { + final Holder soundEvent = Types.SOUND_EVENT.read(buffer); + final Tag description = Types.TAG.read(buffer); + final float lengthInSeconds = buffer.readFloat(); + final int useDuration = Types.VAR_INT.readPrimitive(buffer); + return new JukeboxSong(soundEvent, description, lengthInSeconds, useDuration); + } + + @Override + public void writeDirect(final ByteBuf buffer, final JukeboxSong value) { + Types.SOUND_EVENT.write(buffer, value.soundEvent); + Types.TAG.write(buffer, value.description); + buffer.writeFloat(value.lengthInSeconds); + Types.VAR_INT.writePrimitive(buffer, value.comparatorOutput); + } + }; + } +} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ModifierData.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ModifierData.java deleted file mode 100644 index 440540c7a..000000000 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/ModifierData.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * 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; -import java.util.UUID; - -public record ModifierData(UUID uuid, String name, double amount, int operation) { - - public static final Type TYPE = new Type<>(ModifierData.class) { - @Override - public ModifierData read(final ByteBuf buffer) { - final UUID uuid = Types.UUID.read(buffer); - final String name = Types.STRING.read(buffer); - final double amount = buffer.readDouble(); - final int operation = Types.VAR_INT.readPrimitive(buffer); - return new ModifierData(uuid, name, amount, operation); - } - - @Override - public void write(final ByteBuf buffer, final ModifierData value) { - Types.UUID.write(buffer, value.uuid); - Types.STRING.write(buffer, value.name); - buffer.writeDouble(value.amount); - Types.VAR_INT.writePrimitive(buffer, value.operation); - } - }; - -} diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/StatePropertyMatcher.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/StatePropertyMatcher.java index cf3d0579d..7f141704c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/StatePropertyMatcher.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/StatePropertyMatcher.java @@ -31,7 +31,6 @@ import org.checkerframework.checker.nullness.qual.Nullable; public record StatePropertyMatcher(String name, Either matcher) { - // TODO Abstract Either reading public static final Type TYPE = new Type<>(StatePropertyMatcher.class) { @Override public StatePropertyMatcher read(final ByteBuf buffer) { 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 48ffe10e4..ccdb2c791 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 @@ -84,7 +84,7 @@ public class ProtocolVersion implements Comparable { public static final ProtocolVersion v1_20_2 = register(764, "1.20.2"); public static final ProtocolVersion v1_20_3 = register(765, "1.20.3-1.20.4", new SubVersionRange("1.20", 3, 4)); 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, 196, "1.21"); + public static final ProtocolVersion v1_21 = register(767, 198, "1.21"); public static final ProtocolVersion unknown = new ProtocolVersion(VersionType.SPECIAL, -1, -1, "UNKNOWN", null); public static ProtocolVersion register(int version, String name) { 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 1d0721a3d..1e2b82a71 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 @@ -22,6 +22,9 @@ */ package com.viaversion.viaversion.api.type; +import com.viaversion.viaversion.util.Either; +import io.netty.buffer.ByteBuf; + /** * Type for buffer reading and writing. * @@ -75,4 +78,22 @@ public abstract class Type implements ByteBufReader, ByteBufWriter { public String toString() { return getTypeName(); } + + public static Either readEither(final ByteBuf buf, final Type leftType, final Type rightType) { + if (buf.readBoolean()) { + return Either.left(leftType.read(buf)); + } else { + return Either.right(rightType.read(buf)); + } + } + + public static void writeEither(final ByteBuf buf, final Either value, final Type leftType, final Type rightType) { + if (value.isLeft()) { + buf.writeBoolean(true); + leftType.write(buf, value.left()); + } else { + buf.writeBoolean(false); + rightType.write(buf, value.right()); + } + } } 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 438dd8d52..5c9ba7a74 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 @@ -263,7 +263,7 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol extends Co register(StructuredDataKey.ENCHANTMENTS, this::convertEnchantments); register(StructuredDataKey.CAN_PLACE_ON, this::convertCanPlaceOn); register(StructuredDataKey.CAN_BREAK, this::convertCanBreak); - register(StructuredDataKey.ATTRIBUTE_MODIFIERS, this::convertAttributeModifiers); + register(StructuredDataKey.ATTRIBUTE_MODIFIERS1_20_5, this::convertAttributeModifiers); register(StructuredDataKey.CUSTOM_MODEL_DATA, this::convertCustomModelData); register(StructuredDataKey.HIDE_ADDITIONAL_TOOLTIP, this::convertHideAdditionalTooltip); register(StructuredDataKey.HIDE_TOOLTIP, this::convertHideTooltip); @@ -446,7 +446,7 @@ public class ComponentRewriter1_20_5 extends Co return convertCanPlaceOn(value); } - protected CompoundTag convertAttributeModifiers(final AttributeModifiers value) { + protected CompoundTag convertAttributeModifiers(final AttributeModifiers1_20_5 value) { final CompoundTag tag = new CompoundTag(); final ListTag modifiers = new ListTag<>(CompoundTag.class); for (final AttributeModifier modifier : value.modifiers()) { 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 666bb1d12..00bb7d4bd 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 @@ -35,7 +35,7 @@ import com.viaversion.viaversion.api.minecraft.item.Item; import com.viaversion.viaversion.api.minecraft.item.data.AdventureModePredicate; import com.viaversion.viaversion.api.minecraft.item.data.ArmorTrimMaterial; import com.viaversion.viaversion.api.minecraft.item.data.ArmorTrimPattern; -import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifier; +import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers1_20_5.AttributeModifier; import com.viaversion.viaversion.api.minecraft.item.data.BannerPattern; import com.viaversion.viaversion.api.minecraft.item.data.BannerPatternLayer; import com.viaversion.viaversion.api.minecraft.item.data.Bee; @@ -128,7 +128,7 @@ public final class StructuredDataConverter { }); register(StructuredDataKey.ENCHANTMENTS, (data, tag) -> convertEnchantments(data, tag, false)); register(StructuredDataKey.STORED_ENCHANTMENTS, (data, tag) -> convertEnchantments(data, tag, true)); - register(StructuredDataKey.ATTRIBUTE_MODIFIERS, (data, tag) -> { + register(StructuredDataKey.ATTRIBUTE_MODIFIERS1_20_5, (data, tag) -> { final ListTag modifiers = new ListTag<>(CompoundTag.class); for (int i = 0; i < data.modifiers().length; i++) { final AttributeModifier modifier = data.modifiers()[i]; 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 abbe728db..20d4a73d6 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 @@ -27,23 +27,28 @@ import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.version.Types1_21; import com.viaversion.viaversion.data.entity.EntityTrackerBase; -import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.MappingData; -import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21; -import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.EntityPacketRewriter1_21; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundConfigurationPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundConfigurationPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; -import com.viaversion.viaversion.rewriter.AttributeRewriter; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.AttributeModifierMappings1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.MappingData; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundConfigurationPackets1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPacket1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.packet.ClientboundPackets1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.BlockItemPacketRewriter1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter.EntityPacketRewriter1_21; import com.viaversion.viaversion.rewriter.SoundRewriter; import com.viaversion.viaversion.rewriter.StatisticsRewriter; import com.viaversion.viaversion.rewriter.TagRewriter; +import java.util.Locale; +import java.util.UUID; import static com.viaversion.viaversion.util.ProtocolUtil.packetTypeMap; -public final class Protocol1_20_5To1_21 extends AbstractProtocol { +public final class Protocol1_20_5To1_21 extends AbstractProtocol { public static final MappingData MAPPINGS = new MappingData(); private final EntityPacketRewriter1_21 entityRewriter = new EntityPacketRewriter1_21(this); @@ -51,7 +56,7 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol tagRewriter = new TagRewriter<>(this); public Protocol1_20_5To1_21() { - super(ClientboundPacket1_20_5.class, ClientboundPacket1_20_5.class, ServerboundPacket1_20_5.class, ServerboundPacket1_20_5.class); + super(ClientboundPacket1_20_5.class, ClientboundPacket1_21.class, ServerboundPacket1_20_5.class, ServerboundPacket1_20_5.class); } @Override @@ -66,7 +71,24 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol(this).register(ClientboundPackets1_20_5.AWARD_STATS); - new AttributeRewriter<>(this).register1_20_5(ClientboundPackets1_20_5.UPDATE_ATTRIBUTES); + + registerClientbound(ClientboundPackets1_20_5.UPDATE_ATTRIBUTES, wrapper -> { + wrapper.passthrough(Types.VAR_INT); // Entity ID + + final int size = wrapper.passthrough(Types.VAR_INT); + for (int i = 0; i < size; i++) { + final int attributeId = wrapper.read(Types.VAR_INT); + wrapper.write(Types.VAR_INT, MAPPINGS.getNewAttributeId(attributeId)); + wrapper.passthrough(Types.DOUBLE); // Base + final int modifierSize = wrapper.passthrough(Types.VAR_INT); + for (int j = 0; j < modifierSize; j++) { + final UUID uuid = wrapper.read(Types.UUID); + wrapper.write(Types.STRING, mapAttributeUUID(uuid, null)); + wrapper.passthrough(Types.DOUBLE); // Amount + wrapper.passthrough(Types.BYTE); // Operation + } + } + }); registerClientbound(ClientboundPackets1_20_5.PROJECTILE_POWER, wrapper -> { wrapper.passthrough(Types.VAR_INT); // Id @@ -78,6 +100,22 @@ public final class Protocol1_20_5To1_21 extends AbstractProtocol createPacketTypesProvider() { + protected PacketTypesProvider createPacketTypesProvider() { return new SimplePacketTypesProvider<>( packetTypeMap(unmappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class), - packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_20_5.class, ClientboundConfigurationPackets1_20_5.class), + packetTypeMap(mappedClientboundPacketType, ClientboundPackets1_21.class, ClientboundConfigurationPackets1_21.class), packetTypeMap(mappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class), packetTypeMap(unmappedServerboundPacketType, ServerboundPackets1_20_5.class, ServerboundConfigurationPackets1_20_5.class) ); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/data/AttributeModifierMappings1_21.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/data/AttributeModifierMappings1_21.java new file mode 100644 index 000000000..471168fb8 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/data/AttributeModifierMappings1_21.java @@ -0,0 +1,103 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viaversion.protocols.v1_20_5to1_21.data; + +import com.google.common.collect.BiMap; +import com.google.common.collect.HashBiMap; +import com.viaversion.viaversion.util.Key; +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; +import org.checkerframework.checker.nullness.qual.Nullable; + +public final class AttributeModifierMappings1_21 { + private static final Map ATTRIBUTE_MODIFIER_IDS = new HashMap<>(); + private static final Map ATTRIBUTE_MODIFIER_INVERSE_IDS = new HashMap<>(); + private static final BiMap ATTRIBUTE_MODIFIER_NAMES = HashBiMap.create(Map.of( + "Random spawn bonus", "random_spawn_bonus", + "Random zombie-spawn bonus", "zombie_random_spawn_bonus", + "Leader zombie bonus", "leader_zombie_bonus", + "Zombie reinforcement callee charge", "reinforcement_callee_charge", + "Zombie reinforcement caller charge", "reinforcement_caller_charge" + )); + + static { + add(-4483571535397864886L, -5989644940537681742L, "armor.body"); + add(8144722948526719024L, -7778190119041365872L, "effect.slowness"); + add(6967552254039378640L, -9116175396973475259L, "enchantment.aqua_affinity"); + add(5279725409867744698L, -5150363631200102632L, "attacking"); + add(148071211714102867L, -7685811609035173472L, "attacking"); + add(6196088217904236654L, -7493791321850887290L, "effect.minining_fatigue"); + add(-5084161844451524480L, -8859020046251006329L, "enchantment.soul_speed"); + add(-7907339078496465106L, -8112074600724210224L, "enchantment.swift_sneak"); + add(6688265815086220243L, -6545541163342161890L, "drinking"); + add(8315164243412860989L, -6631520853640075966L, "creative_mode_block_range"); + add(4389663563256579765L, -4827163546944004714L, "enchantment.efficiency"); + add(6732612758648800940L, -5145707699103688244L, "effect.health_boost"); + add(9079981369298536661L, -6728494925450710401L, "covered"); + add(-1521481167610687786L, -8630419745734927691L, "effect.absorption"); + add(-7473408062188862076L, -5872005994337939597L, "creative_mode_entity_range"); + add(-3721396875562958315L, -5317020504214661337L, "effect.unluck"); + add(-2861585646493481178L, -6113244764726669811L, "armor.leggings"); + add(6718535547217657911L, -5386630269401489641L, "enchantment.sweeping_edge"); + add(-7949229004988660584L, -7828611303000832459L, "effect.speed"); + add(-8650171790042118250L, -5749650997644763080L, "enchantment.soul_speed"); + add(551224288813600377L, -8734740027710371860L, "enchantment.respiration"); + add(-7046399332347654691L, -6723081531683397260L, "suffocating"); + add(7361814797886573596L, -8641397326606817395L, "sprinting"); + add(-6972338111383059132L, -8978659762232839026L, "armor.chestplate"); + add(-5371971015925809039L, -6062243582569928137L, "enchantment.fire_protection"); + add(7245570952092733273L, -8449101711440750679L, "effect.strength"); + add(-422425648963762075L, -5756800103171642205L, "base_attack_speed"); + add(-4607081316629330256L, -7008565754814018370L, "effect.jump_boost"); + add(271280981090454338L, -8746077033958322898L, "effect.luck"); + add(2211131075215181206L, -5513857709499300658L, "powder_snow"); + add(-8908768238899017377L, -8313820693701227669L, "armor.boots"); + add(-5797418877589107702L, -6181652684028920077L, "effect.haste"); + add(3086076556416732775L, -5150312587563650736L, "armor.helmet"); + add(-5082757096938257406L, -4891139119377885130L, "baby"); + add(2478452629826324956L, -7247530463494186011L, "effect.weakness"); + add(4659420831966187055L, -5191473055587376048L, "enchantment.blast_protection"); + add(7301951777949303281L, -6753860660653972126L, "evil"); + add(8533189226688352746L, -8254757081029716377L, "baby"); + add(1286946037536540352L, -5768092872487507967L, "enchantment.depth_strider"); + add(-3801225194067177672L, -6586624321849018929L, "base_attack_damage"); + } + + public static @Nullable String uuidToId(final UUID uuid) { + return ATTRIBUTE_MODIFIER_IDS.get(uuid); + } + + public static @Nullable UUID idToUuid(final String id) { + return ATTRIBUTE_MODIFIER_INVERSE_IDS.get(Key.stripMinecraftNamespace(id)); + } + + public static @Nullable String nameToId(final String name) { + return ATTRIBUTE_MODIFIER_NAMES.get(name); + } + + public static @Nullable String idToName(final String id) { + return ATTRIBUTE_MODIFIER_NAMES.inverse().get(id); + } + + private static void add(final long msb, final long lsb, final String id) { + final UUID uuid = new UUID(msb, lsb); + ATTRIBUTE_MODIFIER_IDS.put(uuid, id); + ATTRIBUTE_MODIFIER_INVERSE_IDS.put(id, uuid); + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/packet/ClientboundConfigurationPackets1_21.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/packet/ClientboundConfigurationPackets1_21.java new file mode 100644 index 000000000..4da7cdc44 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/packet/ClientboundConfigurationPackets1_21.java @@ -0,0 +1,56 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viaversion.protocols.v1_20_5to1_21.packet; + +import com.viaversion.viaversion.api.protocol.packet.State; + +public enum ClientboundConfigurationPackets1_21 implements ClientboundPacket1_21 { + + COOKIE_REQUEST, // 0x00 + CUSTOM_PAYLOAD, // 0x01 + DISCONNECT, // 0x02 + FINISH_CONFIGURATION, // 0x03 + KEEP_ALIVE, // 0x04 + PING, // 0x05 + RESET_CHAT, // 0x06 + REGISTRY_DATA, // 0x07 + RESOURCE_PACK_POP, // 0x08 + RESOURCE_PACK_PUSH, // 0x09 + STORE_COOKIE, // 0x0A + TRANSFER, // 0x0B + UPDATE_ENABLED_FEATURES, // 0x0C + UPDATE_TAGS, // 0x0D + SELECT_KNOWN_PACKS, // 0x0E + CUSTOM_REPORT_DETAILS, // 0x0F + SERVER_LINKS; // 0x10 + + @Override + public int getId() { + return ordinal(); + } + + @Override + public String getName() { + return name(); + } + + @Override + public State state() { + return State.CONFIGURATION; + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/packet/ClientboundPacket1_21.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/packet/ClientboundPacket1_21.java new file mode 100644 index 000000000..0ebae4a04 --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/packet/ClientboundPacket1_21.java @@ -0,0 +1,23 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viaversion.protocols.v1_20_5to1_21.packet; + +import com.viaversion.viaversion.api.protocol.packet.ClientboundPacketType; + +public interface ClientboundPacket1_21 extends ClientboundPacketType { +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/packet/ClientboundPackets1_21.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/packet/ClientboundPackets1_21.java new file mode 100644 index 000000000..c434361ad --- /dev/null +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/packet/ClientboundPackets1_21.java @@ -0,0 +1,156 @@ +/* + * This file is part of ViaVersion - https://github.com/ViaVersion/ViaVersion + * Copyright (C) 2016-2024 ViaVersion and contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ +package com.viaversion.viaversion.protocols.v1_20_5to1_21.packet; + +public enum ClientboundPackets1_21 implements ClientboundPacket1_21 { + + BUNDLE_DELIMITER, // 0x00 + ADD_ENTITY, // 0x01 + ADD_EXPERIENCE_ORB, // 0x02 + ANIMATE, // 0x03 + AWARD_STATS, // 0x04 + BLOCK_CHANGED_ACK, // 0x05 + BLOCK_DESTRUCTION, // 0x06 + BLOCK_ENTITY_DATA, // 0x07 + BLOCK_EVENT, // 0x08 + BLOCK_UPDATE, // 0x09 + BOSS_EVENT, // 0x0A + CHANGE_DIFFICULTY, // 0x0B + CHUNK_BATCH_FINISHED, // 0x0C + CHUNK_BATCH_START, // 0x0D + CHUNKS_BIOMES, // 0x0E + CLEAR_TITLES, // 0x0F + COMMAND_SUGGESTIONS, // 0x10 + COMMANDS, // 0x11 + CONTAINER_CLOSE, // 0x12 + CONTAINER_SET_CONTENT, // 0x13 + CONTAINER_SET_DATA, // 0x14 + CONTAINER_SET_SLOT, // 0x15 + COOKIE_REQUEST, // 0x16 + COOLDOWN, // 0x17 + CUSTOM_CHAT_COMPLETIONS, // 0x18 + CUSTOM_PAYLOAD, // 0x19 + DAMAGE_EVENT, // 0x1A + DEBUG_SAMPLE, // 0x1B + DELETE_CHAT, // 0x1C + DISCONNECT, // 0x1D + DISGUISED_CHAT, // 0x1E + ENTITY_EVENT, // 0x1F + EXPLODE, // 0x20 + FORGET_LEVEL_CHUNK, // 0x21 + GAME_EVENT, // 0x22 + HORSE_SCREEN_OPEN, // 0x23 + HURT_ANIMATION, // 0x24 + INITIALIZE_BORDER, // 0x25 + KEEP_ALIVE, // 0x26 + LEVEL_CHUNK_WITH_LIGHT, // 0x27 + LEVEL_EVENT, // 0x28 + LEVEL_PARTICLES, // 0x29 + LIGHT_UPDATE, // 0x2A + LOGIN, // 0x2B + MAP_ITEM_DATA, // 0x2C + MERCHANT_OFFERS, // 0x2D + MOVE_ENTITY_POS, // 0x2E + MOVE_ENTITY_POS_ROT, // 0x2F + MOVE_ENTITY_ROT, // 0x30 + MOVE_VEHICLE, // 0x31 + OPEN_BOOK, // 0x32 + OPEN_SCREEN, // 0x33 + OPEN_SIGN_EDITOR, // 0x34 + PING, // 0x35 + PONG_RESPONSE, // 0x36 + PLACE_GHOST_RECIPE, // 0x37 + PLAYER_ABILITIES, // 0x38 + PLAYER_CHAT, // 0x39 + PLAYER_COMBAT_END, // 0x3A + PLAYER_COMBAT_ENTER, // 0x3B + PLAYER_COMBAT_KILL, // 0x3C + PLAYER_INFO_REMOVE, // 0x3D + PLAYER_INFO_UPDATE, // 0x3E + PLAYER_LOOK_AT, // 0x3F + PLAYER_POSITION, // 0x40 + RECIPE, // 0x41 + REMOVE_ENTITIES, // 0x42 + REMOVE_MOB_EFFECT, // 0x43 + RESET_SCORE, // 0x44 + RESOURCE_PACK_POP, // 0x45 + RESOURCE_PACK_PUSH, // 0x46 + RESPAWN, // 0x47 + ROTATE_HEAD, // 0x48 + SECTION_BLOCKS_UPDATE, // 0x49 + SELECT_ADVANCEMENTS_TAB, // 0x4A + SERVER_DATA, // 0x4B + SET_ACTION_BAR_TEXT, // 0x4C + SET_BORDER_CENTER, // 0x4D + SET_BORDER_LERP_SIZE, // 0x4E + SET_BORDER_SIZE, // 0x4F + SET_BORDER_WARNING_DELAY, // 0x50 + SET_BORDER_WARNING_DISTANCE, // 0x51 + SET_CAMERA, // 0x52 + SET_CARRIED_ITEM, // 0x53 + SET_CHUNK_CACHE_CENTER, // 0x54 + SET_CHUNK_CACHE_RADIUS, // 0x55 + SET_DEFAULT_SPAWN_POSITION, // 0x56 + SET_DISPLAY_OBJECTIVE, // 0x57 + SET_ENTITY_DATA, // 0x58 + SET_ENTITY_LINK, // 0x59 + SET_ENTITY_MOTION, // 0x5A + SET_EQUIPMENT, // 0x5B + SET_EXPERIENCE, // 0x5C + SET_HEALTH, // 0x5D + SET_OBJECTIVE, // 0x5E + SET_PASSENGERS, // 0x5F + SET_PLAYER_TEAM, // 0x60 + SET_SCORE, // 0x61 + SET_SIMULATION_DISTANCE, // 0x62 + SET_SUBTITLE_TEXT, // 0x63 + SET_TIME, // 0x64 + SET_TITLE_TEXT, // 0x65 + SET_TITLES_ANIMATION, // 0x66 + SOUND_ENTITY, // 0x67 + SOUND, // 0x68 + START_CONFIGURATION, // 0x69 + STOP_SOUND, // 0x6A + STORE_COOKIE, // 0x6B + SYSTEM_CHAT, // 0x6C + TAB_LIST, // 0x6D + TAG_QUERY, // 0x6E + TAKE_ITEM_ENTITY, // 0x6F + TELEPORT_ENTITY, // 0x70 + TICKING_STATE, // 0x71 + TICKING_STEP, // 0x72 + TRANSFER, // 0x73 + UPDATE_ADVANCEMENTS, // 0x74 + UPDATE_ATTRIBUTES, // 0x75 + UPDATE_MOB_EFFECT, // 0x76 + UPDATE_RECIPES, // 0x77 + UPDATE_TAGS, // 0x78 + PROJECTILE_POWER, // 0x79 + CUSTOM_REPORT_DETAILS, // 0x7A + SERVER_LINKS; // 0x7B + + @Override + public int getId() { + return ordinal(); + } + + @Override + public String getName() { + return name(); + } +} diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/BlockItemPacketRewriter1_21.java b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/BlockItemPacketRewriter1_21.java index df5eacd2f..6667e0ccd 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/BlockItemPacketRewriter1_21.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/v1_20_5to1_21/rewriter/BlockItemPacketRewriter1_21.java @@ -18,20 +18,25 @@ package com.viaversion.viaversion.protocols.v1_20_5to1_21.rewriter; import com.viaversion.viaversion.api.connection.UserConnection; +import com.viaversion.viaversion.api.minecraft.data.StructuredDataContainer; import com.viaversion.viaversion.api.minecraft.data.StructuredDataKey; import com.viaversion.viaversion.api.minecraft.item.Item; +import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers1_20_5; +import com.viaversion.viaversion.api.minecraft.item.data.AttributeModifiers1_21; import com.viaversion.viaversion.api.type.Types; import com.viaversion.viaversion.api.type.types.chunk.ChunkType1_20_2; 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.protocols.v1_20_5to1_21.Protocol1_20_5To1_21; import com.viaversion.viaversion.protocols.v1_20_2to1_20_3.rewriter.RecipeRewriter1_20_3; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPacket1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ClientboundPackets1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPacket1_20_5; import com.viaversion.viaversion.protocols.v1_20_3to1_20_5.packet.ServerboundPackets1_20_5; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.Protocol1_20_5To1_21; +import com.viaversion.viaversion.protocols.v1_20_5to1_21.data.AttributeModifierMappings1_21; import com.viaversion.viaversion.rewriter.BlockRewriter; import com.viaversion.viaversion.rewriter.StructuredItemRewriter; +import java.util.Arrays; import org.checkerframework.checker.nullness.qual.Nullable; public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter { @@ -79,10 +84,23 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter { + final AttributeModifiers1_21.AttributeModifier[] modifiers = Arrays.stream(attributeModifiers.modifiers()).map(modifier -> { + final AttributeModifiers1_20_5.ModifierData modData = modifier.modifier(); + final AttributeModifiers1_21.ModifierData updatedModData = new AttributeModifiers1_21.ModifierData(Protocol1_20_5To1_21.mapAttributeUUID(modData.uuid(), modData.name()), modData.amount(), modData.operation()); + return new AttributeModifiers1_21.AttributeModifier(modifier.attribute(), updatedModData, modifier.slotType()); + }).toArray(AttributeModifiers1_21.AttributeModifier[]::new); + return new AttributeModifiers1_21(modifiers, attributeModifiers.showInTooltip()); + }); + } + @Override public @Nullable Item handleItemToServer(final UserConnection connection, @Nullable final Item item) { if (item == null) { @@ -90,7 +108,27 @@ public final class BlockItemPacketRewriter1_21 extends StructuredItemRewriter { + final AttributeModifiers1_20_5.AttributeModifier[] modifiers = Arrays.stream(attributeModifiers.modifiers()).map(modifier -> { + final AttributeModifiers1_21.ModifierData modData = modifier.modifier(); + final String name = AttributeModifierMappings1_21.idToName(modData.id()); + final AttributeModifiers1_20_5.ModifierData updatedModData = new AttributeModifiers1_20_5.ModifierData( + Protocol1_20_5To1_21.mapAttributeId(modData.id()), + name != null ? name : modData.id(), + modData.amount(), + modData.operation() + ); + return new AttributeModifiers1_20_5.AttributeModifier(modifier.attribute(), updatedModData, modifier.slotType()); + }).toArray(AttributeModifiers1_20_5.AttributeModifier[]::new); + return new AttributeModifiers1_20_5(modifiers, attributeModifiers.showInTooltip()); + }); + } } \ No newline at end of file diff --git a/common/src/main/java/com/viaversion/viaversion/rewriter/AttributeRewriter.java b/common/src/main/java/com/viaversion/viaversion/rewriter/AttributeRewriter.java index 9d89d45ee..5403af5fe 100644 --- a/common/src/main/java/com/viaversion/viaversion/rewriter/AttributeRewriter.java +++ b/common/src/main/java/com/viaversion/viaversion/rewriter/AttributeRewriter.java @@ -28,7 +28,7 @@ public class AttributeRewriter { this.protocol = protocol; } - public void register1_20_5(C packetType) { + public void register1_21(C packetType) { protocol.registerClientbound(packetType, wrapper -> { wrapper.passthrough(Types.VAR_INT); // Entity ID @@ -43,7 +43,7 @@ public class AttributeRewriter { wrapper.read(Types.DOUBLE); // Base final int modifierSize = wrapper.read(Types.VAR_INT); for (int j = 0; j < modifierSize; j++) { - wrapper.read(Types.UUID); // ID + wrapper.read(Types.STRING); // ID wrapper.read(Types.DOUBLE); // Amount wrapper.read(Types.BYTE); // Operation } @@ -54,7 +54,7 @@ public class AttributeRewriter { wrapper.passthrough(Types.DOUBLE); // Base final int modifierSize = wrapper.passthrough(Types.VAR_INT); for (int j = 0; j < modifierSize; j++) { - wrapper.passthrough(Types.UUID); // ID + wrapper.passthrough(Types.STRING); // ID wrapper.passthrough(Types.DOUBLE); // Amount wrapper.passthrough(Types.BYTE); // Operation } diff --git a/common/src/main/resources/assets/viaversion/data/enchantments-1.21.nbt b/common/src/main/resources/assets/viaversion/data/enchantments-1.21.nbt index 97dfdcde0..442386850 100644 Binary files a/common/src/main/resources/assets/viaversion/data/enchantments-1.21.nbt and b/common/src/main/resources/assets/viaversion/data/enchantments-1.21.nbt differ diff --git a/common/src/main/resources/assets/viaversion/data/identifier-table.nbt b/common/src/main/resources/assets/viaversion/data/identifier-table.nbt index 32aa5c473..b32d3f93e 100644 Binary files a/common/src/main/resources/assets/viaversion/data/identifier-table.nbt and b/common/src/main/resources/assets/viaversion/data/identifier-table.nbt differ diff --git a/common/src/main/resources/assets/viaversion/data/identifiers-1.21.nbt b/common/src/main/resources/assets/viaversion/data/identifiers-1.21.nbt index 9554efb7c..96637200a 100644 Binary files a/common/src/main/resources/assets/viaversion/data/identifiers-1.21.nbt and b/common/src/main/resources/assets/viaversion/data/identifiers-1.21.nbt differ diff --git a/common/src/main/resources/assets/viaversion/data/mappings-1.20.5to1.21.nbt b/common/src/main/resources/assets/viaversion/data/mappings-1.20.5to1.21.nbt index d0afdf0fd..96c11b94c 100644 Binary files a/common/src/main/resources/assets/viaversion/data/mappings-1.20.5to1.21.nbt and b/common/src/main/resources/assets/viaversion/data/mappings-1.20.5to1.21.nbt differ diff --git a/gradle.properties b/gradle.properties index fddbc49f9..fe8b463b5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,5 +1,5 @@ # Project properties - we put these here so they can be modified without causing a recompile of the build scripts -projectVersion=5.0.0-24w20a-SNAPSHOT +projectVersion=5.0.0-24w21b-SNAPSHOT # Smile emoji mcVersions=1.20.6,1.20.5,1.20.4, 1.20.3, 1.20.2, 1.20.1, 1.20, 1.19.4, 1.19.3, 1.19.2, 1.19.1, 1.19, 1.18.2, 1.18.1, 1.18, 1.17.1, 1.17, 1.16.5, 1.16.4, 1.16.3, 1.16.2, 1.16.1, 1.16, 1.15.2, 1.15.1, 1.15, 1.14.4, 1.14.3, 1.14.2, 1.14.1, 1.14, 1.13.2, 1.13.1, 1.13, 1.12.2, 1.12.1, 1.12, 1.11.2, 1.11.1, 1.11, 1.10.2, 1.10.1, 1.10, 1.9.4, 1.9.3, 1.9.2, 1.9.1, 1.9, 1.8.9 diff --git a/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java b/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java index bda1b1774..357ad231c 100644 --- a/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java +++ b/template/src/main/java/com/viaversion/viaversion/template/protocols/Protocol1_99To_98.java @@ -70,7 +70,7 @@ public final class Protocol1_99To_98 extends AbstractProtocol(this).register(ClientboundPackets1_20_5.AWARD_STATS); - new AttributeRewriter<>(this).register1_20_5(ClientboundPackets1_20_5.UPDATE_ATTRIBUTES); + new AttributeRewriter<>(this).register1_21(ClientboundPackets1_20_5.UPDATE_ATTRIBUTES); // Uncomment if an existing type changed serialization format. Mappings for argument type keys can also be defined in mapping files /*final CommandRewriter1_19_4 commandRewriter = new CommandRewriter1_19_4(this) {