diff options
author | Linnea Gräf <nea@nea.moe> | 2024-11-27 15:57:02 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-11-27 16:05:16 +0100 |
commit | 9df1f12970dafdbf4cb13c76c1df1caed66f4a59 (patch) | |
tree | 68ad724801f6999ae64167c70a7adcdabd572d4f /src | |
parent | 139fa705b36b845759cff9318191ff1cca526f2a (diff) | |
download | Firmament-9df1f12970dafdbf4cb13c76c1df1caed66f4a59.tar.gz Firmament-9df1f12970dafdbf4cb13c76c1df1caed66f4a59.tar.bz2 Firmament-9df1f12970dafdbf4cb13c76c1df1caed66f4a59.zip |
fix: Incorrect primary codec in lenient profile serialization
Diffstat (limited to 'src')
-rw-r--r-- | src/main/java/moe/nea/firmament/mixins/LenientProfileComponentPatch.java | 14 | ||||
-rw-r--r-- | src/main/kotlin/util/json/FirmCodecs.kt | 20 |
2 files changed, 29 insertions, 5 deletions
diff --git a/src/main/java/moe/nea/firmament/mixins/LenientProfileComponentPatch.java b/src/main/java/moe/nea/firmament/mixins/LenientProfileComponentPatch.java index b1f9ee4..76b34ba 100644 --- a/src/main/java/moe/nea/firmament/mixins/LenientProfileComponentPatch.java +++ b/src/main/java/moe/nea/firmament/mixins/LenientProfileComponentPatch.java @@ -3,6 +3,10 @@ package moe.nea.firmament.mixins; import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import com.mojang.serialization.Codec; +import com.mojang.serialization.DataResult; +import com.mojang.serialization.Lifecycle; +import com.mojang.util.UndashedUuid; +import moe.nea.firmament.util.json.FirmCodecs; import net.minecraft.component.type.ProfileComponent; import net.minecraft.util.Uuids; import org.objectweb.asm.Opcodes; @@ -13,9 +17,9 @@ import java.util.UUID; @Mixin(ProfileComponent.class) public class LenientProfileComponentPatch { - // lambda in RecordCodecBuilder.create for BASE_CODEC - @ModifyExpressionValue(method = "method_57508", at = @At(value = "FIELD", opcode = Opcodes.GETSTATIC, target = "Lnet/minecraft/util/Uuids;INT_STREAM_CODEC:Lcom/mojang/serialization/Codec;")) - private static Codec<UUID> onStaticInit(Codec<UUID> original) { - return Uuids.CODEC; - } + // lambda in RecordCodecBuilder.create for BASE_CODEC + @ModifyExpressionValue(method = "method_57508", at = @At(value = "FIELD", opcode = Opcodes.GETSTATIC, target = "Lnet/minecraft/util/Uuids;INT_STREAM_CODEC:Lcom/mojang/serialization/Codec;")) + private static Codec<UUID> onStaticInit(Codec<UUID> original) { + return FirmCodecs.UUID_LENIENT_PREFER_INT_STREAM; + } } diff --git a/src/main/kotlin/util/json/FirmCodecs.kt b/src/main/kotlin/util/json/FirmCodecs.kt new file mode 100644 index 0000000..c0863bc --- /dev/null +++ b/src/main/kotlin/util/json/FirmCodecs.kt @@ -0,0 +1,20 @@ +package moe.nea.firmament.util.json + +import com.mojang.serialization.Codec +import com.mojang.serialization.DataResult +import com.mojang.serialization.Lifecycle +import com.mojang.util.UndashedUuid +import net.minecraft.util.Uuids + +object FirmCodecs { + @JvmField + val UUID_LENIENT_PREFER_INT_STREAM = Codec.withAlternative(Uuids.INT_STREAM_CODEC, Codec.STRING.comapFlatMap( + { + try { + DataResult.success(UndashedUuid.fromStringLenient(it), Lifecycle.stable()) + } catch (ex: IllegalArgumentException) { + DataResult.error { "Invalid UUID $it: ${ex.message}" } + } + }, + UndashedUuid::toString)) +} |