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

How can you save data about a player?

 

For example, money.

 

I assume this would be done through NBTTagCompound but I can't find anything relevant about saving tags to players.

 

Thanks!

 

(Saving data to an external text file or the like would work as well, if that is possible.)

Take a look at the IExtendedEntityProperties file which can be found inside the "minecraftforge.common" package or by pressing CTRL+SHIFT+T(in eclipse) and use the "Open Type" window to find it by entering IExtendedEntityProperties into the box.

 

Then take a look at the bottom of Entity.java inside "net.minecraft.entity" package.

The two last methods there are dealing with the extended properties.

 

I haven't seen it before now but it seems quite awesome,

Thanks diesieben07!:)

 

If you guys dont get it.. then well ya.. try harder...

  • Author

Can you give an example, if possible? It's still unclear exactly what I need to extend/override.

 

Thanks!

  • Author

How does this look to you guys?

 

Thanks for all the help!

 

import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;

public class DataSaver extends TileEntity implements IExtendedEntityProperties {

String testString = "";

@Override
public void saveNBTData(NBTTagCompound compound) {

	super.writeToNBT(compound);
	compound.setString("test01", testString);

}

@Override
public void loadNBTData(NBTTagCompound compound) {
	super.readFromNBT(compound);
	testString = compound.getString("test01");
	System.out.println(testString + " loaded.");

}

@Override
public void init(Entity entity, World world) {

}

public void writeString(String par1)
{
	testString = par1;
}

public String getString()
{
	return testString;
}

}

 

and when I need to access or save data...

 

((DataSaver)player.getExtendedProperties("FejProperties")).writeString("xyz");

For note these are new features that I have not reviewed fully as I have been out of town.

I can however tell you for a fact that these things WILL be changed when I get back from Sakuracon as they need cleaning. However, there has been the basic functionality to tag any entity with extra NBT info for a long, long time. So just use that.

I do Forge for free, however the servers to run it arn't free, so anything is appreciated.
Consider supporting the team on Patreon

  • Author

Much better question:

 

I assume I cannot attach a TileEntity to a player, as TileEntities have a fixed position in the world. So, then, I need to attach the NBTs to something else. What can I attach them to in order to have them attached to the player, and what method can I use to get the object from a EntityPlayer?

 

This is assuming I don't use IExtendedEntityProperties.

And when the TE is unloaded? Better off storing and writing to a custom nbt file. Just use event a packets and commands to tell where and when to send it

I think its my java of the variables.

  • Author

How do you write to a custom NBT file? I can't find anything even similar to a filename in the NBT code. I'm probably missing something xD

 

 

  • Author

Wow. That was so easy, especially compared to the IExtendedEntityProperties! Thank you so much!

 

I think I'll write a tutorial about it as well, as long as that kind of thing is wanted by the community.

  • 6 years later...
On 3/29/2013 at 10:17 AM, NuclearFej said:

Wow. That was so easy, especially compared to the IExtendedEntityProperties! Thank you so much!

 

I think I'll write a tutorial about it as well, as long as that kind of thing is wanted by the community.

 

 

Can You please tell me how can i store data for entity before spawning them and after that access that data from another class where the same entity has given as argument in method...

the topic is 7 years old... either everything here is useless or you need to update. If you are on a supported version, create a new topic

  • Guest locked this topic
Guest
This topic is now closed to further replies.

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.