Events for books for modders
Cmdpro opened this issue ยท 4 comments
I have a mod using modonomicon which needs to detect when a locked entry is clicked, it would be nice if there was a way to run code when stuff happens for mods (like clicking an entry, clicking a category and stuff like that), for the locked entry click thing specifically, it could work where it runs the code whenever the entry is clicked but the entry and the visual state are used as parameters, as far as i can tell, there is no current way to do this
@Cmdpro that seems like a good idea, I am sure more people need that.
Can you give some info on your requirements?
- How should you be notified?
I am considering simply offering a callback registry that you hand a lambda/method ref to, as it is lightweight and avoids using the platform specific event systems
- Which logical side, server or client, or both should be notified of the click?
I think in this case it would probably be sufficient to notify client side because it is just input - any server side logic or verification could then be handled by the mods that actually need that to avoid packet spam on click
- What info should come alongside the click?
I think at the very least the book id and entry id, but we could also add the click x/y and such stuff
Ah perhaps another salient question in this context should be the event handling.
Should this event be able to cancel the click?
Currently the entry click detection looks like below. If we have a client-only click event we could allow the event to intercept the default behaviour if that is desirable
public boolean mouseClicked(double pMouseX, double pMouseY, int pButton) {
float xOffset = this.getXOffset();
float yOffset = this.getYOffset();
for (var entry : this.category.getEntries().values()) {
var displayStyle = this.getEntryDisplayState(entry);
if (displayStyle == EntryDisplayState.UNLOCKED) {
if (this.isEntryHovered(entry, xOffset, yOffset, (int) pMouseX, (int) pMouseY)) {
this.openEntry(entry);
return true;
}
}
}
return false;
}
Ah perhaps another salient question in this context should be the event handling. Should this event be able to cancel the click?
Currently the entry click detection looks like below. If we have a client-only click event we could allow the event to intercept the default behaviour if that is desirable
public boolean mouseClicked(double pMouseX, double pMouseY, int pButton) { float xOffset = this.getXOffset(); float yOffset = this.getYOffset(); for (var entry : this.category.getEntries().values()) { var displayStyle = this.getEntryDisplayState(entry); if (displayStyle == EntryDisplayState.UNLOCKED) { if (this.isEntryHovered(entry, xOffset, yOffset, (int) pMouseX, (int) pMouseY)) { this.openEntry(entry); return true; } } } return false; }
Can Cancel : Yes, I dont require the click to be canceled but im sure that canceling it could be useful
Side : Client, it will work fine, as you said, mods can send their own packets for server sided stuff
Notify : Whatever you think will work best, i have not done something like this before
Info : Book Id, Entry Id, Mouse X, Mouse Y, i should be able to get the visual state from this info and mouse click pos could be useful
Edit : Made it easier to read
Edit 2 : Removed a word that should not be there