tutorial:custom_resources
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
tutorial:custom_resources [2021/03/04 16:06] – Remove distracting and unprofessional error message jummit | tutorial:custom_resources [2024/06/29 07:10] (current) – [Reload Listeners 2: The Listener] Remove extra } daomephsta | ||
---|---|---|---|
Line 20: | Line 20: | ||
<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 30: | Line 33: | ||
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 //a// resource reload listener, this is not the only type, however, it is the easiest to implement) that will be registered through '' | + | What you are seeing here is the actual resource reload listener (technically //a// resource reload listener, this is not the only type, however, it is the easiest to implement) that will be registered through '' |
- | The '' | + | 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 ''/ | ||
Line 54: | Line 57: | ||
<code java [enable_line_numbers=" | <code java [enable_line_numbers=" | ||
@Override | @Override | ||
- | public void apply(ResourceManager manager) { | + | public void reload(ResourceManager manager) { |
// Clear caches here | // Clear caches here | ||
for(Identifier id : manager.findResources(" | for(Identifier id : manager.findResources(" | ||
- | try(IntputStream | + | try(InputStream |
// Consume the stream however you want, medium, rare, or well done. | // Consume the stream however you want, medium, rare, or well done. | ||
- | } catch(Exception e) ( | + | } catch(Exception e) { |
TUTORIAL_LOG.error(" | TUTORIAL_LOG.error(" | ||
} | } | ||
Line 67: | Line 70: | ||
[...] | [...] | ||
} | } | ||
- | } | ||
</ | </ | ||
Line 76: | Line 78: | ||
<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(new SimpleSynchronousResourceReloadListener() { | + | |
- | @Override | + | public void onInitialize() { |
- | public Identifier getFabricId() { | + | |
- | return new Identifier(" | + | @Override |
- | } | + | public Identifier getFabricId() { |
+ | return new Identifier(" | ||
+ | } | ||
- | | + | |
- | public void apply(ResourceManager manager) { | + | public void reload(ResourceManager manager) { |
- | // Clear Caches Here | + | // Clear Caches Here |
- | | + | |
- | try(IntputStream | + | try(InputStream |
- | // Consume the stream however you want, medium, rare, or well done. | + | // Consume the stream however you want, medium, rare, or well done. |
- | } catch(Exception e) ( | + | } catch(Exception e) { |
- | TUTORIAL_LOG.error(" | + | TUTORIAL_LOG.error(" |
+ | } | ||
} | } | ||
} | } | ||
- | } | + | }); |
- | }); | + | } |
[...] | [...] | ||
} | } | ||
</ | </ |
tutorial/custom_resources.1614873989.txt.gz · Last modified: 2021/03/04 16:06 by jummit