tutorial:custom_resources
Differences
This shows you the differences between two versions of the page.
Next revision | Previous revision | ||
tutorial:custom_resources [2021/01/24 20:51] – created azazelthedemonlord | tutorial:custom_resources [2024/06/29 07:10] (current) – [Reload Listeners 2: The Listener] Remove extra } daomephsta | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Custom Data/ | ====== Custom Data/ | ||
- | ===== A foreword | + | ===== A Foreword |
- | While not necessary to any extent, it is suggested that you first get accustomed to the basics of fabric | + | While not necessary to any extent, it is suggested that you first get accustomed to the basics of Fabric |
- | Furthermore, | + | Furthermore, |
===== Reload Listeners ===== | ===== Reload Listeners ===== | ||
Line 9: | Line 9: | ||
Data packs and resource packs are wonderful things, they are the heart of data-driven design in the Minecraft modding scene, and as such, learning to wrangle them is an important step of one's growth as a modder. | Data packs and resource packs are wonderful things, they are the heart of data-driven design in the Minecraft modding scene, and as such, learning to wrangle them is an important step of one's growth as a modder. | ||
- | Vanilla comes with a variety of data and resource pack resources, commonly known are things like textures, models, and after the havoc that was wrecked in 1.16.2, biomes, but this can be extended to be able to load custom data from data and resource packs. The process of extending the resource system to suit your mod's needs will be the main topic of this article, and it all starts with the use of '' | + | Vanilla comes with a variety of data and resource pack resources, commonly known are things like textures, models, and after the havoc that was wrecked in 1.16.2, biomes, but this can be extended to be able to load custom data from data and resource packs. The process of extending the resource system to suit your mod's needs will be the main topic of this article, and it all starts with the use of '' |
- | Any and all work you plan to do regarding resources must be registered through '' | + | Any and all work you plan to do regarding resources must be registered through '' |
- | From here on forward, examples will be centered around data packs and use '' | + | From here on forward, examples will be centered around data packs and use '' |
- | Continuing on the registry side of things, registering your reload listener is done through '' | + | Continuing on the registry side of things, registering your reload listener is done through '' |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
- | ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener([...]); | + | |
+ | public void onInitialize() { | ||
+ | | ||
+ | } | ||
| | ||
[...] | [...] | ||
Line 26: | Line 29: | ||
</ | </ | ||
- | ===== Reload Listeners 2: The actual listener | + | ===== Reload Listeners 2: The Listener |
We have now gone over the process of registering your reload listeners, but you have yet to actually //write// one, that part of the process will be discussed in this section (specifically, | We have now gone over the process of registering your reload listeners, but you have yet to actually //write// one, that part of the process will be discussed in this section (specifically, | ||
- | By all laws of programming, you should not be able to instantiate | + | To simplify this tutorial, an [[https:// |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
Line 40: | Line 43: | ||
@Override | @Override | ||
- | public void apply(ResourceManager manager) { | + | public void reload(ResourceManager manager) { |
[...] | [...] | ||
} | } | ||
Line 46: | Line 49: | ||
</ | </ | ||
- | What you are seeing here is the actual resource reload listener (technically | + | What you are seeing here is the actual resource reload listener (technically |
- | The apply method supplies you with a '' | + | The '' |
- | Firstly, you are going to want to clear or otherwise prepare to update anything that is storing the info you are going to be fetching through the manager, otherwise, your mod will likely break whenever ''/ | + | Firstly, you are going to want to clear or otherwise prepare to update anything that is storing the info you are going to be fetching through the manager, otherwise, your mod will likely break whenever ''/ |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
@Override | @Override | ||
- | public void apply(ResourceManager manager) { | + | public void reload(ResourceManager manager) { |
- | /* | + | // Clear caches |
- | * Clear your caches | + | |
- | */ | + | |
- | for(Identifier id : manager.findResources(" | + | |
- | + | try(InputStream | |
- | try(IntputStream | + | // Consume the stream however you want, medium, rare, or well done. |
- | | + | } catch(Exception e) { |
- | | + | TUTORIAL_LOG.error(" |
- | */ | + | } |
- | } catch(Exception e) ( | + | |
- | | + | |
- | | + | |
} | } | ||
[...] | [...] | ||
} | } | ||
- | } | ||
</ | </ | ||
- | There are two important things to note here. Firstly, all resources must be processed as '' | + | There are two important things to note here. Firstly, all resources must be processed as '' |
- | Once you are done, your code should look somewhat like this, at this point you can pat yourself in the back as you have successfully made a part of your mod data-driven! Any files contained in the " | + | Once you are done, your code should look somewhat like this. At this point, you can pat yourself in the back as you have successfully made a part of your mod data-driven! Any files contained in the " |
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
public class ExampleMod implements ModInitializer { | public class ExampleMod implements ModInitializer { | ||
+ | @Override | ||
+ | public void onInitialize() { | ||
+ | ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new SimpleSynchronousResourceReloadListener() { | ||
+ | @Override | ||
+ | public Identifier getFabricId() { | ||
+ | return new Identifier(" | ||
+ | } | ||
+ | @Override | ||
+ | public void reload(ResourceManager manager) { | ||
+ | // Clear Caches Here | ||
- | ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(new SimpleSynchronousResourceReloadListener() { | + | |
- | @Override | + | try(InputStream |
- | public Identifier getFabricId() { | + | // Consume the stream however you want, medium, rare, or well done. |
- | return new Identifier(" | + | } catch(Exception e) { |
- | } | + | TUTORIAL_LOG.error(" |
- | + | } | |
- | @Override | + | } |
- | public void apply(ResourceManager manager) { | + | } |
- | /* | + | }); |
- | * Clear your caches irit | + | } |
- | */ | + | |
- | + | ||
- | for(Identifier id : manager.findResources(" | + | |
- | + | ||
- | try(IntputStream | + | |
- | | + | |
- | | + | |
- | */ | + | |
- | } catch(Exception e) ( | + | |
- | | + | |
- | | + | |
- | | + | |
- | } | + | |
- | }); | + | |
[...] | [...] | ||
} | } | ||
</ | </ |
tutorial/custom_resources.1611521519.txt.gz · Last modified: 2021/01/24 20:51 by azazelthedemonlord