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

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?

 

  • Author

But does this spawn a new item or does it just select it?

  • Author

Neither this:

 

player.inventory.currentItem = 0;

 

Nor this:

 

player.inventory.changeCurrentItem(0);

 

Appears to be working...

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

 

  • Author

I'm not trying to destroy an item. I'm trying to select a hotbar slot.

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.