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

Fix parity issue in Sodium's getFacing optimization #2121

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

embeddedt
Copy link
Contributor

The optimization introduced in #1587 has a subtle parity issue: if x, y, z are all zero, Sodium's Direction.getFacing implementation returns Direction.DOWN, while vanilla returns Direction.NORTH. This could potentially cause modded code to crash if it implicitly assumed that the returned direction was horizontal in this case (I believe this caused AlexModGuy/Ice_and_Fire#4767).

This PR fixes that by checking for this corner case and returning the same value as vanilla. An alternate solution would be to reorder the chain of if statements such that NORTH would end up being selected.

@douira
Copy link
Collaborator

douira commented Oct 12, 2023

Doing this check explicitly feels cleaner than manipulating the other statements, also because it avoids needing to calculate the absolute values in that case. Though I suspect either way doesn't have any performance relevance.

@IMS212 IMS212 merged commit eeafb59 into CaffeineMC:dev Oct 12, 2023
@embeddedt embeddedt deleted the fix/getfacing-parity branch October 13, 2023 23:42
IMS212 added a commit to IMS212/sodium-fabric that referenced this pull request Aug 6, 2024
Fix parity issue in Sodium's getFacing optimization
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