Jump to content

[Solved] Saving data about a player


NuclearFej

Recommended Posts

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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");

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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

Announcements



×
×
  • Create New...

Important Information

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