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

Fixed some bugs and added QoL features #181

Open
wants to merge 8 commits into
base: dev/1.4.0
Choose a base branch
from

Conversation

MissingReports
Copy link

Changes

  • Made stealable items moveable regardless whether they were in a section or no
    Why: If someone specifically marked a slot as stealable, i see NO reason why this should still be cancelling the event. To move sectioned slots the slot itself has to be stealable, if the gui is stealable but the slot isn't then it won't let you move it

  • Made a new Slot Changed section, which is triggered when a specific slot was changed
    Why: This makes it easier to detect changes. Before, it wasn't even possible to detect when you instantly move an item from your inventory into the GUI. Most of the time, cancelling the event won't do anything in a Slot Changed section. You might think this is useless but it has (for me at least) alot of usecases, such as custom anvil or custom crafting table

  • Some changes to the code
    Why: Some parts were causing a warning because they weren't properly coded, such as if List#size == 0 instead of if List#isEmpty

For the most part, I added stuff to skript-gui. It won't affect others and would be useful in some situations. So I hope this PR get's accepted or added in some way

Fixed some bugs regarding removeable/stealable GUI items
@APickledWalrus
Copy link
Owner

I'll take a look into reviewing this soon, sorry for the delay

@APickledWalrus APickledWalrus changed the base branch from master to dev/1.4.0 August 22, 2024 16:47
@APickledWalrus APickledWalrus added the enhancement New feature or request label Aug 22, 2024
Copy link
Owner

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution! Here are some of the things that I noticed. Please feel free to reply to any of my comments if you have any questions/thoughts 🙂

@@ -167,4 +167,7 @@ public String toString(@Nullable Event e, boolean debug) {
}
}

public Expression<Object> getSlots() {
Copy link
Owner

Choose a reason for hiding this comment

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

Is this used anywhere? If not, it should be removed.

Copy link
Author

Choose a reason for hiding this comment

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

I think I accidently auto generated this part

event.setCancelled(true);
break;
ItemStack cursor = event.getCursor();
if (cursor != null) {
Copy link
Owner

Choose a reason for hiding this comment

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

This code is starting to go off into space a little bit. It would be better to terminate exit early when possible instead. That is, do something like:

if (cursor == null)
	return;

Integer[] slots = guiSlots.getAll(e);

for (Integer slot : slots) {
if (gui != null && slot != null && slot >= 0 && slot + 1 <= gui.getInventory().getSize()) {
Copy link
Owner

Choose a reason for hiding this comment

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

the gui != null check should be moved up:

if (gui == null)
	return walk(e, false);

additionally, slot won't ever be null

continue;
}
event.setCancelled(true);

eventHandler.onChange(clickEvent);
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think it's appropriate to call this here. The slot isn't removable.

return;
if (firstEmpty != -1) { // Safe to be moved into the GUI
InventoryClickEvent clickEvent = gui.setClickedSlot(event, firstEmpty);
eventHandler.onChange(clickEvent);
Copy link
Owner

Choose a reason for hiding this comment

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

This should only be called if it is safe to move something into the slot I think

Copy link
Author

Choose a reason for hiding this comment

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

That part was causing a bug, I don't remember it tho

Copy link
Owner

Choose a reason for hiding this comment

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

Would you be able to test it again? My concern here is if the slot is locked but doesn't have anything in it.

Copy link
Author

Choose a reason for hiding this comment

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

Alright

Copy link
Owner

@APickledWalrus APickledWalrus Aug 26, 2024

Choose a reason for hiding this comment

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

I would recommend removing this (per our discussion above) and let me know if it gives you any issues (include code if applicable please 🙂)

Copy link
Author

Choose a reason for hiding this comment

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

I would recommend removing this (per our discussion above) and let me know if it gives you any issues (include code if applicable please 🙂)

If this part is removed, shift clicking an item from your inventory into an empty slot in the gui won't trigger the on change

@@ -233,6 +265,16 @@ public Character convert(Object slot) {
return nextSlot();
}

public InventoryClickEvent setClickedSlot(InventoryClickEvent event, int slot) {
Copy link
Owner

Choose a reason for hiding this comment

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

This would be better off as a static method in GUIEvents

Comment on lines 118 to 121
if (cursor.getAmount() < cursor.getMaxStackSize()) {
InventoryClickEvent clickEvent = gui.setClickedSlot(event, slot);
eventHandler.onChange(clickEvent);
}
Copy link
Owner

Choose a reason for hiding this comment

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

I don't think this is accurate enough. You need to keep a running total of how many items have merged into the cursor. Once you hit the max stack size the other slots (even if they have the same item) won't be modified. Same applies for the below case.

e.setCancelled(!isRemovable(slotData));

Consumer<InventoryClickEvent> runOnChange = slotData.getRunOnChange();
if (runOnChange != null) {
Copy link
Owner

Choose a reason for hiding this comment

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

You shouldn't run the consumer if the event is cancelled.

@MissingReports
Copy link
Author

Thanks for the contribution! Here are some of the things that I noticed. Please feel free to reply to any of my comments if you have any questions/thoughts 🙂

I have committed the updated code, fixing all the previous mistakes

Copy link
Owner

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

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

Mainly just the one change that needs further testing. Other than that, this should be good to go. Thank you for your work!!

return;
if (firstEmpty != -1) { // Safe to be moved into the GUI
InventoryClickEvent clickEvent = gui.setClickedSlot(event, firstEmpty);
eventHandler.onChange(clickEvent);
Copy link
Owner

@APickledWalrus APickledWalrus Aug 26, 2024

Choose a reason for hiding this comment

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

I would recommend removing this (per our discussion above) and let me know if it gives you any issues (include code if applicable please 🙂)

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

Successfully merging this pull request may close these issues.

2 participants