CLASS net/minecraft/class_2378 net/minecraft/registry/Registry COMMENT A registry is used to register various in-game components. Almost all parts of the COMMENT game - from blocks, items, and entity types, to cat types, goat horn instruments, COMMENT and structure pools - are registered in registries. Registry system allows the game COMMENT to enumerate all known types of something, and to assign a unique identifier to each COMMENT of those. Therefore, registering an object in the registry plays a very important COMMENT role, and failure to register new instances of registerable object usually results COMMENT in a bug or even a crash. COMMENT COMMENT

Terminologies

COMMENT

A registry is an object that holds the mapping between three things: COMMENT the string ID, the numeric ID, and the registered value. There are many registries COMMENT for different types of registerable objects, and a registry's type parameter indicates COMMENT the accepted type. For example, you register your {@link net.minecraft.block.Block} to {@code COMMENT Registry}. It's important to note that registries themselves are registered COMMENT in a "registry of registries", {@link Registries#ROOT}. COMMENT COMMENT

The string ID, usually just called "ID", is a human-readable COMMENT {@link Identifier} that uniquely identifies the registered value in a registry. COMMENT This should stay the same between two game versions, and is usually used for disk COMMENT storage. COMMENT COMMENT

The numeric ID or raw ID is an integer COMMENT assigned automatically by the registry to each registered value. This is not COMMENT guaranteed to stay the same between two game versions, and is usually used for COMMENT networking purposes. COMMENT COMMENT

The registered value, often just called "value" in the code, COMMENT is the value added to the registry. The registry's type parameter determines COMMENT the type of the registered value. COMMENT COMMENT

Each registered value can also be identified with a {@linkplain RegistryKey COMMENT registry key}. A registry key is a combination of the registry's ID and COMMENT the registered value's ID. Using a registry key makes the type of the ID's COMMENT associated value clear, as the type parameter contains the type. COMMENT COMMENT

A {@linkplain RegistryEntry registry entry} is an object COMMENT holding a value that can be registered in a registry. In most cases, the COMMENT value is already registered in a registry ("reference entry"), hence the name; COMMENT however, it is possible to create a registry entry by direct reference COMMENT ("direct entry"). This is useful for data packs, as they can define COMMENT one-time use values directly without having to register them every time. COMMENT COMMENT

A {@link RegistryEntryList registry entry list} is a list COMMENT of registry entries. This, is either a direct reference to each item, or COMMENT a reference to a tag. A tag is a way to dynamically COMMENT define a list of registered values. Anything registered in a registry COMMENT can be tagged, and each registry holds a list of tags it recognizes. COMMENT COMMENT

Static and dynamic registries

COMMENT

There are two kinds of registries: static and dynamic. COMMENT COMMENT

COMMENT COMMENT

Using Registry

COMMENT

Reading Registry

COMMENT

A registry is also an {@link IndexedIterable}. Therefore, registries can be COMMENT iterated using, e.g. {@code for (Block block : Registries.BLOCK)}. COMMENT COMMENT

There are several other methods used for reading the contents of the registry: COMMENT

COMMENT COMMENT

Registering something to Registry

COMMENT

The steps for registration are different, depending on whether the registry is static COMMENT or dynamic. For dynamic registries, data packs can usually be used to register a new COMMENT value or replace one. For static registries, the game's code must be modified. COMMENT COMMENT

Static registries are defined in {@link Registries}, and unlike the dynamic registries, it COMMENT cannot be changed after the game initialization. The game enforces this by "freezing" COMMENT the registry. Attempting to register a value after freezing causes a crash, such as COMMENT "Registry is already frozen". Modding APIs usually provide a way to bypass this restriction. COMMENT COMMENT

Use {@link #register(Registry, Identifier, Object)} for registering a value to a registry. COMMENT COMMENT

Intrusive holders

COMMENT

For historical reasons, there are two types of reference registry entries. COMMENT (This is different from the "direct" and "reference" registry entry types.) COMMENT COMMENT

COMMENT COMMENT

When a class whose instances are registered as intrusive holders, such as COMMENT {@link net.minecraft.block.Block} or {@link net.minecraft.item.Item}, are instantiated COMMENT without registering, the game crashes with "Some intrusive holders were not added to COMMENT registry" error message. This includes conditional registration. COMMENT For example, the code below can cause a crash: COMMENT COMMENT

{@code
	COMMENT Item myItem = new Item(new Item.Settings());
	COMMENT if (condition) {
	COMMENT     Registry.register(Registries.ITEM, new Identifier("example", "bad"), myItem);
	COMMENT }
	COMMENT }
COMMENT COMMENT

The correct way is to make the instantiation conditional as well: COMMENT COMMENT

{@code
	COMMENT if (condition) {
	COMMENT     Item myItem = new Item(new Item.Settings());
	COMMENT     Registry.register(Registries.ITEM, new Identifier("example", "bad"), myItem);
	COMMENT }
	COMMENT }
METHOD keys (Lcom/mojang/serialization/DynamicOps;)Ljava/util/stream/Stream; ARG 1 ops METHOD method_10220 stream ()Ljava/util/stream/Stream; COMMENT {@return a stream of all values of this registry} METHOD method_10221 getId (Ljava/lang/Object;)Lnet/minecraft/class_2960; COMMENT {@return the ID assigned to {@code value}, or {@code null} if it is not registered} ARG 1 value METHOD method_10223 get (Lnet/minecraft/class_2960;)Ljava/lang/Object; COMMENT {@return the value that is assigned {@code id}, or {@code null} if there is none} ARG 1 id METHOD method_10226 register (Lnet/minecraft/class_2378;Ljava/lang/String;Ljava/lang/Object;)Ljava/lang/Object; ARG 0 registry ARG 1 id ARG 2 entry METHOD method_10230 register (Lnet/minecraft/class_2378;Lnet/minecraft/class_2960;Ljava/lang/Object;)Ljava/lang/Object; COMMENT Registers {@code entry} to {@code registry} under {@code id}. COMMENT COMMENT @return the passed {@code entry} ARG 0 registry ARG 1 id ARG 2 entry METHOD method_10235 getIds ()Ljava/util/Set; COMMENT {@return the set of all IDs registered in a registry} METHOD method_10240 getRandom (Lnet/minecraft/class_5819;)Ljava/util/Optional; COMMENT {@return a random registry entry from this registry, or an empty optional if the COMMENT registry is empty} ARG 1 random METHOD method_10250 containsId (Lnet/minecraft/class_2960;)Z COMMENT {@return whether {@code id} is registered in this registry} ARG 1 id METHOD method_17966 getOrEmpty (Lnet/minecraft/class_2960;)Ljava/util/Optional; COMMENT {@return the value that is assigned {@code id}, or an empty optional if there is none} ARG 1 id METHOD method_29107 get (Lnet/minecraft/class_5321;)Ljava/lang/Object; COMMENT {@return the value that is assigned {@code key}, or {@code null} if there is none} ARG 1 key METHOD method_29113 getKey (Ljava/lang/Object;)Ljava/util/Optional; COMMENT {@return the registry key of {@code value}, or an empty optional if it is not registered} ARG 1 entry METHOD method_29722 getEntrySet ()Ljava/util/Set; COMMENT {@return the set containing {@link Map.Entry} of the registry keys and values registered COMMENT in this registry} METHOD method_30517 getKey ()Lnet/minecraft/class_5321; COMMENT {@return the registry key that identifies this registry} METHOD method_31138 getLifecycle ()Lcom/mojang/serialization/Lifecycle; METHOD method_31139 getEntryLifecycle (Ljava/lang/Object;)Lcom/mojang/serialization/Lifecycle; COMMENT Gets the lifecycle of a registry entry. ARG 1 entry METHOD method_31140 getOrThrow (Lnet/minecraft/class_5321;)Ljava/lang/Object; COMMENT {@return the value that is assigned {@code key}} COMMENT COMMENT @throws IllegalStateException if there is no value with {@code key} in the registry ARG 1 key METHOD method_31189 getOrEmpty (Lnet/minecraft/class_5321;)Ljava/util/Optional; COMMENT {@return the value that is assigned {@code key}, or an empty optional if there is none} ARG 1 key METHOD method_34028 (Lcom/mojang/serialization/DynamicOps;Lnet/minecraft/class_2960;)Ljava/lang/Object; ARG 1 id METHOD method_35842 contains (Lnet/minecraft/class_5321;)Z COMMENT {@return whether {@code key} is registered in this registry} ARG 1 key METHOD method_39197 register (Lnet/minecraft/class_2378;Lnet/minecraft/class_5321;Ljava/lang/Object;)Ljava/lang/Object; COMMENT Registers {@code entry} to {@code registry} under {@code key}. COMMENT COMMENT @return the passed {@code entry} ARG 0 registry ARG 1 key ARG 2 entry METHOD method_39667 (Lnet/minecraft/class_2960;)Lcom/mojang/serialization/DataResult; ARG 1 id METHOD method_39670 (Ljava/lang/Object;)I ARG 1 value METHOD method_39671 (Ljava/lang/Object;)Lcom/mojang/serialization/DataResult; ARG 1 value METHOD method_39673 getCodec ()Lcom/mojang/serialization/Codec; COMMENT {@return the codec for serializing {@code T}} COMMENT COMMENT @implNote This serializes a value using the ID or (if compressed) the raw ID. METHOD method_40257 populateTags (Ljava/util/Map;)V ARG 1 tagEntries METHOD method_40260 getOrCreateEntryList (Lnet/minecraft/class_6862;)Lnet/minecraft/class_6885$class_6888; ARG 1 tag METHOD method_40264 getEntry (Lnet/minecraft/class_5321;)Ljava/util/Optional; COMMENT {@return the reference registry entry for the value assigned {@code key}, or an COMMENT empty optional if there is no such value} COMMENT COMMENT @see #entryOf ARG 1 key METHOD method_40265 getEntry (I)Ljava/util/Optional; COMMENT {@return the reference registry entry for the value assigned {@code rawId}, or an COMMENT empty optional if there is no such value} ARG 1 rawId METHOD method_40266 getEntryList (Lnet/minecraft/class_6862;)Ljava/util/Optional; COMMENT {@return the registry entry list of values that are assigned {@code tag}, or an empty COMMENT optional if the tag is not known to the registry} ARG 1 tag METHOD method_40269 createEntry (Ljava/lang/Object;)Lnet/minecraft/class_6880$class_6883; ARG 1 value METHOD method_40270 streamEntries ()Ljava/util/stream/Stream; COMMENT {@return a stream of reference registry entries of this registry} METHOD method_40272 streamTagsAndEntries ()Ljava/util/stream/Stream; METHOD method_40273 streamTags ()Ljava/util/stream/Stream; COMMENT {@return a stream of all tag keys known to this registry} METHOD method_40276 freeze ()Lnet/minecraft/class_2378; METHOD method_40278 clearTags ()V METHOD method_40285 (Lnet/minecraft/class_6880;)Lcom/mojang/serialization/DataResult; ARG 1 entry METHOD method_40286 iterateEntries (Lnet/minecraft/class_6862;)Ljava/lang/Iterable; COMMENT {@return an iterable of values that are assigned {@code tag}, or an empty iterable COMMENT if the tag is not known to the registry} ARG 1 tag METHOD method_40290 entryOf (Lnet/minecraft/class_5321;)Lnet/minecraft/class_6880$class_6883; COMMENT {@return the reference registry entry for the value assigned {@code key}} COMMENT COMMENT @throws IllegalStateException if there is no value that is assigned {@code key} COMMENT COMMENT @see #getEntry(RegistryKey) ARG 1 key METHOD method_40294 createEntryCodec ()Lcom/mojang/serialization/Codec; COMMENT {@return the codec for serializing the registry entry of {@code T}} COMMENT COMMENT @implNote This serializes a registry entry using the ID. METHOD method_40295 getIndexedEntries ()Lnet/minecraft/class_2359; METHOD method_42021 getKeys ()Ljava/util/Set; COMMENT {@return the set of all registry keys registered in a registry} METHOD method_46770 getEntryOwner ()Lnet/minecraft/class_7876; METHOD method_46771 getReadOnlyWrapper ()Lnet/minecraft/class_7225$class_7226; COMMENT {@return a registry wrapper that does not mutate the backing registry under COMMENT any circumstances} METHOD method_46772 getTagCreatingWrapper ()Lnet/minecraft/class_7225$class_7226; COMMENT {@return a registry wrapper that creates and stores a new registry entry list COMMENT when handling an unknown tag key} METHOD method_47441 (Lnet/minecraft/class_6880;)Lcom/mojang/serialization/Lifecycle; ARG 1 entry METHOD method_47442 (Lnet/minecraft/class_6880;)Lcom/mojang/serialization/Lifecycle; ARG 1 entry METHOD method_47443 (Lnet/minecraft/class_2960;)Lcom/mojang/serialization/DataResult; ARG 1 id METHOD method_47983 getEntry (Ljava/lang/Object;)Lnet/minecraft/class_6880; ARG 1 value METHOD method_47984 registerReference (Lnet/minecraft/class_2378;Lnet/minecraft/class_5321;Ljava/lang/Object;)Lnet/minecraft/class_6880$class_6883; ARG 0 registry ARG 1 key ARG 2 entry METHOD method_47985 registerReference (Lnet/minecraft/class_2378;Lnet/minecraft/class_2960;Ljava/lang/Object;)Lnet/minecraft/class_6880$class_6883; ARG 0 registry ARG 1 id ARG 2 entry METHOD method_55841 getEntry (Lnet/minecraft/class_2960;)Ljava/util/Optional; ARG 1 id METHOD method_56159 getRandomEntry (Lnet/minecraft/class_6862;Lnet/minecraft/class_5819;)Ljava/util/Optional; COMMENT {@return a random entry from {@code tag}, or an empty {@link Optional} if the COMMENT tag is empty} ARG 1 tag ARG 2 random METHOD method_56160 (Lnet/minecraft/class_5819;Lnet/minecraft/class_6885$class_6888;)Ljava/util/Optional; ARG 1 entryList CLASS 1 METHOD method_46773 (Lnet/minecraft/class_6880$class_6883;)Lnet/minecraft/class_6880; ARG 0 entry