Jump to content

[1.14.4] Loading asset/data files


Keheck

Recommended Posts

Is there a way to load files in the ./assets/ and ./data/ directory of any mod, including your own?

I'd imagine it to work with resource locations, but skimming over the usages of net.minecraft.util.ResourceLocation and net.minecraftforge.registries.ForgeRegistryEntry#getRegistryName didn't help me much.

 

If you're wondering why I want to load files: I'm working on a Pokemon-style mod, except it uses mobs from Minecraft and other mods, and I want other mods to be able to add thier own mobs (or "Fighters" as I call them) to my mod that you can then capture and fight with. And since adding such a Fighter would also mean adding moves it can learn, i want other modders to be able to write it in a .json file where they just list the registry names of the moves and my mod picks out the correct moves, so the actual code of the mod stays rather short and isn't littered with chained methods of adding moves.

 

Edit: I want to load the asset data during mod setup.

Edited by Keheck
Link to comment
Share on other sites

Yes. That's what a ResourceLocation represents, a domain ("mod ID") and location. You ask for new ResourceLocation("NotMyMod","SomeAsset") and you'll get it.

 

Of course, if you're writing a json loading system for a type of asset, I recommend looking into the JsonReloadListener system. As an example,

https://github.com/MinecraftForge/MinecraftForge/blob/d4b6540746ce5676a9a2efe24b87debb3f79dfe7/src/main/java/net/minecraftforge/common/loot/LootModifierManager.java#L38

Note that you need to register it with the MinecraftServer instance, which will require some reflection.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Link to comment
Share on other sites

36 minutes ago, Draco18s said:

Of course, if you're writing a json loading system for a type of asset, I recommend looking into the JsonReloadListener system. As an example,

https://github.com/MinecraftForge/MinecraftForge/blob/d4b6540746ce5676a9a2efe24b87debb3f79dfe7/src/main/java/net/minecraftforge/common/loot/LootModifierManager.java#L38

Note that you need to register it with the MinecraftServer instance, which will require some reflection.

I'm afraid this won't work for me... I want the data for the Fighter during mod setup, specifically during the registraion of the Fighters.

Here's how I invisioned it (this will all happen inside a registry handler for the Fighter Registry with lowest event priority, so it is (likely) the last one to get called):

 

  • Get a list of all the registered fighters.
  • Loop the following for every entry (and account for errors):
    • Get the registry name of the entry
    • Is the domain empty or does it equal "minecraft"?
      • Yes: Look into "./data/mobfighters/"  ("mobfighters" is the modid of my mod)
      • No: Look into "./data/<domain>"/
    • Search in the data directory for "./fighter/<path>"
    • Read the .json
    • Pass the read data onto the entry.

 

Does the way I want to do it even make sense, or is it safe to do that?

If you want to look at my code, I have a repo here.

(The important classes are io.github.keheck.mobfighters.registry.entries.FighterEntry and io.github.keheck.mobfighters.registry.Registry)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.