tutorial:registry
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:registry [2022/12/09 04:52] – [Registry Types] solidblock | tutorial:registry [2024/08/25 14:06] (current) – solidblock | ||
---|---|---|---|
Line 1: | Line 1: | ||
- | -====== | + | ====== |
- | You will need to register most content you add to the game. This helps with: | + | Minecraft uses the **registry system** to handle almost everything in the game. When developing mods, you will need to register most content you add to the game. This helps with: |
* Letting the game know your content exists | * Letting the game know your content exists | ||
* Verifying game content between client & server | * Verifying game content between client & server | ||
Line 9: | Line 9: | ||
* Abstracting or hiding numerical IDs | * Abstracting or hiding numerical IDs | ||
- | When registering any type of content, you pass in an ''< | + | When registering any type of content, you pass in an ''< |
Using custom content without registering it can lead to buggy behavior, such as missing textures, world save issues, and crashes. The game will usually let you know if you forget to register something. | Using custom content without registering it can lead to buggy behavior, such as missing textures, world save issues, and crashes. The game will usually let you know if you forget to register something. | ||
Line 15: | Line 15: | ||
===== Registry Types ===== | ===== Registry Types ===== | ||
- | When registering content, you need to specify which registry you are adding content to. The base game provides registries for all vanilla content, which can be found in '' | + | When registering content, you need to specify which registry you are adding content to. The base game provides registries for all vanilla content, which can be found in '' |
- | For a deeper overview and description | + | Two examples |
- | ===== Registering Content ===== | + | For a deeper overview and description of all available registries, read the '' |
- | Use ''< | + | ===== Basic usages ===== |
+ | ==== Registering your content ==== | ||
+ | Use ''< | ||
- | <yarncode | + | <code java> |
- | public static <T> T method_10230(class_2378<? | + | |
- | return ((class_2385)registry)method_10272(id, | + | </code> |
- | } | + | |
- | </yarncode> | + | |
- | **registry** - an instance of the registry you want to add content to. A list of all vanilla registries, located in ''< | + | |
- | **id** - an identifying label for your content inside the registry. | + | |
+ | * **id** - the identifier | ||
+ | * **content** - an instance of the content you want to register. | ||
- | **entry** - an instance of the content you want to register. | + | For example: |
+ | <code java> | ||
+ | Registry.register(Registries.ITEM, Identifier.of(" | ||
+ | </ | ||
- | ===== Registry Methods ===== | + | > Remember: registration should happen in mod initializers. Otherwise, you cannot register as they may have been frozen. |
- | ''< | + | ==== Getting the object by ID ==== |
+ | |||
+ | ''< | ||
< | < | ||
- | @Nullable | + | Registries.ITEM.containsId(Identifier.ofVanilla(" |
- | public abstract T method_10223(@Nullable class_2960 id); | + | |
+ | Registries.ITEM.containsId(Identifier.ofVanilla(" | ||
+ | |||
+ | Registries.ITEM.get(Identifier.ofVanilla(" | ||
+ | |||
+ | Registries.ITEM.get(Identifier.ofVanilla(" | ||
+ | |||
+ | Registries.ITEM.getOrEmpty(Identifier.ofVanilla(" | ||
+ | |||
+ | Registries.ITEM.getOrEmpty(Identifier.ofVanilla(" | ||
</ | </ | ||
- | ---- | + | ==== Getting the id of an object ==== |
- | ''< | + | ''< |
- | <yarncode | + | <code java> |
- | @Nullable | + | |
- | public abstract class_2960 method_10221(T entry); | + | </code> |
- | </yarncode> | + | |
- | ---- | + | ===== Related concepts ===== |
- | '' | + | ==== Registry keys ===== |
+ | Some type of registries are not staticly stored in '' | ||
- | <yarncode | + | However, each registry has a **registry key**, which can be found in '' |
- | public abstract int method_10206(@Nullable T entry); | + | |
- | </yarncode> | + | <code java> |
+ | final DynamicRegistryManager registryManager = world.getRegistryManager(); | ||
+ | |||
+ | // both of the following two statements return the '' | ||
+ | registryManager.get(RegistryKeys.BIOME).get(Identifier.ofVanilla(" | ||
+ | registryManager.getWrapperOrThrow(RegistryKeys.BIOME).getOrThrow(RegistryKey.of(RegistryKeys.BIOME, | ||
+ | </code> | ||
+ | |||
+ | Not only registries have registry keys. All registry contents have registry keys (as registries themselves also belong to registry contents of '' | ||
+ | |||
+ | ==== Registry entry ===== | ||
+ | |||
+ | A **registry entry** ('' | ||
+ | * '' | ||
+ | * '' | ||
+ | |||
+ | To explicitly show the differences between two, see the following two commands: | ||
+ | * ''/ | ||
+ | * '' | ||
+ | |||
+ | Both the two commands give you a stone. The former one will get the loot table '' | ||
+ | |||
+ | ==== Registry entry list ==== | ||
+ | Similar to registry entries, **registry entry lists** ('' | ||
+ | * '' | ||
+ | * '' |
tutorial/registry.1670561534.txt.gz · Last modified: 2022/12/09 04:52 by solidblock