Jump to content

Bypassing isUsableByPlayer and canInterractWith


vroominator

Recommended Posts

I'm making an Item that allows the user to interract with any block remotely. It does this by calling onBlockActivated on the block whose data is stored in the NBT Tag Compound of the Item. This works fine for blocks like the lever and the door, who have no Container or Tile Entity, but for blocks like the Furnace or the Crafting Table, it only works when the user is within 5 or so blocks of the linked block. The GUI of the associated block shows for a split second, and then closes again, and I'm pretty sure this is because of isUsableByPlayer and/or canInterractWith returning false because the player is not close enough. Is there any way to bypass this, or am I going to have to scrap this Item?

Link to comment
Share on other sites

inside the container class you need to change

@Override
        public boolean canInteractWith(EntityPlayer player) {
                return tileEntity.isUseableByPlayer(player);
        }

to

@Override
        public boolean canInteractWith(EntityPlayer player) {
                if(player.getCurrentEquippedItem()==new ItemStack(Mod.item))return true;
                return tileEntity.isUseableByPlayer(player);
        }

The Korecraft Mod

Link to comment
Share on other sites

Okay, so I did a little digging around in the code, and the responsible line of code is line 330 of EntityPlayer.

if (!this.worldObj.isRemote && this.openContainer != null && !this.openContainer.canInteractWith(this))

This statement causes the current GuiScreen to close if canInteractWith in the open container returns false, so I'm guessing this means there's no workaround at all. I suppose I could do a Pull Request and add a hook in there to cancel the Gui being closed.

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.