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'm trying to save player NBT in an external file and be able to load it later when the player logs in.

 

In a PlayerLoggedInEvent listener I put the code:

NBTInputStream inputStream = new NBTInputStream(new GZIPInputStream(new FileInputStream(savedFile)));
CompoundTag savedCompound = (CompoundTag) inputStream.readTag();

for(Map.Entry<String, ITag> entry : savedCompound.getTags().entrySet()){
     ITag tag = entry.getValue();
     event.player.getEntityData().setTag(tag.getName(), getType(tag));
}

I implemented an NBT reader to parse through the data in the file, as you can't get the value or name of tags with the minecraft classes, so that's what ITag and CompoundTag are. getType(tag) just returns a new NBTBase of the correct type (NBTTagByte, NBTTagInt, etc) with the value in the ITag.

 

The NBT file is read just fine, however the player's NBT remains the same after this, as displayed by their inventory remaining empty rather than filling up with the saved inventory. How can I make it update with the new data?

  • Author

Well, getEntityData doesn't seem to be saving the changes I made to it for some reason. I don't want to add new data to the player, but rather change the values of the fields that it already has, such as inventory, health, etc. Could I do this with IExtendedEntityProperties?

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.