Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.14.4] Loading asset/data files


Keheck
 Share

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
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.

 Share



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • So I've gotten this error and I tried fixing it the way another form did, but it came with no success and I am truly lost as this isn't well documented. Doing `gradlew build` shows: My gradlew path is the following: C:/     Gradle         bin         docs         init.d         lib         src         LICENSE         NOTICE         README The bin is added to the system environment variables "Path" list.   Any help? Thanks!
    • I downloaded the Forge Server Installer and installed the server to my root directory, then I tried to launch the server and got nothing but a log file, it did not even generate the files. This is all that is in the log files, I am running the latest Java 8 version. [28Jan2022 16:56:15.763] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher running: args [--gameDir, ., --launchTarget, fmlserver, --fml.forgeVersion, 36.2.23, --fml.mcpVersion, 20210115.111550, --fml.mcVersion, 1.16.5, --fml.forgeGroup, net.minecraftforge] [28Jan2022 16:56:15.765] [main/INFO] [cpw.mods.modlauncher.Launcher/MODLAUNCHER]: ModLauncher 8.0.9+86+master.3cf110c starting: java version 17.0.2 by Oracle Corporation [28Jan2022 16:56:15.774] [main/DEBUG] [cpw.mods.modlauncher.LaunchServiceHandler/MODLAUNCHER]: Found launch services [minecraft,testharness,fmlclient,fmlserver]  
    • Here is the log file https://drive.google.com/file/d/1Y456kYGNFfgbNDpoE3cW735JKRV-WRt1/view?usp=sharing
    • Here's the new log https://gist.github.com/RichyZ2002/fdaaacb1fd39095d5e15e5d5101542a4
    • I have read the documentation and run the example once, but attach is not executed. When the subscribed Entity is called, attach is called, and then MyCapabilityImplementation is called. fill in the code in the place corresponding to MyCapabilityImplementation. This is how I understand it, am I wrong And I'm not sure what the need for the ResourceLocation string is. It says there are no restrictions, so does that mean it is an ID for identification purposes? Main public void registerCapabilities(RegisterCapabilitiesEvent event) { MyCapability.register(event); }  
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.