-
-
Notifications
You must be signed in to change notification settings - Fork 43
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
Fix "The Crafting Mechanic" example on "Recipes" #155
Conversation
Would you mind explaining how the change fixes a client/server desync? You should generally be checking recipes on the server only, along with removing the block and adding the item entity. It would be different if the recipe was being populated to some sort of client menu, but that is not relevant in this case. |
Sure. Imageine there is a listener from another mod that also listens to UseItemOnBlockEvent and plants a flower. On the server the event gets cancelled, so the flower never is planted. But on the client, the event is delivered to the other handler that put the flower there. Now we have a desync that persists, as the server never cancels the placed flower. Block changes run on both server and client to reduce lag. Cancelling any code path that may place/change/remove a block on one side only is bad. At most you can cancel it on the client and wait for the server to sync the block action (then it will only feel laggy to the player), or cancel it on the server and send a block update back to the original state. But cancelling something server-side only when you have no way of sending a packet that cancels the action (because you have no idea what may have happened) is not good at all. Also, cancelling this event cancels the vanilla logic for the right click. What would that have done? And what would the right-click handling for the offhand have done? The player could have a torch in their offhand, on the server nothing would have happened, but on the client that torch would have been placed. Again, without the server having any idea about it or being able to send an update to undo it. We're very used to code only running on client OR server, but there's plenty of stuff that runs on the client predicting what the server will do. Block updates, entity movement, even day time advancing. Those all are cases where interfering on only one side will either produce desyncs, lag, rubberbanding, or stutter. |
Ah, I missed that this was called in an event. Thank you for the detailed explanation regardless. Though, if we want to make it better, I suggest to replace the |
Deploying with Cloudflare Pages
|
Sure. Could you take that part? I don't feel secure enough in that part yet... |
It should just be |
For context, I would like to mention that I eventually want to make an article all about how the hierarchy surrounding the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! Sorry for being late on this.
Fixes #154
Preview URL: https://pr-155.neoforged-docs-previews.pages.dev