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

When the player right-clicks my custom block, I want the a single item from the stack to be removed from the players inventory, i.e. if the player has 50 of an item it goes down to 49.

I can easily add items to the players inventory use player.addItemStackToInventory but can't seem to find something similar for removing an item. I thought player.entityDropItem might work but that doesn't seem to work; my block also knows what item was used on right-click.

 

Any help is appreciated.

Edited by Blu_Nighttime
topic solved

  • Author

OK, I have this implemented now; thanks for the redirection from the old API. However, how do I get the slot number that the ItemStack is at? I see get slots but that just returns the number of slots available so is there another way?

 

Cheers.

  • Author

Actually, I thought i had it working but turns out when I right-clicked my block, the game crashed. I add this line

IItemHandler inv = (IItemHandler) player.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)

but I don't think this is right, any pointers on this one?

And PlayerInventory#currentItem is what I was looking for.

 

Thanks.

  • Author

Thanks, I messed around this this and never got it to work how I wanted it too.

So I just used player.inventory.decrStackSize() and used currentItem() and the value of 1 which did what I needed.

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.