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

@@ -83,6 +83,7 @@ public class CraftArt implements Art, Handleable<PaintingVariant> {
@NotNull
@Override
public NamespacedKey getKey() {
if (true) return java.util.Objects.requireNonNull(org.bukkit.Registry.ART.getKey(this), () -> this + " doesn't have a key"); // Paper
return this.key;
}

View File

@@ -65,6 +65,7 @@ public class CraftMusicInstrument extends MusicInstrument implements Handleable<
@NotNull
@Override
public NamespacedKey getKey() {
if (true) return java.util.Objects.requireNonNull(org.bukkit.Registry.INSTRUMENT.getKey(this), () -> this + " doesn't have a key"); // Paper
return this.key;
}

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
}

View File

@@ -64,6 +64,7 @@ public class CraftSound implements Sound, Handleable<SoundEvent> {
@NotNull
@Override
public NamespacedKey getKey() {
if (true) return java.util.Objects.requireNonNull(org.bukkit.Registry.SOUNDS.getKey(this), () -> this + " doesn't have a key"); // Paper
return this.key;
}

View File

@@ -67,6 +67,7 @@ public class CraftPatternType implements PatternType, Handleable<BannerPattern>
@Override
public NamespacedKey getKey() {
if (true) return java.util.Objects.requireNonNull(org.bukkit.Registry.BANNER_PATTERN.getKey(this), () -> this + " doesn't have a key"); // Paper
return this.key;
}

View File

@@ -42,6 +42,7 @@ public class CraftStructure extends Structure implements Handleable<net.minecraf
@Override
public NamespacedKey getKey() {
if (true) return java.util.Objects.requireNonNull(org.bukkit.Registry.STRUCTURE.getKey(this), () -> this + " doesn't have a key"); // Paper
return this.key;
}
}

View File

@@ -54,6 +54,7 @@ public class CraftTrimMaterial implements TrimMaterial, Handleable<net.minecraft
@Override
@NotNull
public NamespacedKey getKey() {
if (true) return java.util.Objects.requireNonNull(org.bukkit.Registry.TRIM_MATERIAL.getKey(this), () -> this + " doesn't have a key"); // Paper
return this.key;
}

View File

@@ -54,6 +54,7 @@ public class CraftTrimPattern implements TrimPattern, Handleable<net.minecraft.w
@Override
@NotNull
public NamespacedKey getKey() {
if (true) return java.util.Objects.requireNonNull(org.bukkit.Registry.TRIM_PATTERN.getKey(this), () -> this + " doesn't have a key"); // Paper
return this.key;
}