Jump to content

Recommended Posts

Posted

I was wonder how to store some data about players. Stuff like research. I thought about NBT but it what I did didn't work so I scraped it. I also tried something involving IExtendedEntityProperties. I read about the fact you can use it with an entity but it totally failed. Then I did player.getEntityData() but same thing happened.

:( I think the way to do it would be the NBT but I'm not sure how to store the completed research in every player individually.

 

Thanks for any help. ;)

If I helped then you help, hit that Thank You button or Applaud.

Posted

Thanks for the fast answer. ;)

I'll try it and post the code I get for others.

If I helped then you help, hit that Thank You button or Applaud.

Posted

NBT is a data format. Your wording is basically "How do I store information onto a harddisc? As a word document?"

 

I wasn't how to do it so the player data is different for all the players, I don't want them to share the research.

If I helped then you help, hit that Thank You button or Applaud.

Posted

I read a little about it and I think I got it... Didn't test it yet because I don't have anything triggering it. Here is my code. I f I did anything wrong feel free to point it out.

 

public class PlayerResearch implements IExtendedEntityProperties
{
public final static String EXT_PROP_NAME = "PlayerResearch";

private final EntityPlayer player;

public int[] CurrentResearch = { 0, 0, 0, 0, 0};

public PlayerResearch(EntityPlayer player)
{
	this.player = player;
}

public static final void register(EntityPlayer player)
{
	player.registerExtendedProperties(PlayerResearch.EXT_PROP_NAME, new PlayerResearch(player));
}

public static final PlayerResearch get(EntityPlayer player)
{
return (PlayerResearch)player.getExtendedProperties(EXT_PROP_NAME);
}

public void saveNBTData(NBTTagCompound nbt)
{
	NBTTagCompound research = new NBTTagCompound();

	research.setInteger("Research1", CurrentResearch[0]);
	research.setInteger("Research2", CurrentResearch[1]);
	research.setInteger("Research3", CurrentResearch[2]);
	research.setInteger("Research4", CurrentResearch[3]);
	research.setInteger("Research5", CurrentResearch[4]);
	System.out.print("Key Presses");

	nbt.setTag(EXT_PROP_NAME, research);
}

public void loadNBTData(NBTTagCompound nbt)
{
	NBTTagCompound research = (NBTTagCompound) nbt.getTag(EXT_PROP_NAME);

	CurrentResearch[0] = research.getInteger("Research1");
	CurrentResearch[1] = research.getInteger("Research2");
	CurrentResearch[2] = research.getInteger("Research3");
	CurrentResearch[3] = research.getInteger("Research4");
	CurrentResearch[4] = research.getInteger("Research5");

	System.out.println(research.getInteger("Research1"));
}

public void init(Entity entity, World world)
{

}
}

If I helped then you help, hit that Thank You button or Applaud.

Posted

First problem: PlayerResearch has to be registered for your player with player.registerExtendedEntityProperties(EXT_PROP_NAME,this);

 

You could do the same more nicely (since your research is an array of ints), by using new NBTTagIntArray(currentResearch).

 

Also, CurrentResearch is not a class, so should not be UpperCamelCase.

Posted

I'm not sure if this is the right place to post this, sorry if it's not. It's just that it has something to do with this post.

I was going to fix all that now but my Eclipse sort of messed up. :(

Last time I saved my work and just closed it, this morning when I tired to run Eclipse,

It was constantly giving a me an error. Something to do with the workspace not loading and my code didn't appear. I reinstalled Eclipse, the code was all there but I got a different error:

eclipse.buildId=4.3.2.M20140221-1700
java.version=1.8.0
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=pl_PL
Framework arguments:  -product org.eclipse.epp.package.standard.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.standard.product

Error
Sun May 25 12:10:22 BST 2014
Unable to find Action Set: org.eclipse.rse.core.search.searchActionSet

eclipse.buildId=4.3.2.M20140221-1700
java.version=1.8.0
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=pl_PL
Framework arguments:  -product org.eclipse.epp.package.standard.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.standard.product

Error
Sun May 25 12:10:22 BST 2014
Unable to find Action Set: org.eclipse.mylyn.tasks.ui.navigation

eclipse.buildId=4.3.2.M20140221-1700
java.version=1.8.0
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=pl_PL
Framework arguments:  -product org.eclipse.epp.package.standard.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.standard.product

Error
Sun May 25 12:10:22 BST 2014
Unable to find Action Set: org.eclipse.mylyn.doc.actionSet

eclipse.buildId=4.3.2.M20140221-1700
java.version=1.8.0
java.vendor=Oracle Corporation
BootLoader constants: OS=win32, ARCH=x86_64, WS=win32, NL=pl_PL
Framework arguments:  -product org.eclipse.epp.package.standard.product
Command-line arguments:  -os win32 -ws win32 -arch x86_64 -product org.eclipse.epp.package.standard.product

Error
Sun May 25 12:10:22 BST 2014
Unable to find Action Set: org.eclipse.mylyn.context.ui.actionSet

When I try to do something like

research and I try to put a dot there, nothing is appearing.

If I helped then you help, hit that Thank You button or Applaud.

  • 2 weeks later...
Posted

First problem: PlayerResearch has to be registered for your player with player.registerExtendedEntityProperties(EXT_PROP_NAME,this);

 

You could do the same more nicely (since your research is an array of ints), by using new NBTTagIntArray(currentResearch).

 

Also, CurrentResearch is not a class, so should not be UpperCamelCase.

 

I fixed my problem so I could get back into modding, I register it in EventHandler like this:

package bulkyzanka.electro.mod.handler;

import bulkyzanka.electro.mod.research.PlayerResearch;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.event.entity.EntityEvent.EntityConstructing;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;

public class ElectroEventHandler
{
@SubscribeEvent
public void onEntityConstructing(EntityConstructing event)
{
	if(event.entity instanceof EntityPlayer && PlayerResearch.get((EntityPlayer) event.entity) == null)
	{
		PlayerResearch.register((EntityPlayer) event.entity);
	}

	if (event.entity instanceof EntityPlayer && event.entity.getExtendedProperties(PlayerResearch.EXT_PROP_NAME) == null)
	{
		event.entity.registerExtendedProperties(PlayerResearch.EXT_PROP_NAME, new PlayerResearch((EntityPlayer) event.entity));
	}
}
}

But for the player.registerExtendedEntityProperties(EXT_PROP_NAME,this);

Where do I register that? I'm guessing it's in that class because of the "this". Should I put it in init?

ABout the other little mistakes, I fixed them. ;)

If I helped then you help, hit that Thank You button or Applaud.

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

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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