Don't use delayed registries in impl anywhere (#11918)

This commit is contained in:
Jake Potrebic
2025-01-11 11:02:28 -08:00
committed by GitHub
parent 19ddbeff9e
commit ac3aaa248b
55 changed files with 145 additions and 133 deletions

View File

@ -2,12 +2,13 @@ package org.bukkit;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryBuilderFactory; import io.papermc.paper.registry.RegistryBuilderFactory;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider; import io.papermc.paper.registry.data.InlinedRegistryBuilderProvider;
import io.papermc.paper.registry.data.PaintingVariantRegistryEntry; import io.papermc.paper.registry.data.PaintingVariantRegistryEntry;
import java.util.Locale; import java.util.Locale;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.bukkit.packs.DataPack;
import org.bukkit.util.OldEnum; import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -18,8 +19,8 @@ import org.jetbrains.annotations.Nullable;
* <p> * <p>
* The arts listed in this interface are present in the default server * The arts listed in this interface are present in the default server
* or can be enabled via a {@link FeatureFlag}. * or can be enabled via a {@link FeatureFlag}.
* There may be additional arts present in the server, for example from a {@link DataPack} * There may be additional arts present in the server, for example from a {@link io.papermc.paper.datapack.Datapack}
* which can be accessed via {@link Registry#ART}. * which can be accessed via {@link RegistryAccess#registryAccess()} and {@link RegistryKey#PAINTING_VARIANT}.
*/ */
public interface Art extends OldEnum<Art>, Keyed { public interface Art extends OldEnum<Art>, Keyed {
@ -87,7 +88,7 @@ public interface Art extends OldEnum<Art>, Keyed {
@NotNull @NotNull
private static Art getArt(@NotNull String key) { private static Art getArt(@NotNull String key) {
return Registry.ART.getOrThrow(NamespacedKey.minecraft(key)); return RegistryAccess.registryAccess().getRegistry(RegistryKey.PAINTING_VARIANT).getOrThrow(NamespacedKey.minecraft(key));
} }
/** /**
@ -189,7 +190,7 @@ public interface Art extends OldEnum<Art>, Keyed {
static Art getByName(@NotNull String name) { static Art getByName(@NotNull String name) {
Preconditions.checkArgument(name != null, "Name cannot be null"); Preconditions.checkArgument(name != null, "Name cannot be null");
return Bukkit.getUnsafe().get(Registry.ART, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))); return Bukkit.getUnsafe().get(RegistryKey.PAINTING_VARIANT, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
} }
/** /**
@ -200,7 +201,7 @@ public interface Art extends OldEnum<Art>, Keyed {
@NotNull @NotNull
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils @Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
static Art valueOf(@NotNull String name) { static Art valueOf(@NotNull String name) {
Art art = Bukkit.getUnsafe().get(Registry.ART, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))); Art art = Bukkit.getUnsafe().get(RegistryKey.PAINTING_VARIANT, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Preconditions.checkArgument(art != null, "No art found with the name %s", name); Preconditions.checkArgument(art != null, "No art found with the name %s", name);
return art; return art;
} }

View File

@ -2,6 +2,7 @@ package org.bukkit;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale; import java.util.Locale;
import org.bukkit.util.OldEnum; import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -45,7 +46,7 @@ public interface Fluid extends OldEnum<Fluid>, Keyed {
@NotNull @NotNull
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils @Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
static Fluid valueOf(@NotNull String name) { static Fluid valueOf(@NotNull String name) {
Fluid fluid = Bukkit.getUnsafe().get(Registry.FLUID, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))); Fluid fluid = Bukkit.getUnsafe().get(RegistryKey.FLUID, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Preconditions.checkArgument(fluid != null, "No fluid found with the name %s", name); Preconditions.checkArgument(fluid != null, "No fluid found with the name %s", name);
return fluid; return fluid;
} }

View File

@ -1,5 +1,7 @@
package org.bukkit; package org.bukkit;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.jetbrains.annotations.ApiStatus; import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -31,7 +33,7 @@ public interface JukeboxSong extends Keyed, Translatable {
@NotNull @NotNull
private static JukeboxSong get(@NotNull String key) { private static JukeboxSong get(@NotNull String key) {
return Registry.JUKEBOX_SONG.getOrThrow(NamespacedKey.minecraft(key)); return RegistryAccess.registryAccess().getRegistry(RegistryKey.JUKEBOX_SONG).getOrThrow(NamespacedKey.minecraft(key));
} }
// Paper start - adventure // Paper start - adventure

View File

@ -1,6 +1,8 @@
package org.bukkit; package org.bukkit;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import java.util.Collection; import java.util.Collection;
import java.util.Collections; import java.util.Collections;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -44,7 +46,7 @@ public abstract class MusicInstrument implements Keyed, net.kyori.adventure.tran
@NotNull @NotNull
private static MusicInstrument getInstrument(@NotNull String key) { private static MusicInstrument getInstrument(@NotNull String key) {
return Registry.INSTRUMENT.getOrThrow(NamespacedKey.minecraft(key)); return RegistryAccess.registryAccess().getRegistry(RegistryKey.INSTRUMENT).getOrThrow(NamespacedKey.minecraft(key));
} }
// Paper start - deprecate getKey // Paper start - deprecate getKey

View File

@ -2,6 +2,7 @@ package org.bukkit;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale; import java.util.Locale;
import org.bukkit.packs.DataPack; import org.bukkit.packs.DataPack;
import org.bukkit.util.OldEnum; import org.bukkit.util.OldEnum;
@ -1687,7 +1688,7 @@ public interface Sound extends OldEnum<Sound>, Keyed, net.kyori.adventure.sound.
@NotNull @NotNull
@Deprecated(since = "1.21.3") @Deprecated(since = "1.21.3")
static Sound valueOf(@NotNull String name) { static Sound valueOf(@NotNull String name) {
Sound sound = Bukkit.getUnsafe().get(Registry.SOUNDS, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))); Sound sound = Bukkit.getUnsafe().get(RegistryKey.SOUND_EVENT, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
if (sound != null) { if (sound != null) {
return sound; return sound;
} }

View File

@ -2,6 +2,7 @@ package org.bukkit;
import com.google.common.collect.Multimap; import com.google.common.collect.Multimap;
import io.papermc.paper.entity.EntitySerializationFlag; import io.papermc.paper.entity.EntitySerializationFlag;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.advancement.Advancement; import org.bukkit.advancement.Advancement;
import org.bukkit.attribute.Attribute; import org.bukkit.attribute.Attribute;
import org.bukkit.attribute.AttributeModifier; import org.bukkit.attribute.AttributeModifier;
@ -140,7 +141,7 @@ public interface UnsafeValues {
String get(Class<?> aClass, String value); String get(Class<?> aClass, String value);
@ApiStatus.Internal @ApiStatus.Internal
<B extends Keyed> B get(Registry<B> registry, NamespacedKey key); <B extends Keyed> B get(RegistryKey<B> registry, NamespacedKey key);
@ApiStatus.Internal @ApiStatus.Internal
Biome getCustomBiome(); Biome getCustomBiome();

View File

@ -2,6 +2,7 @@ package org.bukkit.attribute;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.Keyed; import org.bukkit.Keyed;
@ -158,7 +159,7 @@ public interface Attribute extends OldEnum<Attribute>, Keyed, Translatable, net.
@NotNull @NotNull
@Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils @Deprecated(since = "1.21.3", forRemoval = true) @org.jetbrains.annotations.ApiStatus.ScheduledForRemoval(inVersion = "1.22") // Paper - will be removed via asm-utils
static Attribute valueOf(@NotNull String name) { static Attribute valueOf(@NotNull String name) {
Attribute attribute = Bukkit.getUnsafe().get(Registry.ATTRIBUTE, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))); Attribute attribute = Bukkit.getUnsafe().get(RegistryKey.ATTRIBUTE, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Preconditions.checkArgument(attribute != null, "No attribute found with the name %s", name); Preconditions.checkArgument(attribute != null, "No attribute found with the name %s", name);
return attribute; return attribute;
} }

View File

@ -2,13 +2,14 @@ package org.bukkit.block;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.FeatureFlag; import org.bukkit.FeatureFlag;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry; import org.bukkit.Registry;
import org.bukkit.packs.DataPack;
import org.bukkit.util.OldEnum; import org.bukkit.util.OldEnum;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -17,8 +18,8 @@ import org.jetbrains.annotations.NotNull;
* <p> * <p>
* The Biomes listed in this interface are present in the default server * The Biomes listed in this interface are present in the default server
* or can be enabled via a {@link FeatureFlag}. * or can be enabled via a {@link FeatureFlag}.
* There may be additional biomes present in the server, for example from a {@link DataPack} * There may be additional biomes present in the server, for example from a {@link io.papermc.paper.datapack.Datapack}
* which can be accessed via {@link Registry#BIOME}. * which can be accessed via {@link io.papermc.paper.registry.RegistryAccess#getRegistry(RegistryKey)} and {@link RegistryKey#BIOME}.
*/ */
public interface Biome extends OldEnum<Biome>, Keyed, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations public interface Biome extends OldEnum<Biome>, Keyed, net.kyori.adventure.translation.Translatable { // Paper - Adventure translations
@ -98,7 +99,7 @@ public interface Biome extends OldEnum<Biome>, Keyed, net.kyori.adventure.transl
@NotNull @NotNull
private static Biome getBiome(@NotNull String key) { private static Biome getBiome(@NotNull String key) {
return Registry.BIOME.getOrThrow(NamespacedKey.minecraft(key)); return RegistryAccess.registryAccess().getRegistry(RegistryKey.BIOME).getOrThrow(NamespacedKey.minecraft(key));
} }
/** /**
@ -113,7 +114,7 @@ public interface Biome extends OldEnum<Biome>, Keyed, net.kyori.adventure.transl
return Biome.CUSTOM; return Biome.CUSTOM;
} }
Biome biome = Bukkit.getUnsafe().get(Registry.BIOME, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT))); Biome biome = Bukkit.getUnsafe().get(RegistryKey.BIOME, NamespacedKey.fromString(name.toLowerCase(Locale.ROOT)));
Preconditions.checkArgument(biome != null, "No biome found with the name %s", name); Preconditions.checkArgument(biome != null, "No biome found with the name %s", name);
return biome; return biome;
} }

View File

@ -2,6 +2,7 @@ package org.bukkit.block.banner;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import io.papermc.paper.registry.RegistryKey;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -45,7 +46,7 @@ public class Pattern implements ConfigurationSerializable {
PatternType patternType = PatternType.getByIdentifier(value); PatternType patternType = PatternType.getByIdentifier(value);
if (patternType == null) { if (patternType == null) {
patternType = Bukkit.getUnsafe().get(Registry.BANNER_PATTERN, NamespacedKey.fromString(value)); patternType = Bukkit.getUnsafe().get(RegistryKey.BANNER_PATTERN, NamespacedKey.fromString(value));
} }
Preconditions.checkNotNull(patternType, "Pattern type for key %s cannot be null", value); Preconditions.checkNotNull(patternType, "Pattern type for key %s cannot be null", value);

View File

@ -2,6 +2,8 @@ package org.bukkit.block.banner;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@ -95,8 +97,7 @@ public interface PatternType extends OldEnum<PatternType>, Keyed {
* *
* @param identifier the identifier * @param identifier the identifier
* @return the matched pattern type or null * @return the matched pattern type or null
* @see Registry#BANNER_PATTERN * @deprecated magic value, use {@link Registry#get(NamespacedKey)} instead with {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)} and {@link io.papermc.paper.registry.RegistryKey#BANNER_PATTERN}
* @deprecated magic value, use {@link Registry#get(NamespacedKey)} instead
*/ */
@Contract("null -> null") @Contract("null -> null")
@Nullable @Nullable
@ -117,7 +118,7 @@ public interface PatternType extends OldEnum<PatternType>, Keyed {
@NotNull @NotNull
private static PatternType getType(@NotNull String key) { private static PatternType getType(@NotNull String key) {
return Registry.BANNER_PATTERN.getOrThrow(NamespacedKey.minecraft(key)); return RegistryAccess.registryAccess().getRegistry(RegistryKey.BANNER_PATTERN).getOrThrow(NamespacedKey.minecraft(key));
} }
/** /**

View File

@ -1,5 +1,7 @@
package org.bukkit.damage; package org.bukkit.damage;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry; import org.bukkit.Registry;
@ -12,7 +14,7 @@ import org.jetbrains.annotations.NotNull;
* <p> * <p>
* Constants in this class include the base types provided by the vanilla * Constants in this class include the base types provided by the vanilla
* server. Data packs are capable of registering more types of damage which may * server. Data packs are capable of registering more types of damage which may
* be obtained through the {@link Registry#DAMAGE_TYPE}. * be obtained through {@link io.papermc.paper.registry.RegistryAccess#getRegistry(RegistryKey)} and {@link RegistryKey#DAMAGE_TYPE}.
* *
* @see <a href="https://minecraft.wiki/w/Damage_type">Minecraft Wiki</a> * @see <a href="https://minecraft.wiki/w/Damage_type">Minecraft Wiki</a>
*/ */
@ -71,7 +73,7 @@ public interface DamageType extends Keyed, Translatable {
@NotNull @NotNull
private static DamageType getDamageType(@NotNull String key) { private static DamageType getDamageType(@NotNull String key) {
return Registry.DAMAGE_TYPE.getOrThrow(NamespacedKey.minecraft(key)); return RegistryAccess.registryAccess().getRegistry(RegistryKey.DAMAGE_TYPE).getOrThrow(NamespacedKey.minecraft(key));
} }
/** /**

View File

@ -1,6 +1,8 @@
package org.bukkit.enchantments; package org.bukkit.enchantments;
import com.google.common.collect.Lists; import com.google.common.collect.Lists;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale; import java.util.Locale;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@ -229,7 +231,7 @@ public abstract class Enchantment implements Keyed, Translatable, net.kyori.adve
@NotNull @NotNull
private static Enchantment getEnchantment(@NotNull String key) { private static Enchantment getEnchantment(@NotNull String key) {
return Registry.ENCHANTMENT.getOrThrow(NamespacedKey.minecraft(key)); return RegistryAccess.registryAccess().getRegistry(RegistryKey.ENCHANTMENT).getOrThrow(NamespacedKey.minecraft(key));
} }
/** /**

View File

@ -1,5 +1,7 @@
package org.bukkit.entity; package org.bukkit.entity;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@ -105,7 +107,7 @@ public interface Wolf extends Tameable, Sittable, io.papermc.paper.entity.Collar
@NotNull @NotNull
private static Variant getVariant(@NotNull String key) { private static Variant getVariant(@NotNull String key) {
return Registry.WOLF_VARIANT.getOrThrow(NamespacedKey.minecraft(key)); return RegistryAccess.registryAccess().getRegistry(RegistryKey.WOLF_VARIANT).getOrThrow(NamespacedKey.minecraft(key));
} }
} }
} }

View File

@ -1,5 +1,7 @@
package org.bukkit.generator.structure; package org.bukkit.generator.structure;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry; import org.bukkit.Registry;
@ -10,7 +12,7 @@ import org.jetbrains.annotations.NotNull;
* *
* Listed structures are present in the default server. Depending on the server * Listed structures are present in the default server. Depending on the server
* there might be additional structures present (for example structures added by * there might be additional structures present (for example structures added by
* data packs), which can be received via {@link Registry#STRUCTURE}. * data packs), which can be received via {@link io.papermc.paper.registry.RegistryAccess#getRegistry(io.papermc.paper.registry.RegistryKey)} and {@link io.papermc.paper.registry.RegistryKey#STRUCTURE}.
*/ */
public abstract class Structure implements Keyed { public abstract class Structure implements Keyed {
@ -51,7 +53,7 @@ public abstract class Structure implements Keyed {
@NotNull @NotNull
private static Structure getStructure(@NotNull String name) { private static Structure getStructure(@NotNull String name) {
return Registry.STRUCTURE.getOrThrow(NamespacedKey.minecraft(name)); return RegistryAccess.registryAccess().getRegistry(RegistryKey.STRUCTURE).getOrThrow(NamespacedKey.minecraft(name));
} }
/** /**

View File

@ -2,6 +2,7 @@ package org.bukkit.inventory;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import io.papermc.paper.registry.RegistryKey;
import java.util.LinkedHashMap; import java.util.LinkedHashMap;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
@ -543,7 +544,7 @@ public class ItemStack implements Cloneable, ConfigurationSerializable, Translat
stringKey = Bukkit.getUnsafe().get(Enchantment.class, stringKey); stringKey = Bukkit.getUnsafe().get(Enchantment.class, stringKey);
NamespacedKey key = NamespacedKey.fromString(stringKey.toLowerCase(Locale.ROOT)); NamespacedKey key = NamespacedKey.fromString(stringKey.toLowerCase(Locale.ROOT));
Enchantment enchantment = Bukkit.getUnsafe().get(Registry.ENCHANTMENT, key); Enchantment enchantment = Bukkit.getUnsafe().get(RegistryKey.ENCHANTMENT, key);
if ((enchantment != null) && (entry.getValue() instanceof Integer)) { if ((enchantment != null) && (entry.getValue() instanceof Integer)) {
result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue()); result.addUnsafeEnchantment(enchantment, (Integer) entry.getValue());

View File

@ -1,5 +1,7 @@
package org.bukkit.inventory.meta.trim; package org.bukkit.inventory.meta.trim;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@ -59,7 +61,7 @@ public interface TrimMaterial extends Keyed, Translatable {
@NotNull @NotNull
private static TrimMaterial getTrimMaterial(@NotNull String key) { private static TrimMaterial getTrimMaterial(@NotNull String key) {
return Registry.TRIM_MATERIAL.getOrThrow(NamespacedKey.minecraft(key)); return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_MATERIAL).getOrThrow(NamespacedKey.minecraft(key));
} }
// Paper start - adventure // Paper start - adventure

View File

@ -1,5 +1,7 @@
package org.bukkit.inventory.meta.trim; package org.bukkit.inventory.meta.trim;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@ -87,7 +89,7 @@ public interface TrimPattern extends Keyed, Translatable {
@NotNull @NotNull
private static TrimPattern getTrimPattern(@NotNull String key) { private static TrimPattern getTrimPattern(@NotNull String key) {
return Registry.TRIM_PATTERN.getOrThrow(NamespacedKey.minecraft(key)); return RegistryAccess.registryAccess().getRegistry(RegistryKey.TRIM_PATTERN).getOrThrow(NamespacedKey.minecraft(key));
} }
// Paper start - adventure // Paper start - adventure

View File

@ -2,6 +2,7 @@ package org.bukkit.potion;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import io.papermc.paper.registry.RegistryKey;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
@ -175,7 +176,7 @@ public class PotionEffect implements ConfigurationSerializable {
private static PotionEffectType getEffectType(@NotNull Map<?, ?> map) { private static PotionEffectType getEffectType(@NotNull Map<?, ?> map) {
PotionEffectType effect; PotionEffectType effect;
if (map.get(TYPE) instanceof String value) { if (map.get(TYPE) instanceof String value) {
effect = Bukkit.getUnsafe().get(Registry.EFFECT, NamespacedKey.fromString(value)); effect = Bukkit.getUnsafe().get(RegistryKey.MOB_EFFECT, NamespacedKey.fromString(value));
} else { } else {
int type = getInt(map, TYPE); int type = getInt(map, TYPE);
effect = PotionEffectType.getById(type); effect = PotionEffectType.getById(type);

View File

@ -7,7 +7,6 @@ import net.minecraft.core.component.DataComponentMap;
import net.minecraft.core.registries.BuiltInRegistries; import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
import org.jspecify.annotations.Nullable; import org.jspecify.annotations.Nullable;
@ -23,7 +22,7 @@ public abstract class PaperDataComponentType<T, NMS> implements DataComponentTyp
} }
public static DataComponentType minecraftToBukkit(final net.minecraft.core.component.DataComponentType<?> type) { public static DataComponentType minecraftToBukkit(final net.minecraft.core.component.DataComponentType<?> type) {
return CraftRegistry.minecraftToBukkit(type, Registries.DATA_COMPONENT_TYPE, Registry.DATA_COMPONENT_TYPE); return CraftRegistry.minecraftToBukkit(type, Registries.DATA_COMPONENT_TYPE);
} }
public static Set<DataComponentType> minecraftToBukkit(final Set<net.minecraft.core.component.DataComponentType<?>> nmsTypes) { public static Set<DataComponentType> minecraftToBukkit(final Set<net.minecraft.core.component.DataComponentType<?>> nmsTypes) {

View File

@ -1,6 +1,5 @@
package io.papermc.paper.datacomponent.item; package io.papermc.paper.datacomponent.item;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey; import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.util.MCUtil; import io.papermc.paper.util.MCUtil;
import java.util.List; import java.util.List;
@ -20,7 +19,7 @@ public record PaperBannerPatternLayers(
private static List<Pattern> convert(final net.minecraft.world.level.block.entity.BannerPatternLayers nmsPatterns) { private static List<Pattern> convert(final net.minecraft.world.level.block.entity.BannerPatternLayers nmsPatterns) {
return MCUtil.transformUnmodifiable(nmsPatterns.layers(), input -> { return MCUtil.transformUnmodifiable(nmsPatterns.layers(), input -> {
final Optional<PatternType> type = CraftRegistry.unwrapAndConvertHolder(RegistryAccess.registryAccess().getRegistry(RegistryKey.BANNER_PATTERN), input.pattern()); final Optional<PatternType> type = CraftRegistry.unwrapAndConvertHolder(RegistryKey.BANNER_PATTERN, input.pattern());
return new Pattern(Objects.requireNonNull(DyeColor.getByWoolData((byte) input.color().getId())), type.orElseThrow(() -> new IllegalStateException("Inlined banner patterns are not supported yet in the API!"))); return new Pattern(Objects.requireNonNull(DyeColor.getByWoolData((byte) input.color().getId())), type.orElseThrow(() -> new IllegalStateException("Inlined banner patterns are not supported yet in the API!")));
}); });
} }

View File

@ -4,6 +4,8 @@ import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.JsonOps; import com.mojang.serialization.JsonOps;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import net.kyori.adventure.key.Key; import net.kyori.adventure.key.Key;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.resources.RegistryOps; import net.minecraft.resources.RegistryOps;
@ -25,7 +27,8 @@ public interface Holderable<M> extends Handleable<M> {
return this.getHolder().value(); return this.getHolder().value();
} }
static <T extends org.bukkit.Keyed, M> @Nullable T fromBukkitSerializationObject(final Object deserialized, final Codec<? extends Holder<M>> codec, final Registry<T> registry) { // TODO remove Keyed static <T extends org.bukkit.Keyed, M> @Nullable T fromBukkitSerializationObject(final Object deserialized, final Codec<? extends Holder<M>> codec, final RegistryKey<T> registryKey) { // TODO remove Keyed
final Registry<T> registry = RegistryAccess.registryAccess().getRegistry(registryKey);
return switch (deserialized) { return switch (deserialized) {
case @Subst("key:value") final String string -> { case @Subst("key:value") final String string -> {
if (!(Key.parseable(string))) { if (!(Key.parseable(string))) {

View File

@ -7,18 +7,17 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.decoration.PaintingVariant; import net.minecraft.world.entity.decoration.PaintingVariant;
import org.bukkit.Art; import org.bukkit.Art;
import org.bukkit.Registry;
public class CraftArt extends OldEnumHolderable<Art, PaintingVariant> implements Art { public class CraftArt extends OldEnumHolderable<Art, PaintingVariant> implements Art {
private static int count = 0; private static int count = 0;
public static Art minecraftToBukkit(PaintingVariant minecraft) { public static Art minecraftToBukkit(PaintingVariant minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.PAINTING_VARIANT, Registry.ART); return CraftRegistry.minecraftToBukkit(minecraft, Registries.PAINTING_VARIANT);
} }
public static Art minecraftHolderToBukkit(Holder<PaintingVariant> minecraft) { public static Art minecraftHolderToBukkit(Holder<PaintingVariant> minecraft) {
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registry.ART); return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.PAINTING_VARIANT);
} }
public static PaintingVariant bukkitToMinecraft(Art bukkit) { public static PaintingVariant bukkitToMinecraft(Art bukkit) {

View File

@ -4,7 +4,6 @@ import java.util.Locale;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import org.bukkit.Fluid; import org.bukkit.Fluid;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
@ -13,7 +12,7 @@ public class CraftFluid implements Fluid, Handleable<net.minecraft.world.level.m
private static int count = 0; private static int count = 0;
public static Fluid minecraftToBukkit(net.minecraft.world.level.material.Fluid minecraft) { public static Fluid minecraftToBukkit(net.minecraft.world.level.material.Fluid minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.FLUID, Registry.FLUID); return CraftRegistry.minecraftToBukkit(minecraft, Registries.FLUID);
} }
public static net.minecraft.world.level.material.Fluid bukkitToMinecraft(Fluid bukkit) { public static net.minecraft.world.level.material.Fluid bukkitToMinecraft(Fluid bukkit) {

View File

@ -3,14 +3,13 @@ package org.bukkit.craftbukkit;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import org.bukkit.GameEvent; import org.bukkit.GameEvent;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CraftGameEvent extends GameEvent implements Handleable<net.minecraft.world.level.gameevent.GameEvent> { public class CraftGameEvent extends GameEvent implements Handleable<net.minecraft.world.level.gameevent.GameEvent> {
public static GameEvent minecraftToBukkit(net.minecraft.world.level.gameevent.GameEvent minecraft) { public static GameEvent minecraftToBukkit(net.minecraft.world.level.gameevent.GameEvent minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.GAME_EVENT, Registry.GAME_EVENT); return CraftRegistry.minecraftToBukkit(minecraft, Registries.GAME_EVENT);
} }
public static net.minecraft.world.level.gameevent.GameEvent bukkitToMinecraft(GameEvent bukkit) { public static net.minecraft.world.level.gameevent.GameEvent bukkitToMinecraft(GameEvent bukkit) {

View File

@ -6,14 +6,13 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.network.chat.contents.TranslatableContents; import net.minecraft.network.chat.contents.TranslatableContents;
import org.bukkit.JukeboxSong; import org.bukkit.JukeboxSong;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CraftJukeboxSong implements JukeboxSong, Handleable<net.minecraft.world.item.JukeboxSong> { public class CraftJukeboxSong implements JukeboxSong, Handleable<net.minecraft.world.item.JukeboxSong> {
public static JukeboxSong minecraftToBukkit(net.minecraft.world.item.JukeboxSong minecraft) { public static JukeboxSong minecraftToBukkit(net.minecraft.world.item.JukeboxSong minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.JUKEBOX_SONG, Registry.JUKEBOX_SONG); return CraftRegistry.minecraftToBukkit(minecraft, Registries.JUKEBOX_SONG);
} }
public static JukeboxSong minecraftHolderToBukkit(Holder<net.minecraft.world.item.JukeboxSong> minecraft) { public static JukeboxSong minecraftHolderToBukkit(Holder<net.minecraft.world.item.JukeboxSong> minecraft) {

View File

@ -1,6 +1,7 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.util.Holderable; import io.papermc.paper.util.Holderable;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
@ -8,17 +9,16 @@ import net.minecraft.world.item.Instrument;
import org.bukkit.MusicInstrument; import org.bukkit.MusicInstrument;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry; import org.bukkit.Registry;
import org.bukkit.craftbukkit.util.Handleable;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CraftMusicInstrument extends MusicInstrument implements io.papermc.paper.util.Holderable<Instrument> { public class CraftMusicInstrument extends MusicInstrument implements io.papermc.paper.util.Holderable<Instrument> {
public static MusicInstrument minecraftToBukkit(Instrument minecraft) { public static MusicInstrument minecraftToBukkit(Instrument minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.INSTRUMENT, Registry.INSTRUMENT); return CraftRegistry.minecraftToBukkit(minecraft, Registries.INSTRUMENT);
} }
public static MusicInstrument minecraftHolderToBukkit(Holder<Instrument> minecraft) { public static MusicInstrument minecraftHolderToBukkit(Holder<Instrument> minecraft) {
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registry.INSTRUMENT); // Paper - switch to Holder return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.INSTRUMENT); // Paper - switch to Holder
} }
public static Instrument bukkitToMinecraft(MusicInstrument bukkit) { public static Instrument bukkitToMinecraft(MusicInstrument bukkit) {
@ -38,7 +38,7 @@ public class CraftMusicInstrument extends MusicInstrument implements io.papermc.
public static MusicInstrument stringToBukkit(Object string) { // Paper - switch to Holder public static MusicInstrument stringToBukkit(Object string) { // Paper - switch to Holder
Preconditions.checkArgument(string != null); Preconditions.checkArgument(string != null);
return io.papermc.paper.util.Holderable.fromBukkitSerializationObject(string, Instrument.CODEC, Registry.INSTRUMENT); // Paper - switch to Holder return io.papermc.paper.util.Holderable.fromBukkitSerializationObject(string, Instrument.CODEC, RegistryKey.INSTRUMENT); // Paper - switch to Holder
} }
// Paper start - switch to Holder // Paper start - switch to Holder

View File

@ -1,12 +1,15 @@
package org.bukkit.craftbukkit; package org.bukkit.craftbukkit;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.papermc.paper.registry.PaperRegistries;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.registry.entry.RegistryEntryMeta; import io.papermc.paper.registry.entry.RegistryEntryMeta;
import io.papermc.paper.registry.set.NamedRegistryKeySetImpl; import io.papermc.paper.registry.set.NamedRegistryKeySetImpl;
import io.papermc.paper.registry.tag.Tag; import io.papermc.paper.registry.tag.Tag;
import io.papermc.paper.util.Holderable; import io.papermc.paper.util.Holderable;
import java.util.Collection;
import io.papermc.paper.util.MCUtil; import io.papermc.paper.util.MCUtil;
import java.util.Collection;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map; import java.util.Map;
@ -15,7 +18,6 @@ import java.util.function.BiFunction;
import java.util.stream.Stream; import java.util.stream.Stream;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.HolderOwner; import net.minecraft.core.HolderOwner;
import net.minecraft.core.RegistryAccess;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
@ -30,14 +32,14 @@ import org.jetbrains.annotations.NotNull;
public class CraftRegistry<B extends Keyed, M> implements Registry<B> { public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
private static RegistryAccess registry; private static net.minecraft.core.RegistryAccess registry;
public static void setMinecraftRegistry(RegistryAccess registry) { public static void setMinecraftRegistry(final net.minecraft.core.RegistryAccess registry) {
Preconditions.checkState(CraftRegistry.registry == null, "Registry already set"); Preconditions.checkState(CraftRegistry.registry == null, "Registry already set");
CraftRegistry.registry = registry; CraftRegistry.registry = registry;
} }
public static RegistryAccess getMinecraftRegistry() { public static net.minecraft.core.RegistryAccess getMinecraftRegistry() {
return CraftRegistry.registry; return CraftRegistry.registry;
} }
@ -51,14 +53,13 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
* *
* @param minecraft the minecraft representation * @param minecraft the minecraft representation
* @param registryKey the registry key of the minecraft registry to use * @param registryKey the registry key of the minecraft registry to use
* @param bukkitRegistry the bukkit registry to use
* @return the bukkit representation of the minecraft value * @return the bukkit representation of the minecraft value
*/ */
public static <B extends Keyed, M> B minecraftToBukkit(M minecraft, ResourceKey<net.minecraft.core.Registry<M>> registryKey, Registry<B> bukkitRegistry) { public static <B extends Keyed, M> B minecraftToBukkit(M minecraft, ResourceKey<? extends net.minecraft.core.Registry<M>> registryKey) {
Preconditions.checkArgument(minecraft != null); Preconditions.checkArgument(minecraft != null);
net.minecraft.core.Registry<M> registry = CraftRegistry.getMinecraftRegistry(registryKey); net.minecraft.core.Registry<M> registry = CraftRegistry.getMinecraftRegistry(registryKey);
// Paper start - support direct Holders final Registry<B> bukkitRegistry = RegistryAccess.registryAccess().getRegistry(PaperRegistries.registryFromNms(registryKey));
final java.util.Optional<ResourceKey<M>> resourceKey = registry.getResourceKey(minecraft); final java.util.Optional<ResourceKey<M>> resourceKey = registry.getResourceKey(minecraft);
if (resourceKey.isEmpty() && bukkitRegistry instanceof final CraftRegistry<?, ?> craftRegistry && craftRegistry.supportsDirectHolders()) { if (resourceKey.isEmpty() && bukkitRegistry instanceof final CraftRegistry<?, ?> craftRegistry && craftRegistry.supportsDirectHolders()) {
return ((CraftRegistry<B, M>) bukkitRegistry).convertDirectHolder(Holder.direct(minecraft)); return ((CraftRegistry<B, M>) bukkitRegistry).convertDirectHolder(Holder.direct(minecraft));
@ -66,17 +67,16 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
throw new IllegalStateException(String.format("Cannot convert '%s' to bukkit representation, since it is not registered.", minecraft)); throw new IllegalStateException(String.format("Cannot convert '%s' to bukkit representation, since it is not registered.", minecraft));
} }
final B bukkit = bukkitRegistry.get(CraftNamespacedKey.fromMinecraft(resourceKey.get().location())); final B bukkit = bukkitRegistry.get(CraftNamespacedKey.fromMinecraft(resourceKey.get().location()));
// Paper end - support direct Holders
Preconditions.checkArgument(bukkit != null); Preconditions.checkArgument(bukkit != null);
return bukkit; return bukkit;
} }
// Paper start - support direct Holders public static <B extends Keyed, M> B minecraftHolderToBukkit(final Holder<M> minecraft, final ResourceKey<? extends net.minecraft.core.Registry<M>> registryKey) {
public static <B extends Keyed, M> B minecraftHolderToBukkit(final Holder<M> minecraft, final Registry<B> bukkitRegistry) {
Preconditions.checkArgument(minecraft != null); Preconditions.checkArgument(minecraft != null);
final Registry<B> bukkitRegistry = RegistryAccess.registryAccess().getRegistry(PaperRegistries.registryFromNms(registryKey));
final B bukkit = switch (minecraft) { final B bukkit = switch (minecraft) {
case final Holder.Direct<M> direct -> { case final Holder.Direct<M> direct -> {
if (!(bukkitRegistry instanceof final CraftRegistry<?, ?> craftRegistry) || !craftRegistry.supportsDirectHolders()) { if (!(bukkitRegistry instanceof final CraftRegistry<?, ?> craftRegistry) || !craftRegistry.supportsDirectHolders()) {
@ -84,14 +84,13 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
} }
yield ((CraftRegistry<B, M>) bukkitRegistry).convertDirectHolder(direct); yield ((CraftRegistry<B, M>) bukkitRegistry).convertDirectHolder(direct);
} }
case final Holder.Reference<M> reference -> bukkitRegistry.get(io.papermc.paper.util.MCUtil.fromResourceKey(reference.key())); case final Holder.Reference<M> reference -> bukkitRegistry.get(MCUtil.fromResourceKey(reference.key()));
default -> throw new IllegalArgumentException("Unknown holder: " + minecraft); default -> throw new IllegalArgumentException("Unknown holder: " + minecraft);
}; };
Preconditions.checkArgument(bukkit != null); Preconditions.checkArgument(bukkit != null);
return bukkit; return bukkit;
} }
// Paper end - support direct Holders
/** /**
* Usage note: Only use this method to delegate the conversion methods from the individual Craft classes to here. * Usage note: Only use this method to delegate the conversion methods from the individual Craft classes to here.
@ -125,13 +124,10 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
} }
// Paper start - fixup upstream being dum // Paper start - fixup upstream being dum
public static <T extends org.bukkit.Keyed, M> java.util.Optional<T> unwrapAndConvertHolder(final io.papermc.paper.registry.RegistryKey<T> registryKey, final Holder<M> value) { public static <T extends Keyed, M> Optional<T> unwrapAndConvertHolder(final RegistryKey<T> registryKey, final Holder<M> value) {
return unwrapAndConvertHolder(io.papermc.paper.registry.RegistryAccess.registryAccess().getRegistry(registryKey), value); final Registry<T> registry = RegistryAccess.registryAccess().getRegistry(registryKey);
}
public static <T extends org.bukkit.Keyed, M> java.util.Optional<T> unwrapAndConvertHolder(final Registry<T> registry, final Holder<M> value) {
if (registry instanceof CraftRegistry<?,?> craftRegistry && craftRegistry.supportsDirectHolders() && value.kind() == Holder.Kind.DIRECT) { if (registry instanceof CraftRegistry<?,?> craftRegistry && craftRegistry.supportsDirectHolders() && value.kind() == Holder.Kind.DIRECT) {
return java.util.Optional.of(((CraftRegistry<T, M>) registry).convertDirectHolder(value)); return Optional.of(((CraftRegistry<T, M>) registry).convertDirectHolder(value));
} }
return value.unwrapKey().map(key -> registry.get(CraftNamespacedKey.fromMinecraft(key.location()))); return value.unwrapKey().map(key -> registry.get(CraftNamespacedKey.fromMinecraft(key.location())));
} }
@ -140,7 +136,8 @@ public class CraftRegistry<B extends Keyed, M> implements Registry<B> {
// Paper - move to PaperRegistries // Paper - move to PaperRegistries
// Paper - NOTE: As long as all uses of the method below relate to *serialization* via ConfigurationSerializable, it's fine // Paper - NOTE: As long as all uses of the method below relate to *serialization* via ConfigurationSerializable, it's fine
public static <B extends Keyed> B get(Registry<B> bukkit, NamespacedKey namespacedKey, ApiVersion apiVersion) { public static <B extends Keyed> B get(RegistryKey<B> bukkitKey, NamespacedKey namespacedKey, ApiVersion apiVersion) {
final Registry<B> bukkit = RegistryAccess.registryAccess().getRegistry(bukkitKey);
if (bukkit instanceof CraftRegistry<B, ?> craft) { if (bukkit instanceof CraftRegistry<B, ?> craft) {
return craft.get(craft.serializationUpdater.apply(namespacedKey, apiVersion)); // Paper return craft.get(craft.serializationUpdater.apply(namespacedKey, apiVersion)); // Paper
} }

View File

@ -4,7 +4,6 @@ import io.papermc.paper.util.OldEnumHolderable;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.sounds.SoundEvent; import net.minecraft.sounds.SoundEvent;
import org.bukkit.Registry;
import org.bukkit.Sound; import org.bukkit.Sound;
public class CraftSound extends OldEnumHolderable<Sound, SoundEvent> implements Sound { public class CraftSound extends OldEnumHolderable<Sound, SoundEvent> implements Sound {
@ -12,7 +11,7 @@ public class CraftSound extends OldEnumHolderable<Sound, SoundEvent> implements
private static int count = 0; private static int count = 0;
public static Sound minecraftToBukkit(SoundEvent minecraft) { public static Sound minecraftToBukkit(SoundEvent minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.SOUND_EVENT, Registry.SOUNDS); return CraftRegistry.minecraftToBukkit(minecraft, Registries.SOUND_EVENT);
} }
public static SoundEvent bukkitToMinecraft(Sound bukkit) { public static SoundEvent bukkitToMinecraft(Sound bukkit) {

View File

@ -6,6 +6,8 @@ import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import io.papermc.paper.FeatureHooks; import io.papermc.paper.FeatureHooks;
import io.papermc.paper.registry.RegistryAccess;
import io.papermc.paper.registry.RegistryKey;
import it.unimi.dsi.fastutil.longs.Long2ObjectMap; import it.unimi.dsi.fastutil.longs.Long2ObjectMap;
import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap;
import java.io.File; import java.io.File;
@ -2242,7 +2244,7 @@ public class CraftWorld extends CraftRegionAccessor implements World {
@Override @Override
public StructureSearchResult locateNearestStructure(Location origin, StructureType structureType, int radius, boolean findUnexplored) { public StructureSearchResult locateNearestStructure(Location origin, StructureType structureType, int radius, boolean findUnexplored) {
List<Structure> structures = new ArrayList<>(); List<Structure> structures = new ArrayList<>();
for (Structure structure : Registry.STRUCTURE) { for (Structure structure : RegistryAccess.registryAccess().getRegistry(RegistryKey.STRUCTURE)) {
if (structure.getStructureType() == structureType) { if (structure.getStructureType() == structureType) {
structures.add(structure); structures.add(structure);
} }

View File

@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.attribute; package org.bukkit.craftbukkit.attribute;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale; import java.util.Locale;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
@ -18,7 +19,7 @@ public class CraftAttribute implements Attribute, Handleable<net.minecraft.world
private static int count = 0; private static int count = 0;
public static Attribute minecraftToBukkit(net.minecraft.world.entity.ai.attributes.Attribute minecraft) { public static Attribute minecraftToBukkit(net.minecraft.world.entity.ai.attributes.Attribute minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.ATTRIBUTE, Registry.ATTRIBUTE); return CraftRegistry.minecraftToBukkit(minecraft, Registries.ATTRIBUTE);
} }
public static Attribute minecraftHolderToBukkit(Holder<net.minecraft.world.entity.ai.attributes.Attribute> minecraft) { public static Attribute minecraftHolderToBukkit(Holder<net.minecraft.world.entity.ai.attributes.Attribute> minecraft) {
@ -36,7 +37,7 @@ public class CraftAttribute implements Attribute, Handleable<net.minecraft.world
if (key == null) return null; // Paper - Fixup NamespacedKey handling if (key == null) return null; // Paper - Fixup NamespacedKey handling
// Now also convert from when keys where saved // Now also convert from when keys where saved
return CraftRegistry.get(Registry.ATTRIBUTE, key, ApiVersion.CURRENT); return CraftRegistry.get(RegistryKey.ATTRIBUTE, key, ApiVersion.CURRENT);
} }
public static net.minecraft.world.entity.ai.attributes.Attribute bukkitToMinecraft(Attribute bukkit) { public static net.minecraft.world.entity.ai.attributes.Attribute bukkitToMinecraft(Attribute bukkit) {

View File

@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.block; package org.bukkit.craftbukkit.block;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryKey;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import net.minecraft.world.level.block.AbstractBannerBlock; import net.minecraft.world.level.block.AbstractBannerBlock;
@ -39,7 +40,7 @@ public class CraftBanner extends CraftBlockEntityState<BannerBlockEntity> implem
for (int i = 0; i < banner.getPatterns().layers().size(); i++) { for (int i = 0; i < banner.getPatterns().layers().size(); i++) {
BannerPatternLayers.Layer p = banner.getPatterns().layers().get(i); BannerPatternLayers.Layer p = banner.getPatterns().layers().get(i);
// Paper start - fix upstream not handling inlined banner pattern // Paper start - fix upstream not handling inlined banner pattern
java.util.Optional<org.bukkit.block.banner.PatternType> type = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(org.bukkit.Registry.BANNER_PATTERN, p.pattern()); java.util.Optional<org.bukkit.block.banner.PatternType> type = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(RegistryKey.BANNER_PATTERN, p.pattern());
if (type.isEmpty()) continue; if (type.isEmpty()) continue;
this.patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.color().getId()), type.get())); this.patterns.add(new Pattern(DyeColor.getByWoolData((byte) p.color().getId()), type.get()));
// Paper end - fix upstream not handling inlined banner pattern // Paper end - fix upstream not handling inlined banner pattern

View File

@ -4,7 +4,6 @@ import java.util.Locale;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.block.Biome; import org.bukkit.block.Biome;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
@ -15,7 +14,7 @@ public class CraftBiome implements Biome, Handleable<net.minecraft.world.level.b
private static int count = 0; private static int count = 0;
public static Biome minecraftToBukkit(net.minecraft.world.level.biome.Biome minecraft) { public static Biome minecraftToBukkit(net.minecraft.world.level.biome.Biome minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.BIOME, Registry.BIOME); return CraftRegistry.minecraftToBukkit(minecraft, Registries.BIOME);
} }
public static Biome minecraftHolderToBukkit(Holder<net.minecraft.world.level.biome.Biome> minecraft) { public static Biome minecraftHolderToBukkit(Holder<net.minecraft.world.level.biome.Biome> minecraft) {

View File

@ -49,7 +49,7 @@ public class CraftBlockType<B extends BlockData> implements BlockType.Typed<B>,
} }
public static BlockType minecraftToBukkitNew(Block minecraft) { public static BlockType minecraftToBukkitNew(Block minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.BLOCK, Registry.BLOCK); return CraftRegistry.minecraftToBukkit(minecraft, Registries.BLOCK);
} }
public static Block bukkitToMinecraftNew(BlockType bukkit) { public static Block bukkitToMinecraftNew(BlockType bukkit) {

View File

@ -4,7 +4,6 @@ import io.papermc.paper.util.OldEnumHolderable;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.block.entity.BannerPattern; import net.minecraft.world.level.block.entity.BannerPattern;
import org.bukkit.Registry;
import org.bukkit.block.banner.PatternType; import org.bukkit.block.banner.PatternType;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
@ -13,11 +12,11 @@ public class CraftPatternType extends OldEnumHolderable<PatternType, BannerPatte
private static int count = 0; private static int count = 0;
public static PatternType minecraftToBukkit(BannerPattern minecraft) { public static PatternType minecraftToBukkit(BannerPattern minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.BANNER_PATTERN, Registry.BANNER_PATTERN); return CraftRegistry.minecraftToBukkit(minecraft, Registries.BANNER_PATTERN);
} }
public static PatternType minecraftHolderToBukkit(Holder<BannerPattern> minecraft) { public static PatternType minecraftHolderToBukkit(Holder<BannerPattern> minecraft) {
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registry.BANNER_PATTERN); return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.BANNER_PATTERN);
} }
public static BannerPattern bukkitToMinecraft(PatternType bukkit) { public static BannerPattern bukkitToMinecraft(PatternType bukkit) {

View File

@ -4,7 +4,6 @@ import com.google.common.base.Preconditions;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.damage.DamageEffect; import org.bukkit.damage.DamageEffect;
@ -120,6 +119,6 @@ public class CraftDamageType implements DamageType, Handleable<net.minecraft.wor
} }
public static DamageType minecraftToBukkit(net.minecraft.world.damagesource.DamageType minecraftDamageType) { public static DamageType minecraftToBukkit(net.minecraft.world.damagesource.DamageType minecraftDamageType) {
return CraftRegistry.minecraftToBukkit(minecraftDamageType, Registries.DAMAGE_TYPE, Registry.DAMAGE_TYPE); return CraftRegistry.minecraftToBukkit(minecraftDamageType, Registries.DAMAGE_TYPE);
} }
} }

View File

@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.enchantments; package org.bukkit.craftbukkit.enchantments;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.util.Holderable; import io.papermc.paper.util.Holderable;
import java.util.Locale; import java.util.Locale;
import net.minecraft.Util; import net.minecraft.Util;
@ -21,7 +22,7 @@ import org.bukkit.inventory.ItemStack;
public class CraftEnchantment extends Enchantment implements Holderable<net.minecraft.world.item.enchantment.Enchantment> { public class CraftEnchantment extends Enchantment implements Holderable<net.minecraft.world.item.enchantment.Enchantment> {
public static Enchantment minecraftToBukkit(net.minecraft.world.item.enchantment.Enchantment minecraft) { public static Enchantment minecraftToBukkit(net.minecraft.world.item.enchantment.Enchantment minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.ENCHANTMENT, Registry.ENCHANTMENT); return CraftRegistry.minecraftToBukkit(minecraft, Registries.ENCHANTMENT);
} }
public static Enchantment minecraftHolderToBukkit(Holder<net.minecraft.world.item.enchantment.Enchantment> minecraft) { public static Enchantment minecraftHolderToBukkit(Holder<net.minecraft.world.item.enchantment.Enchantment> minecraft) {
@ -52,7 +53,7 @@ public class CraftEnchantment extends Enchantment implements Holderable<net.mine
NamespacedKey key = NamespacedKey.fromString(string); NamespacedKey key = NamespacedKey.fromString(string);
// Now also convert from when keys where saved // Now also convert from when keys where saved
return CraftRegistry.get(Registry.ENCHANTMENT, key, ApiVersion.CURRENT); return CraftRegistry.get(RegistryKey.ENCHANTMENT, key, ApiVersion.CURRENT);
} }
private final Holder<net.minecraft.world.item.enchantment.Enchantment> handle; private final Holder<net.minecraft.world.item.enchantment.Enchantment> handle;

View File

@ -7,7 +7,6 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.animal.CatVariant; import net.minecraft.world.entity.animal.CatVariant;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
@ -55,7 +54,7 @@ public class CraftCat extends CraftTameableAnimal implements Cat {
private static int count = 0; private static int count = 0;
public static Type minecraftToBukkit(CatVariant minecraft) { public static Type minecraftToBukkit(CatVariant minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.CAT_VARIANT, Registry.CAT_VARIANT); return CraftRegistry.minecraftToBukkit(minecraft, Registries.CAT_VARIANT);
} }
public static Type minecraftHolderToBukkit(Holder<CatVariant> minecraft) { public static Type minecraftHolderToBukkit(Holder<CatVariant> minecraft) {

View File

@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.entity; package org.bukkit.craftbukkit.entity;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryKey;
import java.util.Locale; import java.util.Locale;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
@ -61,6 +62,6 @@ public class CraftEntityType {
NamespacedKey key = NamespacedKey.fromString(string); NamespacedKey key = NamespacedKey.fromString(string);
// Now also convert from when keys where saved // Now also convert from when keys where saved
return CraftRegistry.get(Registry.ENTITY_TYPE, key, ApiVersion.CURRENT); return CraftRegistry.get(RegistryKey.ENTITY_TYPE, key, ApiVersion.CURRENT);
} }
} }

View File

@ -7,7 +7,6 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.animal.FrogVariant; import net.minecraft.world.entity.animal.FrogVariant;
import net.minecraft.world.entity.animal.frog.Frog; import net.minecraft.world.entity.animal.frog.Frog;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
@ -59,7 +58,7 @@ public class CraftFrog extends CraftAnimals implements org.bukkit.entity.Frog {
private static int count = 0; private static int count = 0;
public static Variant minecraftToBukkit(FrogVariant minecraft) { public static Variant minecraftToBukkit(FrogVariant minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.FROG_VARIANT, Registry.FROG_VARIANT); return CraftRegistry.minecraftToBukkit(minecraft, Registries.FROG_VARIANT);
} }
public static Variant minecraftHolderToBukkit(Holder<FrogVariant> minecraft) { public static Variant minecraftHolderToBukkit(Holder<FrogVariant> minecraft) {

View File

@ -11,7 +11,6 @@ import net.minecraft.world.level.block.BedBlock;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import org.bukkit.Location; import org.bukkit.Location;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.CraftLocation; import org.bukkit.craftbukkit.util.CraftLocation;
@ -23,7 +22,6 @@ import org.bukkit.event.entity.EntityTransformEvent;
// Paper start // Paper start
import com.destroystokyo.paper.entity.villager.Reputation; import com.destroystokyo.paper.entity.villager.Reputation;
import com.google.common.collect.Maps;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
// Paper end // Paper end
@ -177,7 +175,7 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
private static int count = 0; private static int count = 0;
public static Type minecraftToBukkit(VillagerType minecraft) { public static Type minecraftToBukkit(VillagerType minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.VILLAGER_TYPE, Registry.VILLAGER_TYPE); return CraftRegistry.minecraftToBukkit(minecraft, Registries.VILLAGER_TYPE);
} }
public static VillagerType bukkitToMinecraft(Type bukkit) { public static VillagerType bukkitToMinecraft(Type bukkit) {
@ -258,7 +256,7 @@ public class CraftVillager extends CraftAbstractVillager implements Villager {
private static int count = 0; private static int count = 0;
public static Profession minecraftToBukkit(VillagerProfession minecraft) { public static Profession minecraftToBukkit(VillagerProfession minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.VILLAGER_PROFESSION, Registry.VILLAGER_PROFESSION); return CraftRegistry.minecraftToBukkit(minecraft, Registries.VILLAGER_PROFESSION);
} }
public static VillagerProfession bukkitToMinecraft(Profession bukkit) { public static VillagerProfession bukkitToMinecraft(Profession bukkit) {

View File

@ -6,7 +6,6 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.world.entity.animal.WolfVariant; import net.minecraft.world.entity.animal.WolfVariant;
import org.bukkit.DyeColor; import org.bukkit.DyeColor;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.CraftServer; import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
@ -81,7 +80,7 @@ public class CraftWolf extends CraftTameableAnimal implements Wolf {
public static class CraftVariant implements Variant, Handleable<WolfVariant> { public static class CraftVariant implements Variant, Handleable<WolfVariant> {
public static Variant minecraftToBukkit(WolfVariant minecraft) { public static Variant minecraftToBukkit(WolfVariant minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.WOLF_VARIANT, Registry.WOLF_VARIANT); return CraftRegistry.minecraftToBukkit(minecraft, Registries.WOLF_VARIANT);
} }
public static Variant minecraftHolderToBukkit(Holder<WolfVariant> minecraft) { public static Variant minecraftHolderToBukkit(Holder<WolfVariant> minecraft) {

View File

@ -4,7 +4,6 @@ import com.google.common.base.Suppliers;
import java.util.function.Supplier; import java.util.function.Supplier;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.generator.structure.Structure; import org.bukkit.generator.structure.Structure;
@ -13,7 +12,7 @@ import org.bukkit.generator.structure.StructureType;
public class CraftStructure extends Structure implements Handleable<net.minecraft.world.level.levelgen.structure.Structure> { public class CraftStructure extends Structure implements Handleable<net.minecraft.world.level.levelgen.structure.Structure> {
public static Structure minecraftToBukkit(net.minecraft.world.level.levelgen.structure.Structure minecraft) { public static Structure minecraftToBukkit(net.minecraft.world.level.levelgen.structure.Structure minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.STRUCTURE, Registry.STRUCTURE); return CraftRegistry.minecraftToBukkit(minecraft, Registries.STRUCTURE);
} }
public static net.minecraft.world.level.levelgen.structure.Structure bukkitToMinecraft(Structure bukkit) { public static net.minecraft.world.level.levelgen.structure.Structure bukkitToMinecraft(Structure bukkit) {

View File

@ -2,7 +2,6 @@ package org.bukkit.craftbukkit.generator.structure;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.generator.structure.StructureType; import org.bukkit.generator.structure.StructureType;
@ -10,7 +9,7 @@ import org.bukkit.generator.structure.StructureType;
public class CraftStructureType extends StructureType implements Handleable<net.minecraft.world.level.levelgen.structure.StructureType<?>> { public class CraftStructureType extends StructureType implements Handleable<net.minecraft.world.level.levelgen.structure.StructureType<?>> {
public static StructureType minecraftToBukkit(net.minecraft.world.level.levelgen.structure.StructureType<?> minecraft) { public static StructureType minecraftToBukkit(net.minecraft.world.level.levelgen.structure.StructureType<?> minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.STRUCTURE_TYPE, Registry.STRUCTURE_TYPE); return CraftRegistry.minecraftToBukkit(minecraft, Registries.STRUCTURE_TYPE);
} }
public static net.minecraft.world.level.levelgen.structure.StructureType<?> bukkitToMinecraft(StructureType bukkit) { public static net.minecraft.world.level.levelgen.structure.StructureType<?> bukkitToMinecraft(StructureType bukkit) {

View File

@ -51,7 +51,7 @@ public class CraftItemType<M extends ItemMeta> implements ItemType.Typed<M>, Han
} }
public static ItemType minecraftToBukkitNew(Item minecraft) { public static ItemType minecraftToBukkitNew(Item minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.ITEM, Registry.ITEM); return CraftRegistry.minecraftToBukkit(minecraft, Registries.ITEM);
} }
public static Item bukkitToMinecraftNew(ItemType bukkit) { public static Item bukkitToMinecraftNew(ItemType bukkit) {

View File

@ -8,11 +8,9 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.server.level.ServerPlayer; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.inventory.AbstractContainerMenu; import net.minecraft.world.inventory.AbstractContainerMenu;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.entity.CraftHumanEntity; import org.bukkit.craftbukkit.entity.CraftHumanEntity;
import org.bukkit.craftbukkit.inventory.util.CraftMenus; import org.bukkit.craftbukkit.inventory.util.CraftMenus;
import org.bukkit.craftbukkit.util.CraftChatMessage;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.entity.HumanEntity; import org.bukkit.entity.HumanEntity;
import org.bukkit.inventory.InventoryView; import org.bukkit.inventory.InventoryView;
@ -85,7 +83,7 @@ public class CraftMenuType<V extends InventoryView> implements MenuType.Typed<V>
} }
public static MenuType minecraftToBukkit(net.minecraft.world.inventory.MenuType<?> minecraft) { public static MenuType minecraftToBukkit(net.minecraft.world.inventory.MenuType<?> minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.MENU, Registry.MENU); return CraftRegistry.minecraftToBukkit(minecraft, Registries.MENU);
} }
public static MenuType minecraftHolderToBukkit(Holder<net.minecraft.world.inventory.MenuType<?>> minecraft) { public static MenuType minecraftHolderToBukkit(Holder<net.minecraft.world.inventory.MenuType<?>> minecraft) {

View File

@ -3,6 +3,7 @@ package org.bukkit.craftbukkit.inventory;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import io.papermc.paper.registry.RegistryKey;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
@ -42,7 +43,7 @@ public class CraftMetaBanner extends CraftMetaItem implements BannerMeta {
for (int i = 0; i < Math.min(patterns.size(), 20); i++) { for (int i = 0; i < Math.min(patterns.size(), 20); i++) {
BannerPatternLayers.Layer p = patterns.get(i); BannerPatternLayers.Layer p = patterns.get(i);
DyeColor color = DyeColor.getByWoolData((byte) p.color().getId()); DyeColor color = DyeColor.getByWoolData((byte) p.color().getId());
PatternType pattern = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(org.bukkit.Registry.BANNER_PATTERN, p.pattern()).orElse(null); // Paper - fix upstream not handling inlined banner pattern PatternType pattern = org.bukkit.craftbukkit.CraftRegistry.unwrapAndConvertHolder(RegistryKey.BANNER_PATTERN, p.pattern()).orElse(null); // Paper - fix upstream not handling inlined banner pattern
if (color != null && pattern != null) { if (color != null && pattern != null) {
this.patterns.add(new Pattern(color, pattern)); this.patterns.add(new Pattern(color, pattern));

View File

@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.inventory.trim; package org.bukkit.craftbukkit.inventory.trim;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.util.Holderable; import io.papermc.paper.util.Holderable;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
@ -8,18 +9,17 @@ import net.minecraft.network.chat.contents.TranslatableContents;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry; import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.inventory.meta.trim.TrimMaterial; import org.bukkit.inventory.meta.trim.TrimMaterial;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CraftTrimMaterial implements TrimMaterial, io.papermc.paper.util.Holderable<net.minecraft.world.item.equipment.trim.TrimMaterial> { // Paper - switch to Holder public class CraftTrimMaterial implements TrimMaterial, io.papermc.paper.util.Holderable<net.minecraft.world.item.equipment.trim.TrimMaterial> { // Paper - switch to Holder
public static TrimMaterial minecraftToBukkit(net.minecraft.world.item.equipment.trim.TrimMaterial minecraft) { public static TrimMaterial minecraftToBukkit(net.minecraft.world.item.equipment.trim.TrimMaterial minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.TRIM_MATERIAL, Registry.TRIM_MATERIAL); return CraftRegistry.minecraftToBukkit(minecraft, Registries.TRIM_MATERIAL);
} }
public static TrimMaterial minecraftHolderToBukkit(Holder<net.minecraft.world.item.equipment.trim.TrimMaterial> minecraft) { public static TrimMaterial minecraftHolderToBukkit(Holder<net.minecraft.world.item.equipment.trim.TrimMaterial> minecraft) {
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registry.TRIM_MATERIAL); // Paper - switch to Holder return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.TRIM_MATERIAL); // Paper - switch to Holder
} }
public static net.minecraft.world.item.equipment.trim.TrimMaterial bukkitToMinecraft(TrimMaterial bukkit) { public static net.minecraft.world.item.equipment.trim.TrimMaterial bukkitToMinecraft(TrimMaterial bukkit) {
@ -42,7 +42,7 @@ public class CraftTrimMaterial implements TrimMaterial, io.papermc.paper.util.Ho
public static TrimMaterial objectToBukkit(Object object) { public static TrimMaterial objectToBukkit(Object object) {
Preconditions.checkArgument(object != null); Preconditions.checkArgument(object != null);
return io.papermc.paper.util.Holderable.fromBukkitSerializationObject(object, net.minecraft.world.item.equipment.trim.TrimMaterial.CODEC, Registry.TRIM_MATERIAL); // Paper - switch to Holder return io.papermc.paper.util.Holderable.fromBukkitSerializationObject(object, net.minecraft.world.item.equipment.trim.TrimMaterial.CODEC, RegistryKey.TRIM_MATERIAL); // Paper - switch to Holder
} }
@Override @Override

View File

@ -1,6 +1,7 @@
package org.bukkit.craftbukkit.inventory.trim; package org.bukkit.craftbukkit.inventory.trim;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.papermc.paper.registry.RegistryKey;
import io.papermc.paper.util.Holderable; import io.papermc.paper.util.Holderable;
import net.minecraft.core.Holder; import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
@ -8,18 +9,17 @@ import net.minecraft.network.chat.contents.TranslatableContents;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry; import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.inventory.meta.trim.TrimPattern; import org.bukkit.inventory.meta.trim.TrimPattern;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
public class CraftTrimPattern implements TrimPattern, io.papermc.paper.util.Holderable<net.minecraft.world.item.equipment.trim.TrimPattern> { // Paper - switch to Holder public class CraftTrimPattern implements TrimPattern, io.papermc.paper.util.Holderable<net.minecraft.world.item.equipment.trim.TrimPattern> { // Paper - switch to Holder
public static TrimPattern minecraftToBukkit(net.minecraft.world.item.equipment.trim.TrimPattern minecraft) { public static TrimPattern minecraftToBukkit(net.minecraft.world.item.equipment.trim.TrimPattern minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.TRIM_PATTERN, Registry.TRIM_PATTERN); return CraftRegistry.minecraftToBukkit(minecraft, Registries.TRIM_PATTERN);
} }
public static TrimPattern minecraftHolderToBukkit(Holder<net.minecraft.world.item.equipment.trim.TrimPattern> minecraft) { public static TrimPattern minecraftHolderToBukkit(Holder<net.minecraft.world.item.equipment.trim.TrimPattern> minecraft) {
return CraftRegistry.minecraftHolderToBukkit(minecraft, Registry.TRIM_PATTERN); // Paper - switch to Holder return CraftRegistry.minecraftHolderToBukkit(minecraft, Registries.TRIM_PATTERN); // Paper - switch to Holder
} }
public static net.minecraft.world.item.equipment.trim.TrimPattern bukkitToMinecraft(TrimPattern bukkit) { public static net.minecraft.world.item.equipment.trim.TrimPattern bukkitToMinecraft(TrimPattern bukkit) {
@ -42,7 +42,7 @@ public class CraftTrimPattern implements TrimPattern, io.papermc.paper.util.Hold
public static TrimPattern objectToBukkit(Object object) { public static TrimPattern objectToBukkit(Object object) {
Preconditions.checkArgument(object != null); Preconditions.checkArgument(object != null);
return io.papermc.paper.util.Holderable.fromBukkitSerializationObject(object, net.minecraft.world.item.equipment.trim.TrimPattern.CODEC, Registry.TRIM_PATTERN); // Paper - switch to Holder return io.papermc.paper.util.Holderable.fromBukkitSerializationObject(object, net.minecraft.world.item.equipment.trim.TrimPattern.CODEC, RegistryKey.TRIM_PATTERN); // Paper - switch to Holder
} }
@Override @Override

View File

@ -40,6 +40,7 @@ import org.bukkit.entity.Villager;
import org.bukkit.map.MapCursor; import org.bukkit.map.MapCursor;
import org.bukkit.util.OldEnum; import org.bukkit.util.OldEnum;
@Deprecated
@NotInBukkit @NotInBukkit
@RequireCompatibility("enum-compatibility-mode") @RequireCompatibility("enum-compatibility-mode")
@RequirePluginVersion(maxInclusive = "1.20.6") @RequirePluginVersion(maxInclusive = "1.20.6")

View File

@ -5,7 +5,6 @@ import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries; import net.minecraft.core.registries.Registries;
import net.minecraft.world.level.saveddata.maps.MapDecorationType; import net.minecraft.world.level.saveddata.maps.MapDecorationType;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.map.MapCursor; import org.bukkit.map.MapCursor;
@ -17,7 +16,7 @@ public final class CraftMapCursor {
private static int count = 0; private static int count = 0;
public static MapCursor.Type minecraftToBukkit(MapDecorationType minecraft) { public static MapCursor.Type minecraftToBukkit(MapDecorationType minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.MAP_DECORATION_TYPE, Registry.MAP_DECORATION_TYPE); return CraftRegistry.minecraftToBukkit(minecraft, Registries.MAP_DECORATION_TYPE);
} }
public static MapCursor.Type minecraftHolderToBukkit(Holder<MapDecorationType> minecraft) { public static MapCursor.Type minecraftHolderToBukkit(Holder<MapDecorationType> minecraft) {

View File

@ -5,7 +5,6 @@ import net.minecraft.core.registries.Registries;
import net.minecraft.world.effect.MobEffect; import net.minecraft.world.effect.MobEffect;
import org.bukkit.Color; import org.bukkit.Color;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.craftbukkit.CraftRegistry; import org.bukkit.craftbukkit.CraftRegistry;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
import org.bukkit.potion.PotionEffect; import org.bukkit.potion.PotionEffect;
@ -20,7 +19,7 @@ public class CraftPotionEffectType extends PotionEffectType implements Handleabl
} }
public static PotionEffectType minecraftToBukkit(MobEffect minecraft) { public static PotionEffectType minecraftToBukkit(MobEffect minecraft) {
return CraftRegistry.minecraftToBukkit(minecraft, Registries.MOB_EFFECT, Registry.EFFECT); return CraftRegistry.minecraftToBukkit(minecraft, Registries.MOB_EFFECT);
} }
public static MobEffect bukkitToMinecraft(PotionEffectType bukkit) { public static MobEffect bukkitToMinecraft(PotionEffectType bukkit) {

View File

@ -2,6 +2,7 @@ package org.bukkit.craftbukkit.potion;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import com.google.common.base.Suppliers; import com.google.common.base.Suppliers;
import io.papermc.paper.registry.RegistryKey;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -72,7 +73,7 @@ public class CraftPotionType implements PotionType.InternalPotionData {
if (key == null) return null; // Paper - Fixup NamespacedKey handling if (key == null) return null; // Paper - Fixup NamespacedKey handling
// Now also convert from when keys where saved // Now also convert from when keys where saved
return CraftRegistry.get(Registry.POTION, key, ApiVersion.CURRENT); return CraftRegistry.get(RegistryKey.POTION, key, ApiVersion.CURRENT);
} }
private final NamespacedKey key; private final NamespacedKey key;

View File

@ -12,17 +12,16 @@ import com.mojang.brigadier.StringReader;
import com.mojang.brigadier.exceptions.CommandSyntaxException; import com.mojang.brigadier.exceptions.CommandSyntaxException;
import com.mojang.serialization.Dynamic; import com.mojang.serialization.Dynamic;
import com.mojang.serialization.JsonOps; import com.mojang.serialization.JsonOps;
import io.papermc.paper.registry.RegistryKey;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.EnumSet;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.logging.Level; import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.stream.Stream; import java.util.stream.Stream;
import io.papermc.paper.entity.EntitySerializationFlag; import io.papermc.paper.entity.EntitySerializationFlag;
import net.minecraft.SharedConstants; import net.minecraft.SharedConstants;
@ -48,11 +47,9 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.LevelResource; import net.minecraft.world.level.storage.LevelResource;
import org.bukkit.Bukkit; import org.bukkit.Bukkit;
import org.bukkit.FeatureFlag;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.Material; import org.bukkit.Material;
import org.bukkit.NamespacedKey; import org.bukkit.NamespacedKey;
import org.bukkit.Registry;
import org.bukkit.UnsafeValues; import org.bukkit.UnsafeValues;
import org.bukkit.World; import org.bukkit.World;
import org.bukkit.advancement.Advancement; import org.bukkit.advancement.Advancement;
@ -66,14 +63,12 @@ import org.bukkit.craftbukkit.CraftServer;
import org.bukkit.craftbukkit.CraftWorld; import org.bukkit.craftbukkit.CraftWorld;
import org.bukkit.craftbukkit.block.CraftBiome; import org.bukkit.craftbukkit.block.CraftBiome;
import org.bukkit.craftbukkit.block.data.CraftBlockData; import org.bukkit.craftbukkit.block.data.CraftBlockData;
import org.bukkit.craftbukkit.damage.CraftDamageEffect;
import org.bukkit.craftbukkit.damage.CraftDamageSourceBuilder; import org.bukkit.craftbukkit.damage.CraftDamageSourceBuilder;
import org.bukkit.craftbukkit.entity.CraftEntity; import org.bukkit.craftbukkit.entity.CraftEntity;
import org.bukkit.craftbukkit.inventory.CraftItemStack; import org.bukkit.craftbukkit.inventory.CraftItemStack;
import org.bukkit.craftbukkit.legacy.CraftLegacy; import org.bukkit.craftbukkit.legacy.CraftLegacy;
import org.bukkit.craftbukkit.legacy.FieldRename; import org.bukkit.craftbukkit.legacy.FieldRename;
import org.bukkit.craftbukkit.potion.CraftPotionType; import org.bukkit.craftbukkit.potion.CraftPotionType;
import org.bukkit.damage.DamageEffect;
import org.bukkit.damage.DamageSource; import org.bukkit.damage.DamageSource;
import org.bukkit.damage.DamageType; import org.bukkit.damage.DamageType;
import org.bukkit.enchantments.Enchantment; import org.bukkit.enchantments.Enchantment;
@ -495,7 +490,7 @@ public final class CraftMagicNumbers implements UnsafeValues {
} }
@Override @Override
public <B extends Keyed> B get(Registry<B> registry, NamespacedKey namespacedKey) { public <B extends Keyed> B get(RegistryKey<B> registry, NamespacedKey namespacedKey) {
// We currently do not have any version-dependent remapping, so we can use current version // We currently do not have any version-dependent remapping, so we can use current version
return CraftRegistry.get(registry, namespacedKey, ApiVersion.CURRENT); return CraftRegistry.get(registry, namespacedKey, ApiVersion.CURRENT);
} }

View File

@ -34,11 +34,11 @@ public class PerRegistryTest {
try { try {
Object object = registryField.get(null); Object object = registryField.get(null);
// Ignore Bukkit's default SimpleRegistry. It cannot be tested correctly // Ignore Bukkit's default SimpleRegistry. It cannot be tested correctly
if (!(object instanceof CraftRegistry<?, ?> registry)) { if (object instanceof Registry.NotARegistry) {
continue; continue;
} }
data.add(Arguments.of(registry)); data.add(Arguments.of(object));
} catch (ReflectiveOperationException e) { } catch (ReflectiveOperationException e) {
e.printStackTrace(); e.printStackTrace();
} }

View File

@ -1,8 +1,5 @@
package org.bukkit.registry; package org.bukkit.registry;
import static org.junit.jupiter.api.Assertions.*;
import static org.junit.jupiter.api.Assumptions.*;
import static org.mockito.Mockito.*;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import io.papermc.paper.registry.RegistryKey; import io.papermc.paper.registry.RegistryKey;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -13,7 +10,6 @@ import java.util.HashSet;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import net.minecraft.resources.ResourceKey; import net.minecraft.resources.ResourceKey;
import org.bukkit.Bukkit;
import org.bukkit.Keyed; import org.bukkit.Keyed;
import org.bukkit.Registry; import org.bukkit.Registry;
import org.bukkit.craftbukkit.util.Handleable; import org.bukkit.craftbukkit.util.Handleable;
@ -25,6 +21,13 @@ import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.TestMethodOrder; import org.junit.jupiter.api.TestMethodOrder;
import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.Arguments;
import static org.junit.jupiter.api.Assertions.assertSame;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.Mockito.mock;
@AllFeatures @AllFeatures
@TestMethodOrder(MethodOrderer.OrderAnnotation.class) @TestMethodOrder(MethodOrderer.OrderAnnotation.class)
public class RegistryConversionTest { public class RegistryConversionTest {
@ -260,7 +263,7 @@ public class RegistryConversionTest {
Joiner.on('\n').withKeyValueSeparator(" got: ").join(notMatching))); Joiner.on('\n').withKeyValueSeparator(" got: ").join(notMatching)));
} }
static final Set<RegistryKey<?>> IGNORE_FOR_DIRECT_HOLDER = Set.of(RegistryKey.TRIM_MATERIAL, RegistryKey.TRIM_PATTERN, RegistryKey.INSTRUMENT, RegistryKey.PAINTING_VARIANT, RegistryKey.BANNER_PATTERN, RegistryKey.SOUND_EVENT); // Paper static final Set<RegistryKey<?>> IGNORE_FOR_DIRECT_HOLDER = Set.of(RegistryKey.TRIM_MATERIAL, RegistryKey.TRIM_PATTERN, RegistryKey.INSTRUMENT, RegistryKey.PAINTING_VARIANT, RegistryKey.BANNER_PATTERN, RegistryKey.SOUND_EVENT, RegistryKey.ENCHANTMENT); // Paper
/** /**
* Minecraft registry can return a default key / value * Minecraft registry can return a default key / value