Jump to content
  • Home
  • Files
  • Docs
  • Merch
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [Solved] [1.12.2] Accessing files within the Mod jar
1.13 Update Notes for Mod Creators
Sign in to follow this  
Followers 1
simicats

[Solved] [1.12.2] Accessing files within the Mod jar

By simicats, March 9 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

simicats    2

simicats

simicats    2

  • Tree Puncher
  • simicats
  • Members
  • 2
  • 13 posts
Posted March 9 (edited)

Greetings,

 

having built my mostly client-side Mod into a jar, I soon noticed that it lost access to custom JSON and other text files I had placed in sub-folders of the resource directory.

I've tried several approaches to getting an InputStream for both file listing and reading, yet most of them - if at all - only worked when running it within the IDE. 

-> My question is: Is there a common way to read custom files shipped in the Mod jar, but not part of what belongs to actual resources (textures, models, ...).

 

Some of the things I've tried so far:

Mod.class.getClassLoader().getResourceAsStream(path);

Stopped working once jarred (even with the target files sitting next to the class files).

Minecraft.getMinecraft().getResourceManager().getResource(loc).getInputStream();

Throws a java.io.FileNotFoundException and will most likely not work for iterating over folder contents either way.

 

Apologies if this counts more as a java question, I'm just hoping to find someone who has done this in their work here.
Thanks for your time!~

 

[Edit] by future Simi:

Thanks again to draco for the reference below. The ClassLoader approach seems to be working for known file locations.

I have not gotten file listings to work, but for now I will resort to naming all the files I need uniformly with just an index appended.

Have a good day!

 

 

Edited March 9 by simicats
The issue was resolved.
  • Quote

Share this post


Link to post
Share on other sites

DavidM    102

DavidM

DavidM    102

  • World Shaper
  • DavidM
  • Members
  • 102
  • 1135 posts
Posted March 9

What are you trying to achieve? Why are you trying to manually access files?

  • Quote

Share this post


Link to post
Share on other sites

simicats    2

simicats

simicats    2

  • Tree Puncher
  • simicats
  • Members
  • 2
  • 13 posts
Posted March 9

Hi David, 

For me, this mod serves as a tool for designing Buildings quickly. It works as follows:

1. You draw and arrange cuboids that specify the parts of the building. 

2. The mod goes through its collection of walls / corners / roofs / etc. to decorate the specified rooms with. 

3. Afterwards you choose or create a palette of Blocks to be used in the building.

 

I figured, in order to make this tool portable into whatever pack I'd like to play or share it with others,

I need the mod, all of its designs and the pre-defined block palettes shipped within the jar for convenience.

Cheers!

  • Quote

Share this post


Link to post
Share on other sites

Draco18s    2093

Draco18s

Draco18s    2093

  • Reality Controller
  • Draco18s
  • Members
  • 2093
  • 14029 posts
Posted March 9

This might help:

https://github.com/Draco18s/ReasonableRealism/blob/1.12.1/src/main/java/com/draco18s/hardlib/CogHelper.java#L29

  • Like 1
  • Quote

Share this post


Link to post
Share on other sites

simicats    2

simicats

simicats    2

  • Tree Puncher
  • simicats
  • Members
  • 2
  • 13 posts
Posted March 9

Hi Draco,

thank you for the reference, I'll give it a shot!

  • Quote

Share this post


Link to post
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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  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.

  • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 1
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • DaemonUmbra
      problema con el heap space

      By DaemonUmbra · Posted 8 minutes ago

      User was banned for piracy. Buy the game.
    • lockedlol9
      problema con el heap space

      By lockedlol9 · Posted 9 minutes ago

    • JMAS
      net.minecraftforge.oredict.OreDictionary missing from 1.14.4 MDK

      By JMAS · Posted 25 minutes ago

      Thank you for the answer and for the constructive instruction.  Officially, I started learning Java about three weeks ago.  I completed the SoloLearn program last week, and am 82% of the way done re-viewing it to confirm that what I learned did stick.  I'm reading the Oracle tutorials at their website and am up to Controlling Access to Members of a Class.  Completed the first seven Mr Crayfish modding tutorials, and devoured Jorrit Tyberghein's "Modding Tutorial 1.14: Episode 1 (IDEA setup, basic mod and first block)" after being excoriated by Daemon Umbra for asking questions about 1.7.10. I've jumped in and started with the Minecraft mods as the review code because I can't learn in a vacuum.  I set up the Procyon decompiler and have been reviewing my son's favorite mods and attempting to recompile them for 1.14.4 (per D.U.), which is why my questions are oriented as they are; its the jump from 1.12.2 to 1.14.4 (which would be JDK 7 to JDK 8, I gather). I suspect that Daemon Umbra has lots of experience in coding but very little in human interaction and forgets that his position isn't aiding experts but is aiding newcomers. I thank you again for your instruction and for your good-natured demeanor. Respectfully, JMAS  
    • DaemonUmbra
      problema con el heap space

      By DaemonUmbra · Posted 26 minutes ago

      This crash report says you're in 1.13.2 What launcher are you using? Please provide a screenshot
    • lockedlol9
      problema con el heap space

      By lockedlol9 · Posted 58 minutes ago

      the launcher say me that im in 1.14.4-forge-28.1.94
  • Topics

    • lockedlol9
      5
      problema con el heap space

      By lockedlol9
      Started 1 hour ago

    • JMAS
      7
      net.minecraftforge.oredict.OreDictionary missing from 1.14.4 MDK

      By JMAS
      Started 7 hours ago

    • Barca
      6
      cant use mods in survival 1.12.2

      By Barca
      Started 4 hours ago

    • JMAS
      5
      pointing to MCP folder instead of MDK ???

      By JMAS
      Started 2 hours ago

    • solitone
      19
      Distinguish singleplayer vs. multiplayer

      By solitone
      Started December 5

  • Who's Online (See full list)

    • thevortex
    • Ronaldi2001
    • blender dog
    • Professional Derp
    • lockedlol9
    • DaemonUmbra
    • PrinceRaiden
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [Solved] [1.12.2] Accessing files within the Mod jar
  • Theme
  • Contact Us
  • Discord

Copyright © 2019 ForgeDevelopment LLC · Ads by Curse Powered by Invision Community