Skip to content
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 #1992

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open

Conversation

GoldenStack
Copy link
Contributor

@GoldenStack GoldenStack commented Feb 11, 2024

Rework of the inventory system.
Recreation of hollow-cube#132

Main changes:

  • Accurate click handling (except for special slots like result slots)
  • Improved event API: allows accessing all click information via Click.Info, as well as providing a list of all changes via Click.Result
  • Removed InventoryCondition in favor of three events: InventoryPreClickEvent, modifying only click info, like slot IDs; InventoryClickEvent, modifying the list of changes that will occur as a result of the click; and InventoryPostClickEvent, which can view all the click information but happens after handling is finished

Changes:

  • Added InventoryButtonClickEvent
  • Moved a lot of behaviour into AbstractInventory, renamed AbstractInventory to Inventory and Inventory to ContainerInventory
  • Inventory events return the relevant PlayerInventory instead of null in #getInventory
  • Added the tagged union Click.Info containing all necessary click info (e.g. slots)
  • Made all inventories implement Viewable
  • Simplified click handling and implemented vanilla parity other than special slots (like result slots) in ClickProcessors
  • Moved click packet parsing & drag handling to each player's Click.Preprocessor
  • Added Click.Result which stores a map of all changes and side effects that could occur
  • Refactored InventoryCondition into InventoryClickEvent, and renamed what was formerly InventoryClickEvent into InventoryPostClickEvent
  • More comprehensive tests
  • Use ReentrantLock instead of Java synchronization
  • Made cursor items PlayerInventory-based
  • Greatly simplified inventory transaction logic
  • Creative click logic and drop/swap logic in PlayerDiggingHandler is handled correctly (also removed PlayerSwapItemEvent)

Copy link
Member

@mworzala mworzala left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got part of the way through reviewing, but ill wait for re-remapped ids

@mworzala
Copy link
Member

@GoldenStack please make sure these cases do not bypass events in this PR #1932

@GoldenStack
Copy link
Contributor Author

@GoldenStack please make sure these cases do not bypass events in this PR #1932

This will fix #1932, yes; offhand swaps become ClickInfo.OffhandSwap which are sent through the same pipeline as all other clicks. A quick test confirms that this functions correctly.

Copy link
Member

@TheMode TheMode left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will prob nitpick again later, but this is what I have for now


}

private static final @NotNull StackingRule RULE = StackingRule.get();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

StackingRule will most likely disappear in 1.20.5

@MelonHell
Copy link
Contributor

Hey, I still haven’t figured out how to use the inventory after Inventory Rework PR. How can I block a slot? To prevent a player from taking an item from a slot, to prevent a player from putting an item into a slot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Swapping items into offhand bypasses inventory conditions
5 participants