/* * Decompiled with CFR 0.152. * * Could not load the following classes: * com.mojang.serialization.Lifecycle * org.jspecify.annotations.Nullable */ package net.minecraft.core; import com.mojang.serialization.Lifecycle; import java.util.Optional; import net.minecraft.core.DefaultedRegistry; import net.minecraft.core.Holder; import net.minecraft.core.MappedRegistry; import net.minecraft.core.RegistrationInfo; import net.minecraft.core.Registry; import net.minecraft.resources.Identifier; import net.minecraft.resources.ResourceKey; import net.minecraft.util.RandomSource; import org.jspecify.annotations.Nullable; public class DefaultedMappedRegistry extends MappedRegistry implements DefaultedRegistry { private final Identifier defaultKey; private Holder.Reference defaultValue; public DefaultedMappedRegistry(String defaultKey, ResourceKey> key, Lifecycle lifecycle, boolean intrusiveHolders) { super(key, lifecycle, intrusiveHolders); this.defaultKey = Identifier.parse(defaultKey); } @Override public Holder.Reference register(ResourceKey key, T value, RegistrationInfo registrationInfo) { Holder.Reference result = super.register(key, value, registrationInfo); if (this.defaultKey.equals(key.identifier())) { this.defaultValue = result; } return result; } @Override public int getId(@Nullable T thing) { int id = super.getId(thing); return id == -1 ? super.getId(this.defaultValue.value()) : id; } @Override public Identifier getKey(T thing) { Identifier k = super.getKey(thing); return k == null ? this.defaultKey : k; } @Override public T getValue(@Nullable Identifier key) { Object t = super.getValue(key); return t == null ? this.defaultValue.value() : t; } @Override public Optional getOptional(@Nullable Identifier key) { return Optional.ofNullable(super.getValue(key)); } @Override public Optional> getAny() { return Optional.ofNullable(this.defaultValue); } @Override public T byId(int id) { Object t = super.byId(id); return t == null ? this.defaultValue.value() : t; } @Override public Optional> getRandom(RandomSource random) { return super.getRandom(random).or(() -> Optional.of(this.defaultValue)); } @Override public Identifier getDefaultKey() { return this.defaultKey; } }