/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.serialization.Codec * com.mojang.serialization.JavaOps * org.jspecify.annotations.Nullable */ package net.minecraft.core; import com.mojang.serialization.Codec; import com.mojang.serialization.JavaOps; import java.util.HashMap; import java.util.Map; import net.minecraft.core.HolderLookup; import net.minecraft.core.Registry; import net.minecraft.resources.RegistryOps; import net.minecraft.resources.ResourceKey; import org.jspecify.annotations.Nullable; public class Cloner { private final Codec directCodec; private Cloner(Codec directCodec) { this.directCodec = directCodec; } public T clone(T value, HolderLookup.Provider from, HolderLookup.Provider to) { RegistryOps sourceOps = from.createSerializationContext(JavaOps.INSTANCE); RegistryOps targetOps = to.createSerializationContext(JavaOps.INSTANCE); Object serialized = this.directCodec.encodeStart(sourceOps, value).getOrThrow(error -> new IllegalStateException("Failed to encode: " + error)); return (T)this.directCodec.parse(targetOps, serialized).getOrThrow(error -> new IllegalStateException("Failed to decode: " + error)); } public static class Factory { private final Map>, Cloner> codecs = new HashMap(); public Factory addCodec(ResourceKey> key, Codec codec) { this.codecs.put(key, new Cloner(codec)); return this; } public @Nullable Cloner cloner(ResourceKey> key) { return this.codecs.get(key); } } }