Jump to content

Accessing world file


cad97

Recommended Posts

The mod I'm working on currently needs a data file to be saved. I am using .json and have no problems with that.

 

My problem is saving it properly.

 

To save the file I need to get a Java File object pointing at <minecraftdir>\saves\<worldname>\data\myFile.dat.

 

I can have generated a file pointing to the saves folder of the current minecraft directory, and this code works.

public static final File SAVES_DIRECTORY = new File(Minecraft.getMinecraft().mcDataDir, "/saves");

 

However, when attempting to get to the data folder, I've run into a hitch.

 

With world w, I can make the call

w.getWorldInfo().getWorldName()

to (theoretically) get the name of the world, and can use this to access the correct directory.

 

But instead of returning the name of my world save, the above snippet is returning "MpServer".

 

TLDR; So my question is, what is the best way to access the data folder inside of the save folder for a world?

Link to comment
Share on other sites

Yep! Works like a charm! Thank you!

 

FILE_PATH = new File(DimensionManager.getCurrentSaveRootDirectory().toPath() + "/data/commandblocksigns.json");

 

Just have to make sure this is called when the world is open. (obviously.)

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

Announcements



×
×
  • Create New...

Important Information

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