From eac273fcea9d5caf968fdbb31cedb4fefff4fb91 Mon Sep 17 00:00:00 2001 From: mschae23 <46165762+mschae23@users.noreply.github.com> Date: Sun, 1 Dec 2024 13:33:29 +0100 Subject: [PATCH] Add version to server config packet for forward compatibility --- build.gradle | 6 +++--- gradle.properties | 2 +- .../config/sync/ServerConfigS2CPayload.java | 8 +++++++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/build.gradle b/build.gradle index 42e9345..09b2edc 100644 --- a/build.gradle +++ b/build.gradle @@ -3,8 +3,8 @@ plugins { id 'maven-publish' } -sourceCompatibility = JavaVersion.VERSION_17 -targetCompatibility = JavaVersion.VERSION_17 +sourceCompatibility = JavaVersion.VERSION_21 +targetCompatibility = JavaVersion.VERSION_21 version = "${project.mod_version}+${project.minecraft_version}" group = project.maven_group @@ -81,7 +81,7 @@ processResources { tasks.withType(JavaCompile).configureEach { // Minecraft 1.18 (1.18-pre2) upwards uses Java 17. - it.options.release = 17 + it.options.release = 21 } java { diff --git a/gradle.properties b/gradle.properties index 69f074c..b49b5a5 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs=-Xmx1G loader_version=0.16.9 # Mod Properties - mod_version = 4.0.0-beta.1 + mod_version = 4.0.0-beta.2 maven_group = de.mschae23.minecraft.mod archives_base_name = grind-enchantments diff --git a/src/main/java/de/mschae23/grindenchantments/config/sync/ServerConfigS2CPayload.java b/src/main/java/de/mschae23/grindenchantments/config/sync/ServerConfigS2CPayload.java index eb22b78..baf7c97 100644 --- a/src/main/java/de/mschae23/grindenchantments/config/sync/ServerConfigS2CPayload.java +++ b/src/main/java/de/mschae23/grindenchantments/config/sync/ServerConfigS2CPayload.java @@ -21,6 +21,7 @@ import net.minecraft.network.PacketByteBuf; import net.minecraft.network.codec.PacketCodec; +import net.minecraft.network.codec.PacketCodecs; import net.minecraft.network.packet.CustomPayload; import net.minecraft.util.Identifier; import de.mschae23.grindenchantments.GrindEnchantmentsMod; @@ -37,6 +38,11 @@ public Id getId() { } public static PacketCodec createPacketCodec(PacketCodec costFunctionCodec) { - return ServerConfig.createPacketCodec(costFunctionCodec).xmap(ServerConfigS2CPayload::new, ServerConfigS2CPayload::config); + return PacketCodec.tuple( + // Version field for forward compatibility + PacketCodecs.BYTE, payload -> (byte) 1, + ServerConfig.createPacketCodec(costFunctionCodec), ServerConfigS2CPayload::config, + (version, config) -> new ServerConfigS2CPayload(config) + ); } }