pmmp / PocketMine-MP

A server software for Minecraft: Bedrock Edition in PHP

Home Page:https://pmmp.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

A system to let transactions decide what stuff can go into a particular inventory slot

dktapps opened this issue · comments

Description

This was previously attempted in #4479, but that implementation is limited and has gone stale.

When I originally thought about this, my idea was to have a separate InventorySlotAcceptor unit which would enforce requirements like this, avoiding circular dependencies or needing custom inventory classes, as well as being more flexible.

It would have a method something like

function accept(Inventory $inventory, Item $item) : bool

where the return value would indicate whether the item can be put into that slot or not.

Maybe it can even just be done with an Inventory::getSlotAcceptors() : ObjectSet<Closure(Inventory, Item) : bool> instead.

A system like this would allow any Inventory to receive new acceptors at any time, allowing plugins to introduce their own logic and potentially override builtin logic.

Justification

Slots for armour and offhand aren't currently validated.

Alternative methods