From 1f22dbb860dcad2d21768c72620638fe1a8b5608 Mon Sep 17 00:00:00 2001 From: Eclipse Date: Mon, 25 Aug 2025 07:44:51 +0000 Subject: [PATCH] Use RegistryOps to save Geyser mappings --- src/main/java/org/geysermc/rainbow/CodecUtil.java | 13 +++++++++++-- .../java/org/geysermc/rainbow/pack/BedrockPack.java | 6 ++++-- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/geysermc/rainbow/CodecUtil.java b/src/main/java/org/geysermc/rainbow/CodecUtil.java index 86dd4ba..ee8436f 100644 --- a/src/main/java/org/geysermc/rainbow/CodecUtil.java +++ b/src/main/java/org/geysermc/rainbow/CodecUtil.java @@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder; import com.google.gson.JsonElement; import com.mojang.serialization.Codec; import com.mojang.serialization.DataResult; +import com.mojang.serialization.DynamicOps; import com.mojang.serialization.JsonOps; import com.mojang.serialization.codecs.RecordCodecBuilder; import net.minecraft.util.ExtraCodecs; @@ -47,10 +48,14 @@ public class CodecUtil { } public static T tryReadJson(Codec codec, Path path) throws IOException { + return tryReadJson(codec, path, JsonOps.INSTANCE); + } + + public static T tryReadJson(Codec codec, Path path, DynamicOps ops) throws IOException { try { String raw = Files.readString(path); JsonElement json = GSON.fromJson(raw, JsonElement.class); - return codec.parse(JsonOps.INSTANCE, json).getOrThrow(); + return codec.parse(ops, json).getOrThrow(); } catch (IOException exception) { Rainbow.LOGGER.warn("Failed to read JSON file {}!", path, exception); throw exception; @@ -58,7 +63,11 @@ public class CodecUtil { } public static void trySaveJson(Codec codec, T object, Path path) throws IOException { - JsonElement json = codec.encodeStart(JsonOps.INSTANCE, object).getOrThrow(); + trySaveJson(codec, object, path, JsonOps.INSTANCE); + } + + public static void trySaveJson(Codec codec, T object, Path path, DynamicOps ops) throws IOException { + JsonElement json = codec.encodeStart(ops, object).getOrThrow(); try { ensureDirectoryExists(path.getParent()); diff --git a/src/main/java/org/geysermc/rainbow/pack/BedrockPack.java b/src/main/java/org/geysermc/rainbow/pack/BedrockPack.java index 3198409..b3fdabb 100644 --- a/src/main/java/org/geysermc/rainbow/pack/BedrockPack.java +++ b/src/main/java/org/geysermc/rainbow/pack/BedrockPack.java @@ -1,11 +1,13 @@ package org.geysermc.rainbow.pack; +import com.mojang.serialization.JsonOps; import it.unimi.dsi.fastutil.ints.IntOpenHashSet; import it.unimi.dsi.fastutil.ints.IntSet; import net.fabricmc.loader.api.FabricLoader; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.components.SplashRenderer; import net.minecraft.core.component.DataComponents; +import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceLocation; import net.minecraft.util.ProblemReporter; import net.minecraft.util.RandomSource; @@ -145,10 +147,10 @@ public class BedrockPack { boolean success = true; try { - CodecUtil.trySaveJson(GeyserMappings.CODEC, mappings, exportPath.resolve(MAPPINGS_FILE)); + CodecUtil.trySaveJson(GeyserMappings.CODEC, mappings, exportPath.resolve(MAPPINGS_FILE), RegistryOps.create(JsonOps.INSTANCE, Minecraft.getInstance().level.registryAccess())); CodecUtil.trySaveJson(PackManifest.CODEC, manifest, packPath.resolve(MANIFEST_FILE)); CodecUtil.trySaveJson(BedrockTextureAtlas.CODEC, BedrockTextureAtlas.itemAtlas(name, itemTextures), packPath.resolve(ITEM_ATLAS_FILE)); - } catch (IOException exception) { + } catch (IOException | NullPointerException exception) { reporter.forChild(() -> "saving Geyser mappings, pack manifest, and texture atlas ").report(() -> "failed to save to pack: " + exception); success = false; }