User Tools

Site Tools


tutorial:registry

Differences

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

Link to this comparison view

Next revision
Previous revision
tutorial:registry [2020/01/10 21:43] – created draylartutorial:registry [2023/05/15 03:31] (current) – Fix missing period in code. phanabani
Line 9: Line 9:
   * Abstracting or hiding numerical IDs   * Abstracting or hiding numerical IDs
  
-When registering any type of content, you pass in an ''%%Identifier%%'', which is a label for your addition. Identifiers– often abbreviated as IDs– have a namespace and path. In most cases, the namespace is the ID of your mod, and the path is the name of the content you’re registering. For example, the standard dirt block has the ID of ''%%minecraft:dirt%%''.+When registering any type of content, you pass in an ''<yarn class_2960>'', which is a label for your addition. <yarn class_2960>s– often abbreviated as IDs– have a namespace and path. In most cases, the namespace is the ID of your mod, and the path is the name of the content you’re registering. For example, the standard dirt block has the ID of ''%%minecraft:dirt%%''.
  
 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 ''%%Registry%%''. Two examples of registries you may use include ''%%Registry.ITEM%%'' for items and ''%%Registry.BLOCK%%'' for blocks.+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 ''%%Registries%%'' (for 1.19.3 and above) or ''Registry'' (for below 1.19.3). 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|registry types]] page.+For a deeper overview and description of all available registries, read the [[tutorial:registry_types|registry types]] page.
  
 ===== Registering Content ===== ===== Registering Content =====
  
-Use ''%%Registry.register%%'' for adding content to registries:+Use ''<yarn class_2378>.<yarn method_10230>'' for adding content to registries:
  
-<code java> +<yarncode java> 
-public static <T> T register(Registry<? super T> registry, Identifier id, T entry) { +public static <T> T method_10230(class_2378<? super T> registry, class_2960 id, T entry) { 
-    return ((MutableRegistry)registry).add(id, entry);+    return ((class_2385)registry).method_10272(id, entry);
 } }
-</code+</yarncode
-**registry** - an instance of the registry you want to add content to. A list of all vanilla registries, located in ''%%Registry%%'', can be found in the [[#registry-types|registry types]] page.+**registry** - an instance of the registry you want to add content to. A list of all vanilla registries, located in ''<yarn class_2378>'', can be found in the [[tutorial:registry_types|registry types]] page.
  
 **id** - an identifying label for your content inside the registry. Standard convention is ''%%modid:name%%'', as seen with ''%%minecraft:dirt%%''. **id** - an identifying label for your content inside the registry. Standard convention is ''%%modid:name%%'', as seen with ''%%minecraft:dirt%%''.
Line 36: Line 36:
 ===== Registry Methods ===== ===== Registry Methods =====
  
-''%%getId%%'' - returns the ''%%Identifier%%'' associated with an entry inside a registry. If the entry doesn’t exist, ''%%DefaultedRegistry%%'' returns the default registry value, and ''%%SimpleRegistry%%'' returns null.+''<yarn method_10223>'' - returns the entry associated with an ID inside a registry. If the entry doesn’t exist, ''<yarn class_2348>'' returns the default registry value, and ''<yarn class_2370>'' returns null.
  
-<code java>+<yarncode java>
 @Nullable @Nullable
-public abstract Identifier getId(entry); +public abstract T method_10223(@Nullable class_2960 id); 
-</code>+</yarncode>
  
 ---- ----
  
-''%%getRawId%%'' - returns the internal integer ID associated with an entry inside a registry. If the entry doesn’t exist, ''%%DefaultedRegistry%%'' returns the raw ID of the default registry value, and ''%%SimpleRegistry%%'' returns -1.+''<yarn method_10221>'' - returns the ''<yarn class_2960>'' associated with an entry inside a registry. If the entry doesn’t exist, ''<yarn class_2348>'' returns the default registry ID, and ''<yarn class_2370>'' returns null.
  
-<code java> +<yarncode java> 
-public abstract int getRawId(@Nullable T entry); +@Nullable 
-</code>+public abstract class_2960 method_10221(T entry); 
 +</yarncode> 
 + 
 +---- 
 + 
 +''<yarn method_10206>'' - returns the internal integer ID associated with an entry inside a registry. If the entry doesn’t exist, ''<yarn class_2348>'' returns the raw ID of the default registry value, and ''<yarn class_2370>'' returns -1. 
 + 
 +<yarncode java> 
 +public abstract int method_10206(@Nullable T entry); 
 +</yarncode>
  
tutorial/registry.1578692620.txt.gz · Last modified: 2020/01/10 21:43 by draylar