mirror of
https://github.com/GeyserMC/Rainbow.git
synced 2025-12-19 14:59:16 +00:00
Use RegistryOps to save Geyser mappings
This commit is contained in:
@@ -5,6 +5,7 @@ import com.google.gson.GsonBuilder;
|
|||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.mojang.serialization.Codec;
|
import com.mojang.serialization.Codec;
|
||||||
import com.mojang.serialization.DataResult;
|
import com.mojang.serialization.DataResult;
|
||||||
|
import com.mojang.serialization.DynamicOps;
|
||||||
import com.mojang.serialization.JsonOps;
|
import com.mojang.serialization.JsonOps;
|
||||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||||
import net.minecraft.util.ExtraCodecs;
|
import net.minecraft.util.ExtraCodecs;
|
||||||
@@ -47,10 +48,14 @@ public class CodecUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> T tryReadJson(Codec<T> codec, Path path) throws IOException {
|
public static <T> T tryReadJson(Codec<T> codec, Path path) throws IOException {
|
||||||
|
return tryReadJson(codec, path, JsonOps.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> T tryReadJson(Codec<T> codec, Path path, DynamicOps<JsonElement> ops) throws IOException {
|
||||||
try {
|
try {
|
||||||
String raw = Files.readString(path);
|
String raw = Files.readString(path);
|
||||||
JsonElement json = GSON.fromJson(raw, JsonElement.class);
|
JsonElement json = GSON.fromJson(raw, JsonElement.class);
|
||||||
return codec.parse(JsonOps.INSTANCE, json).getOrThrow();
|
return codec.parse(ops, json).getOrThrow();
|
||||||
} catch (IOException exception) {
|
} catch (IOException exception) {
|
||||||
Rainbow.LOGGER.warn("Failed to read JSON file {}!", path, exception);
|
Rainbow.LOGGER.warn("Failed to read JSON file {}!", path, exception);
|
||||||
throw exception;
|
throw exception;
|
||||||
@@ -58,7 +63,11 @@ public class CodecUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static <T> void trySaveJson(Codec<T> codec, T object, Path path) throws IOException {
|
public static <T> void trySaveJson(Codec<T> codec, T object, Path path) throws IOException {
|
||||||
JsonElement json = codec.encodeStart(JsonOps.INSTANCE, object).getOrThrow();
|
trySaveJson(codec, object, path, JsonOps.INSTANCE);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> void trySaveJson(Codec<T> codec, T object, Path path, DynamicOps<JsonElement> ops) throws IOException {
|
||||||
|
JsonElement json = codec.encodeStart(ops, object).getOrThrow();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ensureDirectoryExists(path.getParent());
|
ensureDirectoryExists(path.getParent());
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package org.geysermc.rainbow.pack;
|
package org.geysermc.rainbow.pack;
|
||||||
|
|
||||||
|
import com.mojang.serialization.JsonOps;
|
||||||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
|
||||||
import it.unimi.dsi.fastutil.ints.IntSet;
|
import it.unimi.dsi.fastutil.ints.IntSet;
|
||||||
import net.fabricmc.loader.api.FabricLoader;
|
import net.fabricmc.loader.api.FabricLoader;
|
||||||
import net.minecraft.client.Minecraft;
|
import net.minecraft.client.Minecraft;
|
||||||
import net.minecraft.client.gui.components.SplashRenderer;
|
import net.minecraft.client.gui.components.SplashRenderer;
|
||||||
import net.minecraft.core.component.DataComponents;
|
import net.minecraft.core.component.DataComponents;
|
||||||
|
import net.minecraft.resources.RegistryOps;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.util.ProblemReporter;
|
import net.minecraft.util.ProblemReporter;
|
||||||
import net.minecraft.util.RandomSource;
|
import net.minecraft.util.RandomSource;
|
||||||
@@ -145,10 +147,10 @@ public class BedrockPack {
|
|||||||
boolean success = true;
|
boolean success = true;
|
||||||
|
|
||||||
try {
|
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(PackManifest.CODEC, manifest, packPath.resolve(MANIFEST_FILE));
|
||||||
CodecUtil.trySaveJson(BedrockTextureAtlas.CODEC, BedrockTextureAtlas.itemAtlas(name, itemTextures), packPath.resolve(ITEM_ATLAS_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);
|
reporter.forChild(() -> "saving Geyser mappings, pack manifest, and texture atlas ").report(() -> "failed to save to pack: " + exception);
|
||||||
success = false;
|
success = false;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user