-
-
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
Separate inventory holder info from container & player inventories #6533
base: major-next
Are you sure you want to change the base?
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
…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 allows introducing block variations of these without name conflicts
this removes a bunch of problematic Position usages from Tile, as well as getting rid of a bunch of code duplication.
…ated turns out relying on scheduled updates for this was a bad idea, since it causes a lot of unnecessary code to run every tick, as well as being problematic for campfire, which doesn't have any blockstates to compare against.
Double chests have also proven to be a pain in the ass and will likely be an obstacle for #6147 as well |
…orld having this created by the block was unreliable anyway. If items were set into the block's created inventory before setting the block in the world, the campfire contents would get overridden when the block was next run through readStateFromWorld() anyway. There needs to be a deeper exploration of how to handle blocks with inventories without requiring plugins to interact with tiles. For now, this isn't the worst solution, but it's not the best either.
…st inventories" This reverts commit 1d2b527. I hadn't considered that the likes of plugins and hoppers need to be able to interact with double chest inventories as well as players. If we were to move this logic to the Block side, we'd have to expose APIs on the Chest block to get the correct inventory lazily. I'm not sure I want to commit to having getInventory() on the block right now, as we can't guarantee it's available (see problems around Campfire inventory on the block). Short term, it'll probably be better to just expose the logic in block\Chest for deciding which side the inventories should be on.
this could be used for a bunch of different things aside from double chests since the DoubleChestInventory no longer references anything specific about chests, I figured it was time to generalize this.
…ere directly modified this was always lacking with DoubleChestInventory and is a major factor in it being basically useless for custom use cases.
Only remaining major issue is around the lengthened usage for opening inventory windows to players. I didn't quite decide how to deal with it. There are a few things to consider:
|
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()
block\utils\AnimatedContainer
&block\utils\AnimatedContainerTrait
(for chests, shulkerboxes, etc)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
, (blocks now handle this logic directly usingAnimatedContainer
andAnimatedContainerTrait
)block\inventory\BlockInventoryTrait
,block\inventory\BlockInventory
BlockInventory
classes have been transitioned toInventoryWindow
wrappersSimpleInventory
internally (no cyclic references) except forChest
(which usesCombinedInventory
, 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
DoubleChestInventory
superseded byCombinedInventory
- this new class allows combining any number of inventories behind a single object; mainly used for double chests but plugins could use it to do lots of fun thingsI 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.