Skip to content

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
Contributor

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
Contributor

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
Contributor

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.

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

feature Pull request adding a new feature.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants