WesJD / AnvilGUI

Capture user input in Minecraft through an anvil GUI in under 20 lines of code
MIT License
479 stars 113 forks source link

Looking for Advice #354

Open RocketManKian opened 5 days ago

RocketManKian commented 5 days ago

Hey there! So loving the customisation of the API so far but I am quite stuck on trying to achieve what I want to achieve.

I would basically like to completely copy the regular use of an Anvil but with the AnvilGUI API, this is because I want to make a /anvil command where players can use it wherever they choose.

Here is my current code new AnvilGUI.Builder() .onClick((slot, stateSnapshot) -> { // Either use sync or async variant, not both return Collections.emptyList(); }) .interactableSlots(AnvilGUI.Slot.INPUT_LEFT, AnvilGUI.Slot.INPUT_RIGHT, AnvilGUI.Slot.OUTPUT) .title("Repair & Name") //set the title of the GUI (only works in 1.14+) .plugin(ServerEssentials.getPlugin()) //set the plugin instance .open(player);

But I am having issues where when I put an item in any of the slots I can shift + click it out and the output will duplicate the item, so I haven't quite nailed the vanilla anvil functionality.

Any advice or help would be appreciated :)

0dinD commented 4 days ago

Hi! So your /anvil command is supposed to open a virtual anvil that behaves exactly like a vanilla anvil?

If so, you should know that AnvilGUI reimplements some parts of the anvil logic in order to make more advanced customization of the anvil behavior possible on as many versions of the game as possible. So because AnvilGUI reimplements rather than delegates to the vanilla logic, it is possible that AnvilGUI behaves differently from the vanilla anvil in some cases. With that said, ideally it should be possible to create a "vanilla-like" anvil with AnvilGUI.

Your issue sounds like it could be caused by a bug in AnvilGUI. I'm currently busy with other projects but I want to investigate this possible bug, maybe within a week or two.

Either way, if you just want a virtual vanilla anvil, you could probably use the Spigot/Paper API for it instead. If you're using 1.21.1+, I would recommend you to check out Spigot's new MenuType API.

RocketManKian commented 4 days ago

Oh sweet! Thank you for the link to the MenuType API, I'll be sure to check it out :)

0dinD commented 4 days ago

You're welcome :)

But it also just occurred to me that your issue might not be a bug but rather a misunderstanding about how AnvilGUI works (the documentation could definitely be improved in some regards). I said earlier that the AnvilGUI reimplementation of the anvil has some deviations from the vanilla anvil, but if I'm not mistaken, there are some pretty substantial differences, such as:

With that in mind you're probably better off using the MenuType or similar API if you want vanilla behavior. The situation might be improved in the future, but AnvilGUI has traditionally been used (and developed for) other use cases, such as text input, so "vanilla-like" behavior may be hard or impossible to achieve with the current AnvilGUI version.