Posted November 24, 20177 yr Here's a few problems I've ran into. 1. I have a piece of code which checks if a stack has a specific key every tick. However, the NBTTagCompoud#hasKey method seems to be functioning incorrectly. I've debugged it and it looks like it always returns false. public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) { if(!world.isRemote) { NBTTagCompound nbt = stack.hasTagCompound() ? stack.getTagCompound() : new NBTTagCompound(); System.out.println(nbt.getUniqueId("Identifier")); if(!nbt.hasKey("Identifier")) { nbt.setUniqueId("Identifier", UUID.randomUUID()); stack.setTagCompound(nbt); } } } 2. From what I've heard NBT is handled on the server side only. How would I add a string from an item's NBT to its lore? Trying to retrieve tags on the client side in Item#addInformation always returns null. 3. In what case would I want to use capabilities instead of item NBT? Edited November 24, 20177 yr by Melonslise
November 25, 20177 yr 8 hours ago, Melonslise said: 1. I have a piece of code which checks if a stack has a specific key every tick. However, the NBTTagCompoud#hasKey method seems to be functioning incorrectly. I've debugged it and it looks like it always returns false. If you look at the implementation of NBTTagCompound#setUniqueId, you'll see that it doesn't use the key you give it directly; it uses two different keys based on it. This means that NBTTagCompound#hasKey will never return true for the key you passed to NBTTagCompound#setUniqueId, you need to use NBTTagCompound#hasUniqueId instead. 8 hours ago, Melonslise said: 2. From what I've heard NBT is handled on the server side only. How would I add a string from an item's NBT to its lore? Trying to retrieve tags on the client side in Item#addInformation always returns null. ItemStack NBT is automatically synced to the client. If you're setting on the server but can't access it from Item#addInformation, you're doing something wrong. Post your code. 8 hours ago, Melonslise said: 3. In what case would I want to use capabilities instead of item NBT? To create your own API or implement an existing one like IItemHandler/IFluidHandler; or to store data without having to serialise it to/deserialise it from NBT every time you want to access/modify it. 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.
November 25, 20177 yr Author Thanks a lot! For some reason I automatically thought a UUID would be stored just like any other data type. Thanks for clearing things up, everything works now. Edited November 25, 20177 yr by Melonslise
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.