Jump to content
View in the app

A better way to browse. Learn more.

Forge Forums

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Featured Replies

Posted

So previously on 1.16.5 I was using the ItemHandler Capability to read and write the nbt data for the sharetags. But in 1.18.2 Forge doesn't have those methods anymore so I simply copied it in. Obviously, it doesn't work since when I try to get the contents of the itemhandler in my item so that I can render the item on the screen and the stack size, the contained itemstacks don't update until I open the item's inventory. So how can I update the item on the client whenever the itemhandler has changes?

I need to get the inventory in BulletCountRender.java and BulletRadialMenu.java

Item Class: AbstractPouch.java

@Override
    public void readShareTag(ItemStack stack, @Nullable CompoundTag nbt) {
        super.readShareTag(stack, nbt);
        LazyOptional<IItemHandler> optional = AbstractPouch.getData(stack).getOptional();
        if (optional.isPresent()){
            IItemHandler handler = optional.resolve().get();
            if (!(handler instanceof IItemHandlerModifiable))
                throw new RuntimeException("IItemHandler instance does not implement IItemHandlerModifiable");
            IItemHandlerModifiable itemHandlerModifiable = (IItemHandlerModifiable) handler;
            ListTag tagList = nbt.getList("ClientInventory", Tag.TAG_COMPOUND);
            for (int i = 0; i < tagList.size(); i++)
            {
                CompoundTag itemTags = tagList.getCompound(i);
                int j = itemTags.getInt("Slot");

                if (j >= 0 && j < handler.getSlots())
                {
                    itemHandlerModifiable.setStackInSlot(j, ItemStack.of(itemTags));
                }
            }
        }
    }

    @Nullable
    @Override
    public CompoundTag getShareTag(ItemStack stack) {
        LazyOptional<IItemHandler> optional = AbstractPouch.getData(stack).getOptional();
        CompoundTag tag = super.getShareTag(stack);
        if (optional.isPresent()){
            IItemHandler handler = optional.resolve().get();
            ListTag nbtTagList = new ListTag();
            int size = handler.getSlots();
            for (int i = 0; i < size; i++)
            {
                ItemStack stack1 = handler.getStackInSlot(i);
                if (!stack1.isEmpty())
                {
                    CompoundTag itemTag = new CompoundTag();
                    itemTag.putInt("Slot", i);
                    stack1.save(itemTag);
                    nbtTagList.add(itemTag);
                }
            }
            tag.put("ClientInventory", nbtTagList);
        }

        return tag;
    }

Edited by NindyBun

  • Author

Right, so I just used a few packets to save the inventory as a Listtag to the item and I just use that instead since nbt data is always synced. It's a very crude way but it works for now.

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.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

Important Information

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

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.