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

Looking for Advice #354

Open
RocketManKian opened this issue Oct 14, 2024 · 3 comments
Open

Looking for Advice #354

RocketManKian opened this issue Oct 14, 2024 · 3 comments
Labels

Comments

@RocketManKian
Copy link

RocketManKian commented Oct 14, 2024

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
Copy link
Collaborator

0dinD commented Oct 14, 2024

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.

@0dinD 0dinD added the question label Oct 14, 2024
@RocketManKian
Copy link
Author

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

@0dinD
Copy link
Collaborator

0dinD commented Oct 14, 2024

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:

  • AnvilGUI does not provide any "vanilla" behavior such as "if the player takes the output item then all anvil slots should be cleared". If you want that behavior, you can probably reimplement it yourself, via onClick. But do note that many of the Bukkit inventory API caveats mentioned in the Javadocs also apply to AnvilGUI.
  • AnvilGUI always copies the left item to the output slot (I think for convenience, as this is what you'd usually want). I think we should make this more customizable though.
  • 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.
  • Unlike the vanilla anvil, AnvilGUI does not drop the items inside the anvil input slots when the anvil menu is closed. This means that any items that the player puts into the anvil slots (if permitted using interactableSlots) will "vanish" when the anvil is closed, unless you add code to drop the player-inserted items in onClose.

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.

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