Jump to content

Recommended Posts

Posted

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?

 

Posted

Neither this:

 

player.inventory.currentItem = 0;

 

Nor this:

 

player.inventory.changeCurrentItem(0);

 

Appears to be working...

Posted

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);

 

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.