[Scarpet] [Request] add event handler for when block interaction ends.
Lodran opened this issue ยท 9 comments
I'm working on a Scarpet app that would provide mystcraft style teleportation by modifying the lectern. In order do this, I need an event handler to notify me that the player's interaction with the lectern has ended, as well as the reason that it ended (player pressed "Done", player pressed "Take Book", player pressed the 'esc' key).
Tbh, I've no idea if Fabric allows it - I'm using Scarpet to insulate myself against Fabric's complications. Hopefully someone with more experience here than I knows if it can be done.
That would work for the "Done" vs "Take book" case (checking for the existence of the book on the lectern should also work), but since "Done" will teleport the player, I'd like "esc" to cancel the interaction entirely. For that, I'd need more information.
Fabric allows anything to be done, since it allows you to even directly replace a part of the game code with your own (even the entire game, lol). However, the problem is whether the vanilla game allows it, since clients without Carpet can join Carpet servers, and it would be necessary to check whether the (vanilla) client actually sends that information.
The Take book
is definitely synced somehow (server must know book is no longer there), but not sure about Done
nor esc
(if they exist, I don't think they will be different). In chests and containers they exist for sure (IIRC client requests to stop tracking changes in the inventory, since those are live), but I'm not sure about non-containers (container being an actual "inventory" (visible), lectern doesn't fit in that category since it either has or doesn't have the book, and IIRC the UI doesn't even open when there is no book). EDIT: Checking the last part of the comment, if the server knows whether the client has the lectern open in order to close it if it's broken or someone else takes the book, it is likely that clients send when they stop looking at them.
It may be synced in ButtonClickC2S
or CloseHandledScreenC2S
.
If checking screen closed for "everything" is possible, then I'd like to suggest an __on_player_closes_screen(player, block)
, where block
is the block that was holding the screen that was closed, if available (if not possible, at least the handler type, and if possible, in case of closing due to block breaking, passing the block before it being broken, to be able to check the type and not finding air
in there).
In your use case, you could differentiate between Done
/esc
and Take book
by scheduling to maybe in 1 tick, if not instant or at the end of the tick, check whether the player now has the book in its inventory.
Is this something that could be implemented using the custom events mechanism (i.e. handle_event)? If so, how?
No, it couldn't, since those events are thought to be used for custom things, you still need a way to trigger them, and Scarpet doesn't currently have such handler.
(btw you can dinamically change your handlers of default events with handle_event
, not only custom ones).
PS: Of course, you could make your own Carpet extension (in Java) if you don't want to wait for an official implementation/the official implementation is not good enough for you. Although I think that wasn't the question.
No, it couldn't, since those events are thought to be used for custom things, you still need a way to trigger them, and Scarpet doesn't currently have such handler.
U sure about dat mate. See #602 ... Idk if thats truly related, but worth seeing.