/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.google.common.collect.MapMaker * com.mojang.serialization.Codec * io.netty.buffer.ByteBuf */ package net.minecraft.resources; import com.google.common.collect.MapMaker; import com.mojang.serialization.Codec; import io.netty.buffer.ByteBuf; import java.util.Optional; import java.util.concurrent.ConcurrentMap; import net.minecraft.core.Registry; import net.minecraft.core.registries.Registries; import net.minecraft.network.codec.StreamCodec; import net.minecraft.resources.Identifier; public class ResourceKey { private static final ConcurrentMap> VALUES = new MapMaker().weakValues().makeMap(); private final Identifier registryName; private final Identifier identifier; public static Codec> codec(ResourceKey> registryName) { return Identifier.CODEC.xmap(name -> ResourceKey.create(registryName, name), ResourceKey::identifier); } public static StreamCodec> streamCodec(ResourceKey> registryName) { return Identifier.STREAM_CODEC.map(name -> ResourceKey.create(registryName, name), ResourceKey::identifier); } public static ResourceKey create(ResourceKey> registryName, Identifier location) { return ResourceKey.create(registryName.identifier, location); } public static ResourceKey> createRegistryKey(Identifier identifier) { return ResourceKey.create(Registries.ROOT_REGISTRY_NAME, identifier); } private static ResourceKey create(Identifier registryName, Identifier identifier) { return VALUES.computeIfAbsent(new InternKey(registryName, identifier), k -> new ResourceKey(k.registry, k.identifier)); } private ResourceKey(Identifier registryName, Identifier identifier) { this.registryName = registryName; this.identifier = identifier; } public String toString() { return "ResourceKey[" + String.valueOf(this.registryName) + " / " + String.valueOf(this.identifier) + "]"; } public boolean isFor(ResourceKey> registry) { return this.registryName.equals(registry.identifier()); } public Optional> cast(ResourceKey> registry) { return this.isFor(registry) ? Optional.of(this) : Optional.empty(); } public Identifier identifier() { return this.identifier; } public Identifier registry() { return this.registryName; } public ResourceKey> registryKey() { return ResourceKey.createRegistryKey(this.registryName); } private record InternKey(Identifier registry, Identifier identifier) { } }