Jump to content

[1.15.2] Unable to compare RegistryObject<Item> to Item


NickWrecks

Recommended Posts

I'm trying to model an item after the book and quill. The goal is to open a GUI in which the player can write stuff, and when a button is pressed use NBT to store it. To make things easier on myself I'm limiting it to one page and no signing feature. 

In the packet handler, I'm creating a method (called processEditScroll, obviously a copy of processEditBook from ServerPlayNetHandler) that checks if the item in hand is the scroll (again, like processEditBook). What I believe to be the relevant code is here:

public void processEditScroll(ScrollPacket packetIn) {

    ItemStack itemstack = packetIn.getStack();
    if (!itemstack.isEmpty()) {
        if (MessageScrollItem.isNBTValid(itemstack.getTag())) {
            ItemStack itemstack1 = this.player.getHeldItem(packetIn.getHand());
            if (itemstack.getItem() == ModItems.MESSAGE_SCROLL)

I'm aware I can't compare ItemStacks to Items (since I did try and look into it before posting, and that's the only related problem that pops up) so I use itemstack.getItem. The issue I'm having is that Intellij says 

Quote

Operator '==' cannot be applied to 'net.minecraft.item.Item', 'net.minecraftforge.fml.RegistryObject<net.minecraft.item.Item>

In case it's at all relevant, I'm using the DefferedRegistry system. 

Link to comment
Share on other sites

Have you tried ModItems.MESSAGE_SCROLL.get()?
The method comment for RegistryObject::get is:

Quote

/**

* Directly retrieves the wrapped Registry Object. This value will automatically be updated when the backing registry is updated.

* Will throw NPE if the value is null, use isPresent to check first. Or use any of the other guarded functions.

*/

 

  • Thanks 1

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

Hey, we all have our moments when we need to rubber duck debug.
Sometimes the answer could be staring right at us and we don't notice until someone else points it out. It's a human Feature

Also previously known as eAndPi.

"Pi, is there a station coming up where we can board your train of thought?" -Kronnn

Published Mods: Underworld

Handy links: Vic_'s Forge events Own WIP Tutorials.

Link to comment
Share on other sites

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...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



×
×
  • Create New...

Important Information

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