Posted June 1, 20178 yr I'm having trouble comparing the name and lore of an item to a name and lore that I specify. Here is some code that demonstrates my issue: public static final String NAME = TextFormatting.LIGHT_PURPLE + "Magic"; public NBTTagList lore = new NBTTagList(); lore.appendTag(new NBTTagString(TextFormatting.DARK_PURPLE + "This does magic stuff!")); lore.appendTag(new NBTTagString(TextFormatting.RED + "Magic stuff is magical.")); public ItemStack itemStack = // some ItemStack that has a display name of NAME and a lore of lore public NBTTagList getLore(ItemStack itemStack) { NBTTagCompound nbt = itemStack.getTagCompound(); if (nbt != null) { NBTTagCompound display = nbt.getCompoundTag("display"); if (display != null) { NBTTagList lore = display.getTagList("Lore", 8); if (lore != null) { return lore; } } } return new NBTTagList(); } public boolean displayNamesEqual = itemStack.getDisplayName() == NAME; public boolean loresEqual = getLore(itemStack).toString() == lore.toString(); // displayNamesEqual and loresEqual both evaluate to false Does it have to do something with the color/style of this information? Edited June 5, 20178 yr by Draconwolver
June 1, 20178 yr Author 43 minutes ago, Jay Avery said: Where do you set the NBT of the stack you're checking? I don't. I check the NBT of the item I'm currently holding at certain times.
June 1, 20178 yr 7 hours ago, Draconwolver said: I don't. I check the NBT of the item I'm currently holding at certain times. Well, if you've never set the NBT then it's never going to be equal to the condition you're checking for. It won't set itself to the exact text you want unless you tell it to. You're also using the == operator which checks for object identity. So unless you are checking references to the exact same object, they will return false even if they seem to be the same. Instead you should use equals or an equivalent method to check for matching content. Edited June 1, 20178 yr by Jay Avery
June 1, 20178 yr Author 8 hours ago, Jay Avery said: Well, if you've never set the NBT then it's never going to be equal to the condition you're checking for. It won't set itself to the exact text you want unless you tell it to. You're also using the == operator which checks for object identity. So unless you are checking references to the exact same object, they will return false even if they seem to be the same. Instead you should use equals or an equivalent method to check for matching content. Thank you, the equals method worked perfectly for both the display name and lore.
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.