Inventory - Insert New Item - Returned Object

  • Hey all. So I'm reading the Javadocs and they tell me that the Inventory method insertNewItem() should return null if the new item cannot be added to the player's inventory. However, in my code, the method is returning a non-null item object even when the player's inventory is full and the item gets dropped into the world. Hoping I've missed something obvious and one of you might spot it. Any help would be appreciated.

  • Oh, this is unfortunately a bug :wat: If the item couldn't be added due to a full inventory, the game still returns the unused item instance (which is quite useless)... that's not intended...


    But I'm afraid there isn't even a proper workaround available :silenced: You could check if the newly returned item instance exists in inventory (I've posted an example below), however, that does not work in case of stackable items (if the item was added to an existing stack)... so this solution only works reliably for non-stackable items (e.g. tools, weapons etc).


Participate now!

Don’t have an account yet? Create a new account now and be part of our community!