Jump to content

Recommended Posts

Posted

I am trying to save information to a file on server side. My save method is getting triggered by WorldEvent.Save

 

I am getting this error when the world try's to save:

23:50:13] [server thread/ERROR] [FML]: Exception caught during firing event net.minecraftforge.event.world.WorldEvent$Save@7100ac37:
java.lang.ExceptionInInitializerError
at lidr.common.LiDrEvents.worldSave(LiDrEvents.java:32) ~[LiDrEvents.class:?]
...
Caused by: java.lang.NullPointerException
at lidr.common.DraftableReg.SaveDraftables(DraftableReg.java:57)

 

and my WorldSave Method:

@SubscribeEvent
public void worldSave(WorldEvent.Save e){
	if(!e.world.isRemote)
		DraftableReg.SaveDraftables(); // this is line 32
}

 

DraftableReg is a java "static" class meaning every field and method is static, private instructor with another field that instantiates it.

public final class DraftableReg {
public static final DraftableReg draftableReg = new DraftableReg();
        private static final URL LOCATION = draftableReg.getClass().getClassLoader().getResource("Draftables.json");

private DraftableReg(){
	DraftableMap dMap = new DraftableMap();
	dMap.AddPart(new TriTuple(0,0,0), new EdgePart(LuxinReg.RegisteredLuxin.get("Blue"), Purity.Base));
	RegisterDraftable(CoreFactory.GenerateFrom("test", CoreType.Sword, dMap)); //Testing items
}

public static void SaveDraftables(){
	try {
		GsonBuilder builder = new GsonBuilder();
		builder.registerTypeHierarchyAdapter(IDraftable.class, new DraftableAdapter<DraftingItemCore>());
		builder.enableComplexMapKeySerialization();
		builder.setPrettyPrinting();
		Gson gson = builder.create();
		BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(LOCATION.getFile()), "UTF-8"));
		gson.toJson(knowledgeBase, out); // this is line 57
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}

 

So obviously my URL is faulty. How should I be choosing a location to save to?

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

Yes, your save location is faulty because it is inside the JAR file.  You need to point to a location that has write access.

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.

Posted

Thats what I can't figure out how to get. Lets say this is the folder structure:

/
   mods/
           LightDrafter.jar
           ...
   config/
           LightDrafter/
                   Draftables.json

How do I get the path/URL of Draftables.json

Current Project: Armerger 

Planned mods: Light Drafter  | Ore Swords

Looking for help getting a mod off the ground? Coding  | Textures

Posted

Client-side you can get the game directory from Minecraft#mcDataDir, server-side from MinecraftServer#getDataDirectory(), or you can get it in pre-init with FMLPreInitializationEvent#getModConfigurationDirectory().

Posted

You can also use FMLInitializationEvent#getSuggestedConfigurationFile() which you could manipulate to get the config directory

 

There's also Loader.instance().getConfigDir()

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.

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.