-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Inventory rework #6533
base: major-next
Are you sure you want to change the base?
Inventory rework #6533
Conversation
this allows this functionality to be used with any type of inventory, and also makes it a little nicer to use in many cases.
we want viewers to be as close to decorative as possible, so that they provide useful information to plugins, but don't get in the way of other changes.
this unblocks a variety of changes, such as positionless tiles, enhanced APIs on Blocks for inventories, and also eliminates a bunch of cyclic references within the core code. linked to #5033
9c5df90
…tories it already needs to locate the correct pair anyway to know the left/right for DoubleChestInventoryWindow, so we might as well use this logic for initializing the DoubleChestInventory itself too. The old logic in tile/Chest didn't work correctly.
this is *probably* fine, but best avoided.
…y of AnimatedContainer interface this allows getting rid of several container window classes. we should probably look into adding more info to the BlockInventoryWindow to make the type easier to identify, though. now that holder is tracked by an ephemeral window, we can put whatever we like in there.
this really needs a shorter name
I have no real problem with the current implementation. It seems fine to me and is a first step towards a better inventory system. Another follow-up I would suggest concerns the viewers of the inventory. I can see the point of including viewers in this system but I still have a sticking point because we're including a reference to the player in the inventory interface. Wouldn't it be good after this to think of a system where we have classes that only contain storage logic / listeners and that's it ? |
Yeah, that's the ideal world. Unfortunately we need the Inventory to still track the viewers so that plugins can see all the viewers of an inventory, and also so that the inventory menus get closed when a block is deleted. I don't see another obvious solution to this problem. We could pull the viewer list out of |
Few issues remain with the PR:
|
This PR breaks the cyclic dependency between
Inventory
and its holder, which unblocks a lot of new developments.Related issues & PRs
Fixes #5033
Opens the gates for #6147 (which in turn means that async tasks will eventually be able to work with tiles)
Changes
API changes
Player->getCurrentWindow()
now returns?InventoryWindow
instead of?Inventory
Player->setCurrentWindow()
now accepts?InventoryWindow
instead of?Inventory
InventoryWindow
introduced, which is created for each player viewing the inventory, provides decorative information like holder info forInventoryTransactionEvent
, and is destroyed when the window is closed, eliminating cyclic referencesplayer\InventoryWindow
player\PlayerInventoryWindow
- wraps all permanent inventories of Player with type info for transactionsinventory\Hotbar
- replaces all hotbar & held-item usages inPlayerInventory
Human->getHotbar()
inventory\DelegateInventory
(only used for ender chests)inventory\PlayerInventory
,inventory\PlayerOffHandInventory
,inventory\PlayerCraftingInventory
,inventory\PlayerCursorInventory
- these have all been internally replaced bySimpleInventory
& they will appear asPlayerInventoryWindow
in transactions (checkgetType()
against thePlayerInventoryWindow::TYPE_*
constants to identify them)block\inventory\AnimatedBlockInventoryTrait
,block\inventory\BlockInventoryTrait
,block\inventory\BlockInventory
(replaced byAnimatedBlockInventoryWindow
,BlockInventoryWindow
)BlockInventory
classes have been transitioned toInventoryWindow
wrappersSimpleInventory
internally (no cyclic references) except forChest
(which still usesDoubleChestInventory
, but without holder info)InventoryOpenEvent
andInventoryCloseEvent
now provideInventoryWindow
instead ofInventory
(to provide type information)InventoryTransaction
andSlotChangeAction
now provideInventoryWindow
instead ofInventory
TransactionBuilderInventory
toSlotChangeActionBuilder
TransactionBuilderInventory->getBuilder()
now acceptsInventoryWindow
instead ofInventory
I am aware that the current changeset makes it rather more annoying to open inventory menus to the player. This PR is still under active development and will change in the future.
Behavioural changes
Inventories no longer keep permanent cyclic references to their holders.
Backwards compatibility
This makes significant BC breaks. However, all changes are able to be adapted to and the same amount of information is present on all APIs and events.
Follow-up
getInventory()
APIs to blocksTests
Briefly tested in-game.