-
Notifications
You must be signed in to change notification settings - Fork 14
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
base: dev/1.4.0
Are you sure you want to change the base?
Conversation
Fixed some bugs regarding removeable/stealable GUI items
I'll take a look into reviewing this soon, sorry for the delay |
There was a problem hiding this 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() { |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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()) { |
There was a problem hiding this comment.
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
src/main/java/io/github/apickledwalrus/skriptgui/gui/GUIEventHandler.java
Show resolved
Hide resolved
continue; | ||
} | ||
event.setCancelled(true); | ||
|
||
eventHandler.onChange(clickEvent); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright
There was a problem hiding this comment.
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 🙂)
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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
if (cursor.getAmount() < cursor.getMaxStackSize()) { | ||
InventoryClickEvent clickEvent = gui.setClickedSlot(event, slot); | ||
eventHandler.onChange(clickEvent); | ||
} |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
… and the opposite Removed unwanted code
I have committed the updated code, fixing all the previous mistakes |
src/main/java/io/github/apickledwalrus/skriptgui/elements/sections/SecMakeGUI.java
Outdated
Show resolved
Hide resolved
src/main/java/io/github/apickledwalrus/skriptgui/gui/events/GUIEvents.java
Outdated
Show resolved
Hide resolved
…ions/SecMakeGUI.java Co-authored-by: Patrick Miller <[email protected]>
…IEvents.java Co-authored-by: Patrick Miller <[email protected]>
There was a problem hiding this 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!!
src/main/java/io/github/apickledwalrus/skriptgui/gui/events/GUIEvents.java
Show resolved
Hide resolved
return; | ||
if (firstEmpty != -1) { // Safe to be moved into the GUI | ||
InventoryClickEvent clickEvent = gui.setClickedSlot(event, firstEmpty); | ||
eventHandler.onChange(clickEvent); |
There was a problem hiding this comment.
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 🙂)
…IEvents.java Co-authored-by: Patrick Miller <[email protected]>
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 ofif 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