Vswe's Summer Courses | You're not logged in. Sign up or log in | Server time: | Donate
One can now see other persons' badge hunts. Simply head over to their profiles to access them.

Go back to course page

Forging a Minecraft mod

Basic Minecraft modding with Minecraft Forge

Accessing xml files

  • 2014-06-05 19:36:54
    So I want to code some kind of info book (similar to thaumonomicon, TC Materials and you, arcane compendium or similar stuff) and I wanna read an xml file containing the information. How do you do that? (I guess you can't just use file access, because the class is zipped and the zip has some kind of cryptic version names)
  • 2014-06-06 21:46:03
    You can do different was depending if you are on the client or the server side.

    This gives you a InputStream of the file, works on both:
    InputStream inputStream = getClass().getResourceAsStream("/path/from/package/root.xml");
    InputStream inputStream = getClass().getResourceAsStream("path/from/the/current/class.xml");

    This gives you the InputStream of the file, works only on the Client.
    ResourceLocation location = new ResourceLocation("modID", "path/from/the/modID/folder/in/assets/folder.xml");
    InputStream inputStream = Minecraft.getMinecraft().getResourceManager().getResource(location).getInputStream();
  • 2014-06-08 06:48:06
    Thanks, thought about ResourceLocation but didn't know they weren't only for textures.
  • Log in or sign up to reply to this thread