Repository navigation
Prevent negative damage being passed into DamageContainer creation - #3728
Open
TelepathicGrunt wants to merge 3 commits into
Open
TelepathicGrunt wants to merge 3 commits into
TelepathicGrunt wants to merge 3 commits into
Conversation
|
pupnewfster
requested changes
Nov 10, 2026
pupnewfster
approved these changes
Nov 11, 2026
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.
Since the other PR: #3725 is vibecoded with the wrong solution in wrong place, I made this PR for the proper fix.
So the issue is rolled-up Armadillos have this damage calculation before they call LivingEntity$hurtServer:
damage = (damage - 1.0F) / 2.0F;Now while you can't actually damage they with 0 damage, you can inflict damage between 0 and 1 such as calling this command while the armadillo is rolled up:
/damage @e[type=minecraft:armadillo,limit=1] 0.5 minecraft:arrowThis will inflict 0.5 damage to the armadillo whose calculation will turn it into -0.25.
Then in LivingEntity$hurtServer, we create a DamageContainer with this -0.25 damage and then fire LivingIncomingDamageEvent with that container
Now here's the issue, DamageContainer$setDamage will throw an exception if it is fed a negative damage. So if a mod hooks up to LivingIncomingDamageEvent and multiplies the incoming damage by 2 and then call setDamage, -0.25 will be turned into -0.5 which is still negative, triggers the negative damage check and explode.
Since vanilla entities can go negative damage right off the bat such as rolled-up armadillos, this means other modded entities could copy the armadillo and do similar calculations with chances of going negative. The most comprehensive solution seems to just cap damage to no longer than 0 right before creating the initial DamageContainer. This should avoid mods that multiple/divide damage from exploding out of nowhere as they expect the damage to be positive.
EDIT: Now we early return if negative damage is detected