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

shift click does not work in 1.8 and item gets lost on close #355

Open
arthurvanl opened this issue Oct 15, 2024 · 2 comments
Open

shift click does not work in 1.8 and item gets lost on close #355

arthurvanl opened this issue Oct 15, 2024 · 2 comments
Labels

Comments

@arthurvanl
Copy link

arthurvanl commented Oct 15, 2024

2024-10-15.18-13-05.mp4

I am using 1.10.2-SNAPSHOT and item gets lost on close and shift clicking does not work.

code I used:

new AnvilGUI.Builder()
                    .onClose(stateSnapshot -> {
                        stateSnapshot.getPlayer().sendMessage("You closed the inventory.");
                    })
                    .onClick((slot, stateSnapshot) -> { // Either use sync or async variant, not both
                        System.out.println(slot);
                        ItemStack leftItem = stateSnapshot.getLeftItem();
                        ItemStack rightItem = stateSnapshot.getRightItem();
                        if(slot == Slot.OUTPUT) {
                            
                        }
                        return Collections.emptyList();
                    })
                    .interactableSlots(Slot.INPUT_LEFT, Slot.INPUT_RIGHT)
                    .plugin(plugin)                                          //set the plugin instance
                    .open((Player) event.getPlayer());
@0dinD
Copy link
Collaborator

0dinD commented Oct 24, 2024

shift click does not work

This is either a bug or a missing feature depending on ones perspective, but either way I agree that it should be possible to allow shift-clicks. The reason it does not currently work is that AnvilGUI can't tell what will happen when you shift-click (unless AnvilGUI reimplements the entire vanilla inventory logic, which is not going to happen), so AnvilGUI doesn't know which slot(s) the shift-clicked item stack will end up in. Because of that, AnvilGUI can't tell whether the shift-click should be allowed or not based on the interactableSlots, so currently it just denies the shift-click. In my opinion, interactableSlots was kind of a mistake because as you can see it's kind of impossible to implement "correctly".

But either way, I think we can make a band-aid fix in AnvilGUI by allowing shift-clicks only if both the left and the right input slot is interactable, because then AnvilGUI does not need to know where the items would end up. And if for some reason someone wants only one of the input slots to be interactable, they can just reimplement the inventory logic themselves.

I'll add this fix after updating AnvilGUI to work on Minecraft 1.21.3.

item gets lost on close

For historical reasons, that's kind of how AnvilGUI works (AnvilGUI was created as a text input library, not a general-purpose Anvil library), but I can see why you're confused (I'll try to improve the documentation later). You can implement the item drop logic yourself via onClose, see #354 (comment)

@0dinD 0dinD added the question label Oct 24, 2024
@arthurvanl
Copy link
Author

arthurvanl commented Oct 24, 2024

AnvilGUI always sets the final level cost to 0. I think we should make this more customizable, but I guess this wasn't done because most people's use cases for AnvilGUI involved using it as text input or some kind of custom anvil where they didn't want to consume XP from the player.

I see this in your comment. Can this be changed? I really would like to use this and the shift click. The main reason why I stopped using anvils at the moment. Much appreciated!

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

No branches or pull requests

2 participants