Blu_Nighttime Posted September 9, 2019 Share Posted September 9, 2019 (edited) 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 September 15, 2019 by Blu_Nighttime topic solved Quote Link to comment Share on other sites More sharing options...
Blu_Nighttime Posted September 10, 2019 Author Share Posted September 10, 2019 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. Quote Link to comment Share on other sites More sharing options...
Blu_Nighttime Posted September 10, 2019 Author Share Posted September 10, 2019 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. Quote Link to comment Share on other sites More sharing options...
Blu_Nighttime Posted September 15, 2019 Author Share Posted September 15, 2019 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.