Skip to content

Prevent negative damage being passed into DamageContainer creation - #3728

Open
TelepathicGrunt wants to merge 3 commits into
neoforged:26.3.xfrom
TelepathicGrunt:NegativeDamage
Open

TelepathicGrunt wants to merge 3 commits into
neoforged:26.3.xfrom
TelepathicGrunt:NegativeDamage

Conversation

@TelepathicGrunt

@TelepathicGrunt TelepathicGrunt commented Nov 10, 2026 •

Copy link
Copy Markdown
Contributor

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;

image

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:arrow

This 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

image

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

@TelepathicGrunt TelepathicGrunt added bug A bug or error 26.3 Targeted at Minecraft 26.3 labels Nov 10, 2026
@neoforged-pr-publishing

Copy link
Copy Markdown
  • Publish PR to GitHub Packages

@TelepathicGrunt TelepathicGrunt changed the title Prevent negative damage into DamageContainer creation Prevent negative damage being passed into DamageContainer creation Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

26.3 Targeted at Minecraft 26.3 bug A bug or error

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants