Skip to content

add onPrepare method#232

Closed
mastercake10 wants to merge 4 commits intoWesJD:masterfrom
mastercake10:v1_19
Closed

add onPrepare method#232
mastercake10 wants to merge 4 commits intoWesJD:masterfrom
mastercake10:v1_19

Conversation

@mastercake10
Copy link
Copy Markdown
Contributor

see #231.
Tested both on 1.8 and 1.19 with the new onPrepare function set, seems to work without causing any errors. I've registered the PrepareAnvilEvent using the PluginManager#registerEvent method, since it can't be in the same Listener class for mc < 1.9.

This listener can be used by calling Builder#onPrepare. It will be
triggered whenever a change to the item name has been made (WesJD#231).
@WesJD
Copy link
Copy Markdown
Owner

WesJD commented Nov 10, 2022

I really appreciate this PR. Sorry I haven't gotten a chance to look at it yet.

Looking at the original issue, the person mentions being able to modify the title or another element of the anvil in onPrepare. How do you think we should handle that?

@portlek
Copy link
Copy Markdown
Contributor

portlek commented Nov 10, 2022

@mastercake10
Copy link
Copy Markdown
Contributor Author

mastercake10 commented Nov 12, 2022

I really appreciate this PR. Sorry I haven't gotten a chance to look at it yet.

Looking at the original issue, the person mentions being able to modify the title or another element of the anvil in onPrepare. How do you think we should handle that?

I think we could use a BiFunction<Player, String, Response> for the onPrepare function, then return a Response that changes the title of the window AnvilGUI.Response.title(String).

The window title can be changed by re-sending the window open packet, the method is already there in the wrapper.
Unfortunately it also resets the input text field to the display name of the input item, so you basically can't sync the window title with the user input.

However, when you update the left input item's display name before sending the window open packet, it will also update the input text field to this value, so this could be a way around it. But with this method, the name of the input item and the input field are the same, so there is no output item.

So, whenever updating the inventory title, there is no output item, since both strings are the same. My solution is to add an enchanted book to the right slot, which will always force an output item and thus allow title updates:

Peek.2022-11-12.21-11.mp4

I don't know if there is a better solution for this, I think this is the only way for a smooth experience without clearing/blocking the output slot when updating the window title.

@WesJD
Copy link
Copy Markdown
Owner

WesJD commented Nov 27, 2022

Thanks for the research you did on this. The enchanted book idea is definitely interesting, but I think limits the usability of the library by other developers.

Based on your findings, I don't think it is really worth implementing this feature. It looks weird for the user, and it feels like the creator of the issue probably need this on a one-off case for likely just a cool small add on. Feels too limiting to add in.

@WesJD WesJD closed this Nov 27, 2022
@WesJD WesJD mentioned this pull request Nov 27, 2022
@mastercake10 mastercake10 mentioned this pull request Dec 20, 2022
@mastercake10 mastercake10 mentioned this pull request Nov 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants