Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

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

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.

  • Author

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

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

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

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.