Posted August 17, 201411 yr Hello, I have written a small Item that stores the UUID of the player that only this player can use it, but now I want that instead of the UUID the player name will be shown, so that every other player knows "Ok, this isn't my item". So is there a way to get the Player name by the UUID and to update it if the player name was changed? I want to use the addInformation method for that. Bektor "NEW" PROBLEM: look a bit down or use that link http://www.minecraftforge.net/forum/index.php?action=post;quote=114249;topic=22491.0;last_msg=114249 Developer of Primeval Forest.
August 17, 201411 yr How about store the UUID and player name when the ownership is given and at some point check to see if the UUID is the same, but username isn't. If the two names are different and UUIDs are the same, then change the name then. And the addInformation is good for this stuff. Just make sure the NBT exists in the ItemStack. -Mitchellbrine Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible. It may be freaking fucking hard though, but still possible If you create a topic on Modder Support, live by this motto: I don't want your charity, I want your information
August 17, 201411 yr Author Ok. I did this, but something is wrong: It says that this items didn't belong to me, but it is my item and it won't send the right chat message (only the path where I can find it in the language file...). So here is the code: /** * Called whenever this item is equipped and the right mouse button is pressed. Args: itemStack, world, entityPlayer */ @Override public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player) { if(world.isRemote) return itemStack; if(!itemStack.hasTagCompound()) itemStack.setTagCompound(new NBTTagCompound()); NBTTagCompound nbttagcompound = itemStack.getTagCompound(); NBTTagString nbttagstring = (NBTTagString)nbttagcompound.getTag("author"); NBTTagString nbtnamestring = (NBTTagString)nbttagcompound.getTag("name"); if(nbttagstring == null) itemStack.setTagInfo("author", new NBTTagString(player.getUniqueID().toString())); if(nbtnamestring == null) itemStack.setTagInfo("name", new NBTTagString("Hallo")); // for testing it // TODO: player.getDisplayName() if(nbttagstring != null && nbtnamestring != null) { if(!nbttagstring.equals(player.getUniqueID().toString())) { if(!world.isRemote) player.addChatComponentMessage(new ChatComponentTranslation("msg.wrong_player.txt")); } else { if(!nbtnamestring.equals(player.getDisplayName())) itemStack.setTagInfo("name", new NBTTagString(player.getDisplayName())); player.openGui(PrimevalForest.instance, EnumGUI.QUESTLOG.getID(), world, (int)player.posX, (int)player.posY, (int)player.posZ); } } return itemStack; } /** * Called when item is crafted/smelted. */ @Override public void onCreated(ItemStack itemStack, World world, EntityPlayer player) { super.onCreated(itemStack, world, player); if(!itemStack.hasTagCompound()) itemStack.setTagCompound(new NBTTagCompound()); NBTTagCompound nbttagcompound = itemStack.getTagCompound(); NBTTagString nbttagstring = (NBTTagString)nbttagcompound.getTag("author"); NBTTagString nbtnamestring = (NBTTagString)nbttagcompound.getTag("name"); if(nbttagstring == null) itemStack.setTagInfo("author", new NBTTagString(player.getUniqueID().toString())); if(nbtnamestring == null) itemStack.setTagInfo("name", new NBTTagString(player.getDisplayName())); } /** * allows items to add custom lines of information to the mouseover description */ @Override @SuppressWarnings({ "rawtypes", "unchecked" }) public void addInformation(ItemStack itemStack, EntityPlayer player, List list, boolean par4) { if(itemStack.hasTagCompound()) { NBTTagCompound nbttagcompound = itemStack.getTagCompound(); NBTTagString nbtnamestring = (NBTTagString)nbttagcompound.getTag("name"); if(nbtnamestring != null) list.add(EnumChatFormatting.GOLD + String.format("Owner: " + nbtnamestring)); else list.add(EnumChatFormatting.RED + String.format("No Owner!")); } } So what is there wrong? Bektor Developer of Primeval Forest.
August 18, 201411 yr Author Ok. I found something out. If I let write Minecraft my UUID and the UUID of the NBTTagString in the Chat then this happens: UUID "UUID" (Well, I replaced the UUID with the word UUID here...) But if I fix this then, then it says that this isn't my item, too: "UUID" "UUID" I tested it with nbttagstring.toString() != player.getUniqueID().toString() -> if this is true, then it says me, that this item is not yours. And I tested it with nbttagstring.equals(player.getUniqueID) and then I tested both on a way that the output is "UUID" so because NBTTagString saves it with "" (I'm don't know the english word for " ) and inside of "" its putting the UUID, so I tried it by checking that it add " before and after the player.getUniqueID() so that the chat output is the same, but for an unknown reason it returns everytime true, so everytime it thinks that I'm not the owner of the item that I'm the owner from. And the second problem is, that the method player.addChatComponentMessage(new ChatComponentTranslation("msg.wrong_player.txt")); will always return msg.wrong_player.txt instead of the chat message that I put in the language file. So whats wrong. Bektor Developer of Primeval Forest.
August 18, 201411 yr player.getUniqueID() is not what you think it is. Use player.getGameProfile().getId(); That will always stay the same. -Mitchellbrine Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible. It may be freaking fucking hard though, but still possible If you create a topic on Modder Support, live by this motto: I don't want your charity, I want your information
August 18, 201411 yr getUniqueID is per session or per world (not sure what exactly), it is for every entity and isn't actually UUID. I believe it gets reset after respawn (also not sure). what you want is getGameProfile().getId().toString() (UUID is a class)
August 19, 201411 yr Right, toString()! Forgot about that. What he said is correct, Bektor. Do not use getUniqueID() or getPersistentID() because they are per session (or world, I can't figure it out either). -Mitchellbrine Minecraft can do ANYTHING, it's coded in Java and you got the full power of Java behind you when you code. So nothing is impossible. It may be freaking fucking hard though, but still possible If you create a topic on Modder Support, live by this motto: I don't want your charity, I want your information
August 19, 201411 yr Author Ok, thanks, but this won't fix the problem. It says still that it's not my item. Oh and player.getDisplayName() is right, or need I to use player.getGameProfile().getName() ? Developer of Primeval Forest.
August 19, 201411 yr Author Ok. I fixed it with nbttagstring.toString().equals("\"" + getGameProfile().getId().toString() + "\""); Developer of Primeval Forest.
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.