Discussion on explosion behavior change (2/2): Fix block bounds off by one#926
Open
EZForever wants to merge 1 commit into
Open
Discussion on explosion behavior change (2/2): Fix block bounds off by one#926EZForever wants to merge 1 commit into
EZForever wants to merge 1 commit into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is the alternative PR about changing explosion behavior. See my last PR, #925, for context.
Rather than a logic refactor like in the last PR, this PR fixes a bug in current logic and partially restores correct explosion handling.
As mentioned in the last PR, there are multiple causes contributing to the block bounds being larger than intended; the bug this PR fixes is one of them.
To enumerate all the blocks inside the mapped, sublevel-local block area (essentially a rotated cube), the current logic takes the area's min and max coords,
floor()s them, and treats them as coords of a grid-aligned bounding box. This alone creates other problems, but let's leave it alone for now.sable/common/src/main/java/dev/ryanhcode/sable/mixin/explosion/ExplosionMixin.java
Lines 109 to 116 in c5e4737
This bounding box's min and max coords is then immediately gets extracted and iterated over.
sable/common/src/main/java/dev/ryanhcode/sable/mixin/explosion/ExplosionMixin.java
Lines 120 to 122 in c5e4737
The problem is the bounding box's max coords is assumed to be exclusive by the calculation logic, but is then used in the loop as inclusive. (For example,
floor()ing range -0.2~0.8 gives -1~0, which is correct in this context, but the loop will then count over both -1 and 0.) As a result, there is always one more block along each axis gets involved in the following logic, thus the effective minimal block bounds becomes 2x2x2 instead of 1x1x1.Doing the same test as in the last PR shows that fixing this bug partially fixes explosion handling; the crater (on the right) is larger than without the fix, but still smaller than it should be (on the left).
IMO this PR comes with less risk of breaking stuff than the last one (can't say for sure though), but it does not resolve the fundamental problem the current logic has.