Jump to content

Sheker

Members
  • Posts

    2
  • Joined

  • Last visited

Everything posted by Sheker

  1. 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.
  2. @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"); } } }
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.