Sheker Posted July 13, 2019 Share Posted July 13, 2019 @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, @Nullable World worldIn, java.util.List<String> tooltip, ITooltipFlag flagIn) { super.addInformation(stack, worldIn, (java.util.List<String>) tooltip, flagIn); IItemHandler itemHandler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); for (int i = 0; i < itemHandler.getSlots() - 1; i++) { ItemStack displayedStack = itemHandler.getStackInSlot(i); if (!displayedStack.isEmpty() && displayedStack.getItem() != Item.getItemFromBlock(Blocks.AIR)) { tooltip.add(TextFormatting.GRAY + displayedStack.getDisplayName()); } } } Hi everyone, I have an item that opens its contents on right-click. I've been trying to have a tooltip similar to how Shulker Boxes have a tooltip listing all its contents. It's close to how I want it to work on singleplayer, but the tooltip only updates when I right-click and open up the item GUI again. I also have the problem of not being able to see the tooltip on a server. I've looked around and the closest solution I've found is to override getNBTShareTag(), but I have no idea where to start and how it works as none of my data seems to be saved. Here is my code for my attempt to utilise getNBTShareTag to solve the problem: @Override public NBTTagCompound getNBTShareTag(ItemStack stack) { IItemHandler handler = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); NBTBase capTag = CapabilityItemHandler.ITEM_HANDLER_CAPABILITY.getStorage().writeNBT(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, handler, null); NBTTagCompound tag = stack.getTagCompound(); if (tag == null) { tag = new NBTTagCompound(); } if (capTag != null) { tag.setTag("GemInventory", capTag); } return tag; } @SideOnly(Side.CLIENT) public void addInformation(ItemStack stack, @Nullable World worldIn, java.util.List<String> tooltip, ITooltipFlag flagIn) { super.addInformation(stack, worldIn, (java.util.List<String>) tooltip, flagIn); if (!stack.hasTagCompound()) { stack.setTagCompound(new NBTTagCompound()); } NBTTagCompound itemTagCompound = stack.getTagCompound(); NBTTagList list = itemTagCompound.getTagList("GemInventory", 10);; for (int i = 0; i < list.tagCount(); i++) { ItemStack slotStack = new ItemStack(list.getCompoundTagAt(i)); if (!slotStack.isEmpty()) { tooltip.add("Test"); } } } Quote Link to comment Share on other sites More sharing options...
Sheker Posted July 14, 2019 Author Share Posted July 14, 2019 Thank you for your help, it ended up working. Did an override on readNBTShareTag where it wrote all NBT data to the handler's slots, and now the tooltip works immediately on servers. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.