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.

[Unsolved] Save Data Separate from World (i.e in saves/world/data/myfile.dat)

Featured Replies

Posted

I have some NBT data I want to save to .minecraft/saves/<world>/data/myfile.dat.  How would I do that?  I couldn't find out with google or the forge javadocs.  Do I just open a binary file and write the nbt in binary or does Forge have a function I should call?

 

Thanks,

electrodude

 

EDIT:  Also, how can I make it so this data gets loaded and saved automatically (i.e. by calling my object's readFromNBT and writeToNBT methods) on world load and save/quit?

here is the information that I found useful when I made my implementation of saving to world save folder....

 

http://www.minecraftforge.net/forum/index.php?topic=8520.0

 

https://github.com/diesieben07/Questology/blob/e9f46d8b3aa41b82f9021c892bca7ee558e7899a/source/demonmodders/questology/QuestologyWorldData.java

 

and... my implementation..with load/save stuff

 

https://github.com/shadowmage45/AncientWarfare/tree/master/AncientWarfare/src/shadowmage/ancient_warfare/common/tracker

(hint...load/save are handled mostly automatically whenever the world loads/saves, you just need to make sure you keep the data up-to-date)

 

Oh hey...Hi diesieben07 :)    hope you don't mind I used your previous example(s) :)

 

  • Author
  On 8/21/2013 at 3:01 PM, shadowmage4513 said:

-snip-

 

Thanks!  I looked at your code and that's exactly what I want!  The only question I have left (that I know of atm) is, how is your tracker told to load data (by making a new AWGameData()) on world load?  When is GameDataTracker.handleWorldLoad(World world) called?

That method is called from my event handler, from the worldLoad event:

 

@ForgeSubscribe
public void onWorldLoad(WorldEvent.Load evt)
  {
  if(evt.world instanceof WorldServer)
    {
    GameDataTracker.instance().handleWorldLoad(evt.world);
    }  
  }

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.