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

Add InventoryDragEvent #5474

Merged
merged 6 commits into from
Jun 23, 2023
Merged

Add InventoryDragEvent #5474

merged 6 commits into from
Jun 23, 2023

Conversation

UnderscoreTud
Copy link
Member

Description

This PR adds the inventory drag event.


Target Minecraft Versions: any
Requirements: none
Related Issues: #3744

@UnderscoreTud UnderscoreTud added the feature Pull request adding a new feature. label Feb 24, 2023
Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com>
Co-authored-by: Ayham Al Ali <20037329+AyhamAl-Ali@users.noreply.github.com>
return event.getWhoClicked().getWorld();
}
}, EventValues.TIME_NOW);
EventValues.registerEventValue(InventoryDragEvent.class, ItemStack[].class, new Getter<ItemStack[], InventoryDragEvent>() {
Copy link
Member

@AyhamAl-Ali AyhamAl-Ali Mar 23, 2023

Choose a reason for hiding this comment

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

Is there a use for getOldCursor() here? Could it be the past timestate of event-itemstack?

@Override
@Nullable
public Inventory[] get(InventoryDragEvent event) {
Set<Inventory> inventories = new HashSet<>(2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

use an array here instead of a set when we know the length of the return array

Copy link
Member Author

Choose a reason for hiding this comment

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

That won't work because I'm dynamically checking the size of the set, with an array it's always a fixed size. Technically it can be done with arrays but it will just make code uglier

Copy link
Collaborator

Choose a reason for hiding this comment

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

It just occurred to me that this is not future proof, Mojang could add some sort of view where more than 2 inventories could be returned from this.

I don't believe it should be capped off at 2, just return however many inventories could be found.

int slot = view.convertSlot(rawSlot);
if (inventory == null)
continue;
if (inventory instanceof PlayerInventory && slot >= 36) {
Copy link
Member

Choose a reason for hiding this comment

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

Maybe add notes why using the inventory size (36) for future contributions

@Override
@Nullable
public Inventory[] get(InventoryDragEvent event) {
Set<Inventory> inventories = new HashSet<>(2);
Copy link
Collaborator

Choose a reason for hiding this comment

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

It just occurred to me that this is not future proof, Mojang could add some sort of view where more than 2 inventories could be returned from this.

I don't believe it should be capped off at 2, just return however many inventories could be found.

@TheLimeGlass TheLimeGlass added the 2.7 Targeting a 2.7.X version release label Jun 22, 2023
Co-authored-by: LimeGlass <16087552+TheLimeGlass@users.noreply.github.com>
@TheLimeGlass TheLimeGlass merged commit 3dd5394 into master Jun 23, 2023
TheLimeGlass pushed a commit that referenced this pull request Jun 23, 2023
(cherry picked from commit 3dd5394)
@TheLimeGlass TheLimeGlass deleted the feature/inventory-drag-event branch July 13, 2023 06:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
2.7 Targeting a 2.7.X version release feature Pull request adding a new feature.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants