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 give the player items the first time they join the world.

 

So I check a boolean in the player nbt, if it's false I check if their username contains one of several specific words and if it does it gives them some special items and enables some other aesthetic features, then set it to true.

 

And at first glance it works perfectly. I log in to a new world, get the items, log out and when I log back it it recognises that I already got them.

 

Unfortunately, if I log out after I die it's undone and it gives me new items the next time I log back in.

 

I assume this is because the player gets a new nbt on respawn?

 

I'm specifically trying to do this WITHOUT using IExtendedEntityProperties because I cannot get that to work no matter which tutorial I try, for what ever reason. How can I get it to stay through death without using IEEP?

 

@SubscribeEvent
public void login(PlayerLoggedInEvent event)
{
	EntityPlayer player = event.player;
	NBTTagCompound entityData = player.getEntityData();

	if (event.player.dimension == 0)
	{
		if (entityData.getBoolean(Infinity.MODID + "." + "RecievedItems") == false)
		{
			if (Tools.hasRelatedName(player))
			{
				player.inventory.addItemStackToInventory(new ItemStack(Content.dream_sword));
				player.addChatMessage(
						new ChatComponentText(EnumChatFormatting.GOLD + "You got a Keychain and the Dream Sword!"));
				player.inventory.addItemStackToInventory(new ItemStack(Content.keychain));

				entityData.setBoolean(Infinity.MODID + "." + "RecievedItems", true);
			}
			else
			{
				player.addChatMessage(new ChatComponentText(EnumChatFormatting.LIGHT_PURPLE + "[" + Infinity.NAME + "]"
						+ EnumChatFormatting.RESET + "There's nothing special for you today."));
			}
		}
	}
}

The compound tag returned by

Entity#getEntityData

is persisted through saves, but it's not copied when the player respawns (

EntityPlayer#clonePlayer

). Only the data in the

EntityPlayer.PERSISTED_NBT_TAG

sub-compound of

Entity#getEntityData

is copied over when the player respawns.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

  • Author

Okay, so how would I save it in that?

 

I tried setting

	NBTTagCompound entityData = player.getEntityData();

 

to

 

	NBTTagCompound entityData = player.getEntityData().getCompoundTag(EntityPlayer.PERSISTED_NBT_TAG);

 

And it just gives the player items on every single login now.

I have no idea how to actually use that.

That should work. If you look at the player's NBT data after login at runtime or in the save, is your key present?

 

Post your new code on Gist or Pastebin with syntax highlighting and link it here.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

If there's no compound tag at the specified key,

NBTTagCompound#getCompoundTag

will return a new one; but this new tag won't be added to the parent tag's map so you need to do this manually.

 

I've written a basic example of this for 1.8.9 here. It should be mostly the same in earlier versions.

Please don't PM me to ask for help. Asking your question in a public thread preserves it for people who are having the same problem in the future.

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.