Jump to content

Checking if a NBT integer exists?


TLHPoE

Recommended Posts

I thought hasKey would work, but apparently not. I have my code setup inside of a player tick handler, and it constantly spams "HI1" in the console.

 

public static void playerTick(EntityPlayer player)
{

	String playerName = player.username;
	NBTTagCompound worldNBT = player.worldObj.getWorldInfo().getNBTTagCompound();

	if(!worldNBT.hasKey(playerName + "Gold"))
	{

		GloriaRPG.print("HI1");

		worldNBT.setInteger(playerName + "Gold", 0);

	}

Kain

Link to comment
Share on other sites

These values are only saved on the server. The console chat is sent from the client. what if you added !player.worldObj.isRemote to your if() statement? Would it stop then?

Author of PneumaticCraft, MineChess, Minesweeper Mod and Sokoban Mod. Visit www.minemaarten.com to take a look at them.

Link to comment
Share on other sites

Hi

 

I had a quick look into getNBTTagCompound, which calls updateTagCompound, and it looks to me like it creates it a new one each time and fills it with values stored in WorldInfo.  So you can add a key but it just gets thrown away at the end of your PlayerTick.

 

Why do you want to store something in WorldInfo?

Depending on what you want to do, .getAdditionalProperty and .setAdditionalProperty might be what you're looking for?

 

-TGG

Link to comment
Share on other sites

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.



×
×
  • Create New...

Important Information

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