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

Update SlotWithIndex and InventorySlot Comparisons #7713

Open
wants to merge 7 commits into
base: dev/feature
Choose a base branch
from

Conversation

Fusezion
Copy link
Contributor

@Fusezion Fusezion commented Mar 16, 2025

Description

This PR aims to change how the comparison of SlotWihtIndex behaviors, old behavior would cause some relatively less than desired behavior if two different inventories were comparing with the same index.

This would be a mild breaking change to some degree on servers, however this change should attempt to make the comparison a bit more stricter. Only two areas in skript actually set the raw index accordingly and that's clicked slot and event-slot for InventoryClickEvent

Everywhere else handles it as this.index = this.rawIndex = index

an example of this change being in effect is

on inventory click:
    event-slot is slot 4 of top inventory of player
    broadcast "Clicked slot 4 of top Inventory"

Before this would return true for both the bottom and top, now only when it's the top


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

@Efnilite Efnilite added the bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. label Mar 16, 2025
@Efnilite
Copy link
Member

what do you think about deprecating isSameSlot and overriding equals instead with the new correct behaviour?

@Fusezion
Copy link
Contributor Author

what do you think about deprecating isSameSlot and overriding equals instead with the new correct behaviour?

I'd be perfectly with that type of implementation, however I'd like to hear one or two more team member's opinions before I go and do that change

@sovdeeth
Copy link
Member

what do you think about deprecating isSameSlot and overriding equals instead with the new correct behaviour?

I'd be perfectly with that type of implementation, however I'd like to hear one or two more team member's opinions before I go and do that change

Makes sense to me, remember to change the slot comparator accordingly and check for any breaking changes.

@Fusezion Fusezion requested a review from a team as a code owner March 22, 2025 17:57
@Fusezion Fusezion requested review from APickledWalrus and Pesekjak and removed request for a team March 22, 2025 17:57
@Fusezion
Copy link
Contributor Author

Alright I've gone ahead and committed the deprecation as well as update their related classes.
I've changed the slot to slot comparison, I was unable to find any other calls that need fixed. At most this might be some Slot#equals(Slot) that existed prior and would be prone to poor behavior in the past.

Do we believe the Slot -> Number comparison should also be updated to raw index if possible? I was testing and realized that the below code would pass where as slot 0 of player's top inventory is event-slot will not.

on inventory click:
    event-slot is 0
    broadcast "passed"

@sovdeeth
Copy link
Member

sovdeeth commented Mar 22, 2025

Alright I've gone ahead and committed the deprecation as well as update their related classes. I've changed the slot to slot comparison, I was unable to find any other calls that need fixed. At most this might be some Slot#equals(Slot) that existed prior and would be prone to poor behavior in the past.

Do we believe the Slot -> Number comparison should also be updated to raw index if possible? I was testing and realized that the below code would pass where as slot 0 of player's top inventory is event-slot will not.

on inventory click:
    event-slot is 0
    broadcast "passed"

No, I think it should maintain the same behavior as index of event-slot (which shouldn't change based on the current inventory view). Also, have you tested things like event-slot is player's tool, or event-slot is slot 0 of player's inventory?

@Fusezion
Copy link
Contributor Author

Also, have you tested things like event-slot is player's tool, or event-slot is slot 0 of player's inventory?

l've tested the latter, but I will test the former shortly

Copy link
Member

@sovdeeth sovdeeth left a comment

Choose a reason for hiding this comment

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

Based on some testing, I believe the rawIndex approach is fundamentally flawed and there's a better and easier solution by implementing isSameSlot on InventorySlot to compare inventories as well as indices. See https://discord.com/channels/135877399391764480/836220422223036467/1353113589841531021 for discussion.

@Fusezion Fusezion changed the title SlotWithIndex - Change comparison to use rawIndex instead of index SlotWithIndex Compare with rawindex, InventorySlot include inventory comparison Mar 23, 2025
@Fusezion Fusezion changed the title SlotWithIndex Compare with rawindex, InventorySlot include inventory comparison Update SlotWithIndex and InventorySlot Comparisons Mar 23, 2025
@Fusezion Fusezion requested a review from sovdeeth March 23, 2025 06:14
@sovdeeth
Copy link
Member

Sorry to flip flop my opinion here but after looking into it further I don't think equals is appropriate here. The behavior implemented does not satisfy the constraints the javadocs for equals() set out. I think it's best to stick with isSameSlot.

@Fusezion
Copy link
Contributor Author

Fusezion commented Mar 23, 2025

I've reverted the isSameSlot deprecation and equals, along with added a few public methods for developers to get the core object references in the classes.

i.e. DisplayEntitySlot getItemDisplay(), ThrowableProjectileSlot getProjectile(), while not currently used outside of their isSameSlot comparisons this at least grants access to developers freely.

@sovdeeth sovdeeth requested a review from Efnilite March 23, 2025 17:24
@sovdeeth sovdeeth requested a review from Burbulinis March 23, 2025 17:24
@Efnilite Efnilite added the feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version. label Mar 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. feature-ready A PR/issue that has been approved, tested and can be merged/closed in the next feature version.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants