tutorial:registry
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Next revision | |||
— | tutorial:registry [2020/01/10 21:43] – created draylar | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Registry System ====== | ||
+ | |||
+ | You will need to register most content you add to the game. This helps with: | ||
+ | * Letting the game know your content exists | ||
+ | * Verifying game content between client & server | ||
+ | * Handling invalid content in a save | ||
+ | * Preventing conflicts between different mods | ||
+ | * Compression for client <-> server communication and data saving | ||
+ | * Abstracting or hiding numerical IDs | ||
+ | |||
+ | 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. | ||
+ | |||
+ | ===== 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 '' | ||
+ | |||
+ | For a deeper overview and description of all available registries, read the [[# | ||
+ | |||
+ | ===== Registering Content ===== | ||
+ | |||
+ | Use '' | ||
+ | |||
+ | <code java> | ||
+ | public static <T> T register(Registry<? | ||
+ | return ((MutableRegistry)registry).add(id, | ||
+ | } | ||
+ | </ | ||
+ | **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. Standard convention is '' | ||
+ | |||
+ | **entry** - an instance of the content you want to register. | ||
+ | |||
+ | ===== Registry Methods ===== | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code java> | ||
+ | @Nullable | ||
+ | public abstract Identifier getId(T entry); | ||
+ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | '' | ||
+ | |||
+ | <code java> | ||
+ | public abstract int getRawId(@Nullable T entry); | ||
+ | </ | ||
tutorial/registry.txt · Last modified: 2023/05/15 03:31 by phanabani