User Tools

Site Tools


tutorial:registry

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
tutorial:registry [2024/08/25 13:20] – [Registry System] match the title in the sidebar solidblocktutorial:registry [2024/08/25 14:06] (current) solidblock
Line 1: Line 1:
 ====== Intro to Registries ====== ====== Intro to Registries ======
  
-Minecraft uses the **registry system** to handle almost everything in the game. For mod developers, 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 19: Line 19:
 Two examples of registries you may use include ''Registries.ITEM'' (for 1.19.3 above)/''Registry.ITEM'' (for 1.19.2 below) for items and ''Registries.BLOCK'' (for 1.19.3 above)/''Registry.BLOCK'' (for 1.19.2 below) for blocks. Two examples of registries you may use include ''Registries.ITEM'' (for 1.19.3 above)/''Registry.ITEM'' (for 1.19.2 below) for items and ''Registries.BLOCK'' (for 1.19.3 above)/''Registry.BLOCK'' (for 1.19.2 below) for blocks.
  
-For a deeper overview and description of all available registries, read the [[registry types]] page.+For a deeper overview and description of all available registries, read the ''Registries'' or ''Registry'' class. A brief description for the registry types can be found in [[registry types]] page.
  
 ===== Basic usages ===== ===== Basic usages =====
 ==== Registering your content ==== ==== Registering your content ====
-Use ''<yarn class_2378>.<yarn method_10230>'' to register your contents into registries. Remember, each content cannot be registered once. The basic syntax is:+Use ''<yarn class_2378>.<yarn method_10230>'' to register your contents into registries. Remember, each content can be registered no more than once. The basic syntax is:
  
 <code java> <code java>
Line 42: Line 42:
 ==== Getting the object by ID ==== ==== Getting the object by ID ====
  
-''<yarn method_10223>'' returns the content associated with an ID inside a registry. If the conten doesn’t exist, ''<yarn class_2348>'' returns the default registry value, and ''<yarn class_2370>'' returns null. You can use ''containsId'' or ''getOrEmpty'' method to test whether the id exists. For example:+''<yarn method_10223>'' returns the content associated with an ID inside a registry. If the content doesn’t exist, ''<yarn class_2348>'' returns the default registry value, and ''<yarn class_2370>'' returns null. You can use ''containsId'' or ''getOrEmpty'' method to test whether the id exists. For example:
  
 <yarncode java> <yarncode java>
Line 86: Line 86:
  
 A **registry entry** (''RegistryEntry'') is a wrapper of contents that belong to types that have registry. They have two types: A **registry entry** (''RegistryEntry'') is a wrapper of contents that belong to types that have registry. They have two types:
-  * ''RegistryEntry.Reference'': things that are registered in the register, and therefore have their IDs.+  * ''RegistryEntry.Reference'': things that are registered in the registry, and therefore have their IDs.
   * ''RegistryEntry.Direct'': things not registered in the register. They may be anonymously specified in some ways.   * ''RegistryEntry.Direct'': things not registered in the register. They may be anonymously specified in some ways.
  
Line 93: Line 93:
   * ''%%/loot give @s loot {pools:[{rolls:1, entries:[{type:"item", name:"minecraft:stone"}]}]}%%''   * ''%%/loot give @s loot {pools:[{rolls:1, entries:[{type:"item", name:"minecraft:stone"}]}]}%%''
  
-Both the two commands give you a stone. The former one will get the loot table ''minecraft:blocks/stone'' from the loot table registry of the world, so it is ''RegistryEntry.Reference''. The latter one will encode a loot table from a SNBT, which does not have an ID, so it is ''RegistryEntry.Direct''. Both the two type of registry entries can be fetched the actual content by calling ''value()'' method.+Both the two commands give you a stone. The former one will get the loot table ''minecraft:blocks/stone'' from the loot table registry of the world, so it is ''RegistryEntry.Reference''. The latter one will decode a loot table from a SNBT, which does not have an ID, so it is ''RegistryEntry.Direct''. Both the two type of registry entries can be fetched the actual content by calling ''value()'' method.
  
 ==== Registry entry list ==== ==== Registry entry list ====
  
-Similar to registry entries, **registry entry lists** (''RegistryEntryList'') are used in many cases and have two types:+Similar to registry entries, **registry entry lists** (''RegistryEntryList'') are used in many cases and also have two types:
   * ''RegistryEntryList.Named'': The list defined by [[tags]], which are defined in data packs.   * ''RegistryEntryList.Named'': The list defined by [[tags]], which are defined in data packs.
   * ''RegistryEntryList.Direct'': The list defirectly defined by listing all contents.   * ''RegistryEntryList.Direct'': The list defirectly defined by listing all contents.
tutorial/registry.1724592043.txt.gz · Last modified: 2024/08/25 13:20 by solidblock