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 53a522475..6e6b66770 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 @@ -105,6 +105,13 @@ public final class StructuredDataContainer { } } + public void replaceKey(final StructuredDataKey key, final StructuredDataKey toKey) { + final StructuredData data = remove(key); + if (data != null) { + set(toKey, data.value()); + } + } + public void set(final StructuredDataKey key) { this.set(key, Unit.INSTANCE); } 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 e8edcb937..8119b65a2 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 @@ -47,9 +47,9 @@ import com.viaversion.viaversion.api.minecraft.item.data.SuspiciousStewEffect; import com.viaversion.viaversion.api.minecraft.item.data.ToolProperties; import com.viaversion.viaversion.api.minecraft.item.data.Unbreakable; import com.viaversion.viaversion.api.minecraft.item.data.WrittenBook; -import com.viaversion.viaversion.api.type.Type; -import com.viaversion.viaversion.api.type.Types; -import com.viaversion.viaversion.api.type.types.version.Types1_20_5; +import com.viaversion.viaversion.api.Types.Type; +import com.viaversion.viaversion.api.Types.Types; +import com.viaversion.viaversion.api.Types.types.version.Types1_20_5; import com.viaversion.viaversion.util.Unit; public record StructuredDataKey(String identifier, Type type) { @@ -74,7 +74,8 @@ public record StructuredDataKey(String identifier, Type type) { public static final StructuredDataKey CREATIVE_SLOT_LOCK = new StructuredDataKey<>("creative_slot_lock", Types.EMPTY); public static final StructuredDataKey ENCHANTMENT_GLINT_OVERRIDE = new StructuredDataKey<>("enchantment_glint_override", Types.BOOLEAN); public static final StructuredDataKey INTANGIBLE_PROJECTILE = new StructuredDataKey<>("intangible_projectile", Types.TAG); // Doesn't actually hold data - public static final StructuredDataKey FOOD = new StructuredDataKey<>("food", FoodProperties.TYPE); + public static final StructuredDataKey FOOD1_20_5 = new StructuredDataKey<>("food", FoodProperties.TYPE1_20_5); + public static final StructuredDataKey FOOD1_21 = new StructuredDataKey<>("food", FoodProperties.TYPE1_21); public static final StructuredDataKey FIRE_RESISTANT = new StructuredDataKey<>("fire_resistant", Types.EMPTY); public static final StructuredDataKey TOOL = new StructuredDataKey<>("tool", ToolProperties.TYPE); public static final StructuredDataKey STORED_ENCHANTMENTS = new StructuredDataKey<>("stored_enchantments", Enchantments.TYPE); diff --git a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java index 7c582d27c..8206cfe4a 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java +++ b/api/src/main/java/com/viaversion/viaversion/api/minecraft/item/data/FoodProperties.java @@ -24,12 +24,13 @@ 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.version.Types1_21; import io.netty.buffer.ByteBuf; public record FoodProperties(int nutrition, float saturationModifier, boolean canAlwaysEat, float eatSeconds, FoodEffect[] possibleEffects) { - public static final Type TYPE = new Type<>(FoodProperties.class) { + public static final Type TYPE1_20_5 = new Type<>(FoodProperties.class) { @Override public FoodProperties read(final ByteBuf buffer) { final int nutrition = Types.VAR_INT.readPrimitive(buffer); @@ -49,5 +50,26 @@ public record FoodProperties(int nutrition, float saturationModifier, boolean ca FoodEffect.ARRAY_TYPE.write(buffer, value.possibleEffects); } }; + public static final Type TYPE1_21 = new Type(FoodProperties.class) { + @Override + public FoodProperties read(final ByteBuf buffer) throws Exception { + final int nutrition = Type.VAR_INT.readPrimitive(buffer); + final float saturationModifier = buffer.readFloat(); + final boolean canAlwaysEat = buffer.readBoolean(); + final float eatSeconds = buffer.readFloat(); + final Item usingConvertsTo = Types1_21.OPTIONAL_ITEM.read(buffer); + final FoodEffect[] possibleEffects = FoodEffect.ARRAY_TYPE.read(buffer); + return new FoodProperties(nutrition, saturationModifier, canAlwaysEat, eatSeconds, usingConvertsTo, possibleEffects); + } + @Override + public void write(final ByteBuf buffer, final FoodProperties value) throws Exception { + Type.VAR_INT.writePrimitive(buffer, value.nutrition); + buffer.writeFloat(value.saturationModifier); + buffer.writeBoolean(value.canAlwaysEat); + buffer.writeFloat(value.eatSeconds); + Types1_21.OPTIONAL_ITEM.write(buffer, value.usingConvertsTo); + FoodEffect.ARRAY_TYPE.write(buffer, value.possibleEffects); + } + }; } 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 cdba22f1d..62671b240 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, 193, "1.21"); + public static final ProtocolVersion v1_21 = register(767, 194, "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/types/item/ItemType1_20_5.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_5.java index 40717433f..89ef06f88 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_5.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/item/ItemType1_20_5.java @@ -28,6 +28,7 @@ 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.StructuredItem; +import com.viaversion.viaversion.api.type.OptionalType; import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.Types; import io.netty.buffer.ByteBuf; @@ -114,4 +115,11 @@ public class ItemType1_20_5 extends Type { } } } + + public final class OptionalItemType extends OptionalType { + + public OptionalItemType() { + super(ItemType1_20_5.this); + } + } } diff --git a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_21.java b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_21.java index 39b2ba473..a2ba8384c 100644 --- a/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_21.java +++ b/api/src/main/java/com/viaversion/viaversion/api/type/types/version/Types1_21.java @@ -42,7 +42,8 @@ public final class Types1_21 { public static final StructuredDataType STRUCTURED_DATA = new StructuredDataType(); public static final Type[]> STRUCTURED_DATA_ARRAY = new ArrayType<>(STRUCTURED_DATA); - public static final Type ITEM = new ItemType1_20_5(STRUCTURED_DATA); + public static final ItemType1_20_5 ITEM = new ItemType1_20_5(STRUCTURED_DATA); + public static final Type OPTIONAL_ITEM = ITEM.new OptionalItemType(); // Optional as in boolean prefixed, not via the amount public static final Type ITEM_ARRAY = new ArrayType<>(ITEM); public static final Type ITEM_COST = new ItemCostType1_20_5(STRUCTURED_DATA_ARRAY); public static final Type OPTIONAL_ITEM_COST = new ItemCostType1_20_5.OptionalItemCostType(ITEM_COST); diff --git a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_21to1_20_5/Protocol1_21To1_20_5.java b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_21to1_20_5/Protocol1_21To1_20_5.java index 1b2c3ff6f..b27c4eccb 100644 --- a/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_21to1_20_5/Protocol1_21To1_20_5.java +++ b/common/src/main/java/com/viaversion/viaversion/protocols/protocol1_21to1_20_5/Protocol1_21To1_20_5.java @@ -23,6 +23,7 @@ import com.viaversion.viaversion.api.minecraft.entities.EntityTypes1_20_5; import com.viaversion.viaversion.api.protocol.AbstractProtocol; import com.viaversion.viaversion.api.protocol.packet.provider.PacketTypesProvider; import com.viaversion.viaversion.api.protocol.packet.provider.SimplePacketTypesProvider; +import com.viaversion.viaversion.api.type.Type; import com.viaversion.viaversion.api.type.types.misc.ParticleType; import com.viaversion.viaversion.api.type.types.version.Types1_20_5; import com.viaversion.viaversion.api.type.types.version.Types1_21; @@ -67,13 +68,21 @@ public final class Protocol1_21To1_20_5 extends AbstractProtocol(this).register(ClientboundPackets1_20_5.STATISTICS); new AttributeRewriter<>(this).register1_20_5(ClientboundPackets1_20_5.ENTITY_PROPERTIES); + + registerClientbound(ClientboundPackets1_20_5.PROJECTILE_POWER, wrapper -> { + wrapper.passthrough(Type.VAR_INT); // Id + final double xPower = wrapper.read(Type.DOUBLE); + final double yPower = wrapper.read(Type.DOUBLE); + final double zPower = wrapper.read(Type.DOUBLE); + final double accelerationPower = Math.sqrt(xPower * xPower + yPower * yPower + zPower * zPower); + wrapper.write(Type.DOUBLE, accelerationPower); + }); } @Override protected void onMappingDataLoaded() { super.onMappingDataLoaded(); - // Added preemptively TODO Check if there are actual changes before release Types1_21.PARTICLE.filler(this) .reader("block", ParticleType.Readers.BLOCK) .reader("block_marker", ParticleType.Readers.BLOCK) @@ -81,7 +90,7 @@ public final class Protocol1_21To1_20_5 extends AbstractProtocol(protocol).register1_20_5(ClientboundPackets1_20_5.DECLARE_RECIPES); } + + @Override + public @Nullable Item handleItemToClient(final UserConnection connection, @Nullable final Item item) { + if (item == null) { + return null; + } + + super.handleItemToClient(connection, item); + item.structuredData().replaceKey(StructuredDataKey.FOOD1_20_5, StructuredDataKey.FOOD1_21); + return item; + } + + @Override + public @Nullable Item handleItemToServer(final UserConnection connection, @Nullable final Item item) { + if (item == null) { + return null; + } + + super.handleItemToServer(connection, item); + item.structuredData().replaceKey(StructuredDataKey.FOOD1_21, StructuredDataKey.FOOD1_20_5); + return item; + } } \ No newline at end of file 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 997413b5b..438dd8d52 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 @@ -261,7 +261,7 @@ public final class Protocol1_20_3To1_20_5 extends AbstractProtocol extends Co register(StructuredDataKey.ENCHANTMENT_GLINT_OVERRIDE, this::convertEnchantmentGlintOverride); register(StructuredDataKey.CREATIVE_SLOT_LOCK, null); register(StructuredDataKey.INTANGIBLE_PROJECTILE, this::convertIntangibleProjectile); - register(StructuredDataKey.FOOD, this::convertFood); + register(StructuredDataKey.FOOD1_20_5, this::convertFood); register(StructuredDataKey.FIRE_RESISTANT, this::convertFireResistant); register(StructuredDataKey.TOOL, this::convertTool); register(StructuredDataKey.STORED_ENCHANTMENTS, this::convertStoredEnchantments); 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 8508fd634..666bb1d12 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 @@ -596,7 +596,7 @@ public final class StructuredDataConverter { getBackupTag(tag).putInt("rarity", data); } }); - register(StructuredDataKey.FOOD, (data, tag) -> { + register(StructuredDataKey.FOOD1_20_5, (data, tag) -> { if (backupInconvertibleData) { final CompoundTag backupTag = new CompoundTag(); backupTag.putInt("nutrition", data.nutrition()); 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 2c613fe55..97dfdcde0 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/identifiers-1.21.nbt b/common/src/main/resources/assets/viaversion/data/identifiers-1.21.nbt index 36189349a..9554efb7c 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 54faa5422..d0afdf0fd 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 de83ae393..3d159ec3a 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-24w18a-SNAPSHOT +projectVersion=5.0.0-24w19a-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