Improve Registry

This commit is contained in:
Jake Potrebic
2023-12-20 02:03:05 -08:00
parent a264c42314
commit 5b1ab02f39
9 changed files with 24 additions and 5 deletions

View File

@@ -184,6 +184,7 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
private final Class<?> bukkitClass; // Paper - relax preload class
private final Map<NamespacedKey, B> cache = new HashMap<>();
private final Map<B, NamespacedKey> byValue = new java.util.IdentityHashMap<>(); // Paper - improve Registry
private final net.minecraft.core.Registry<M> minecraftRegistry;
private final io.papermc.paper.registry.entry.RegistryTypeMapper<M, B> minecraftToBukkit; // Paper - switch to Holder
private final BiFunction<NamespacedKey, ApiVersion, NamespacedKey> serializationUpdater; // Paper - rename to make it *clear* what it is *only* for
@@ -237,6 +238,7 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
}
this.cache.put(namespacedKey, bukkit);
this.byValue.put(bukkit, namespacedKey); // Paper - improve Registry
return bukkit;
}
@@ -279,4 +281,11 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
return this.minecraftToBukkit.convertDirectHolder(holder);
}
// Paper end - support Direct Holders
// Paper start - improve Registry
@Override
public NamespacedKey getKey(final B value) {
return this.byValue.get(value);
}
// Paper end - improve Registry
}