From 58d7dc7ca6c465f9d9ab8c516345d0f3e9553627 Mon Sep 17 00:00:00 2001 From: Nassim Jahnke Date: Fri, 10 May 2024 17:02:16 +0200 Subject: [PATCH] 24w19a --- .../data/StructuredDataContainer.java | 7 +++++ .../api/minecraft/data/StructuredDataKey.java | 9 ++++--- .../minecraft/item/data/FoodProperties.java | 24 ++++++++++++++++- .../api/protocol/version/ProtocolVersion.java | 2 +- .../api/type/types/item/ItemType1_20_5.java | 8 ++++++ .../api/type/types/version/Types1_21.java | 3 ++- .../Protocol1_21To1_20_5.java | 15 ++++++++--- .../rewriter/BlockItemPacketRewriter1_21.java | 25 +++++++++++++++++- .../Protocol1_20_3To1_20_5.java | 2 +- .../BlockItemPacketRewriter1_20_5.java | 2 +- .../rewriter/ComponentRewriter1_20_5.java | 2 +- .../rewriter/StructuredDataConverter.java | 2 +- .../viaversion/data/enchantments-1.21.nbt | Bin 29022 -> 29507 bytes .../viaversion/data/identifiers-1.21.nbt | Bin 4864 -> 4888 bytes .../viaversion/data/mappings-1.20.5to1.21.nbt | Bin 312 -> 336 bytes gradle.properties | 2 +- 16 files changed, 87 insertions(+), 16 deletions(-) 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 2c613fe55e60dc266557f358a17040d4d0693452..97dfdcde0da3da1593d7624f0bffb8855cdf172e 100644 GIT binary patch delta 480 zcmccji1F|<#tn(WEX;{{m7CLrtJoyil5+Bsvx^z{b2IZ&lZz75O03EgOHzv_-*0UI~LJLJQcC_=23objMWCH`M$#O2- zlX;@$Cm-4siTvbi7CW>#7+@||P)69F1~fE2vA6(ea(qr^dPYfNQcmjRK1*>9 zE(X@LoYKsc$&6B>tf{#LC6$wxSUPKC^N$$9JcxgiGZORCQ#U`gWM-T^-$Q~M$(G4{ z7TTK)tZxE+SHL%UmId!-O_x9s0T!T+6fOq#)U-69Q;NAJ_eE$-PE0YI{3}9hvuY$S zw;~sV9KxF9qWt3Gr2O)DpiM>TsqrP5xv4N^)B=j5ZQ3P3rR$jSX?5E}up84#NTu{99e0I>rQI|8v25W51g8xVT|u{RJ00CC{vYiu!0K%0y?^H|sz z-!d>TUY|UlH=Oa^=Fhx&OklTcP8Dc`y6TnSF^KcF2$_n59L&hTl$pZJ%)nBdS(VDb Jz+l0^0035xI4}SJ delta 186 zcmbQC)}S^)nuURZp?RbHO-3Mt)o1b_MoGq_o5h&&SproV7?{<7SRIHpfLIHNwSia< zi1mTk5Qt5I*bIoRfY=&{?Sa?w1a6vi4YS51IrX3Uck-3RFcoYz`!(d-X;KH*9Noz 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