Posted January 27, 20169 yr 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.")); } } } }
January 27, 20169 yr 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.
January 29, 20169 yr 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.
January 30, 20169 yr 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.
January 30, 20169 yr 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.