Jump to content

Selecting a hotbar slot


ipsq

Recommended Posts

I'm trying to select a hotbar slot with a certain item in it by first grabbing the inventory and scanning through the list of items to find a match. If I find a match, I want to select this slot but this is where I'm stuck. I can't find any method in the Inventory or Player API that let's me do that. Is this possible or did I overlook something?

 

Link to comment
Share on other sites

I take it you want to destroy the current item as you're trying to set it to null?

 

Isn't it more efficient to call the following instead of messing around with changeCurrentItem?

 

YourcurrentEntityPlayerObject.destroyCurrentEquippedItem();

 

or

 

YourcurrentEntityPlayerObject.inventory.getCurrentItem()

 

it returns an itemstack. Otherwise you have to append '.getItem()' behind it.

 

Furthermore you can swap items with

 

YourcurrentEntityPlayerObject.inventory.setInventorySlotContents(current item, new itemstack of item you want to place there);

 

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.