Creating an Inventory that you can withdraw items from, but not deposit items to

Hello Everyone!

So I have a bit of a puzzle for you all that I’ve been trying to solve. I’ve been trying to create a custom chest inventory that allows you to withdraw items from it, but not place items into it. I can listen to InteractInventoryEvent and from that get the cursor transaction. However I’m stuck in determining if this is a transaction taking and item from the top half of the inventory (the chest) and depositing it in the bottom half of the inventory (the player) and thus should be allowed, or if it’s the reverse and should be canceled. Any ideas or insight you all could provided would be greatly appreaciated! :smile:

How i would do it is get the affected slots. That should give you a list of Slot that well … Were effected. I.E the item original position and the items placement (as well as other slots that may have been affected).

After that you will need to filter out the slots your not interested in. I dont know enough about the affected slots to know of an algorthum here. But you just need to take a look at what slots were affected and how (it could just be that the slot it was taken from and the slot that it was placed at are the last 2 slots in the list).

After that you need to determine the position of the slots. You can do this by getting the players Inventory (without the chest inventory attached) and then filtering though the inventories slots until one matches.

Another way to do this part would be to check the slots for the affected item

After that you have 2 slots, one is in the players Inventory the other isnt (all other combination your not interested in). You also have the order that the slots came in (the affected slots list).

So just compare the player inventory slot with the first slot in that list. If that slot is the player inventory slot then it came from the players inventory, so cancel. If not then dont cancel.