mojira.dev
MC-2310

Wrong attack radius calculation damages/kills entities through blocks and corners

The bug

Mobs can attack you through blocks and corners due to miscalculation of attack radius.

How to reproduce

  1. Build a completely sealed off house with no windows or doors from opaque blocks like planks or cobblestone or the like, leave some blocks in the inventory for you to place in step 7.

  2. Make a two-block tall one-block wide empty doorway in the wall for you to go through and to seal off with blocks in step 7.

  3. Outside the house, spawn a Ravager.

  4. Switch to survival mode.

  5. The Ravager should start going for you.

  6. Run in the house, let it hit you once through the empty doorway.

  7. Seal off the doorway with two blocks.

Result: The Ravager is still able to hit the player, from about two blocks away, with a complete wall every possible place in between.

Expected: The Ravager can't attack the player any more.

Example

An example can be seen in this comment.

Old example

I just created a villager in MCEdit with the Create Shops filter to have a custom shop. I saved it and launched MC. The villager started to run around normally in his house but then he went to the door where a zombie was knocking at (wooden door on normal difficulty) and the villager blinked red and got damage and after a few hits he died. The zombie killed him through a closed door and the villager did not run away he always came back to the door until he died.

Additional informations

From @unknown:
There are a number of bug reports about attack radius that are all very similar. MC-2310, MC-18326, MC-50668, MC-63965, MC-71834, and MC-74907 are all about the attack radius of mobs extending through blocks. (Some mobs are more bugged than others, but it’s the same basic problem).

There are also a few related issues:

  • MC-1297 is the same as the above, but for players.

  • MC-3059 is the same as the above, but for arrows.

Code analysis

Based on 1.11.2 decompiled using MCP 9.35 rc1

The problem seems to be the method net.minecraft.entity.ai.EntityAIAttackMelee.checkAndPerformAttack(EntityLivingBase, double) and methods overriding it. They all only test if the mob to attack is in a certain radius to the attacker without testing if blocks are between them.

Possible solutions

Bounding box check

The current behavior would be replaced by only allowing mobs to attack other mobs when their bounding boxes intersect.

Ray casting

The current behavior would be extended to require a ray cast from the attacker to the mob to attack (excluding liquids and blocks without collision box) to return no colliding blocks. Possible use y + height / 1.5 as attack height or have a method for mobs to define their attack height(s?). The height at which the mob to attack will be attacked could for example be y + height / 2 or with multiple tries depending on the height of the mob, for example

for (int attackFraction = 0; attackFraction < height / 2; attackFraction++) {
    double attackHeight = y + height * ((attackFraction + 1.0) / (height / 2.0 + 1.0))
}

Linked issues

MC-15127 Zombies can Hit NPCs Through Doors. Resolved MC-18326 Hit by mob through solid wall Resolved MC-20142 Zombies hit me through doors Resolved MC-23919 Baby Zombies can attack through doors. Resolved MC-24069 zombie glitch Resolved

Attachments

Comments 100

Michael Irvine

I know I'm not a mod but I think I know the problem. Zombies can't hit mobs but can break doors when they are closed. If the door is open, the zombie can hit mobs but can't break it down. If you place the door sideways, then put it in the open position, zombies can hit mobs (like the villager) through doors. Th other problem might be that Createshops filter was messing it up. If the zombie is making the banging noises than Createshops is the problem. If not it could be either one. I may also be completely wrong.

Andrew Anthony

We're seeing this on naturally generated villages in our vanilla server.

This can sometimes happen to players (tested 1.6.2) and will always occur with baby zombies.

This is a really annoying problem which I hope is fixed soon. Confirmed to still be an issue on Mineraft 1.6.2 with Java 7 update 25 64-bit.

Maybe this issue should be re-opened. I ran some tests in a creative world and it appears that villagers seem to crowd,mostly around the door, in one or several houses at night.

Because the zombies group before the door and then start hitting the villagers through the door somehow, if one villager turns into a zombie, your whole villager population is killed in one sweep.

90 more comments

In 23w32a

Finally, zombies can't hit you through doors anymore. Good job Gnembon!

Woah, amazing to see this fixed.

Still happens sometimes in 23w33a with spiders.

That's tracked in MC-264915.

Alexander Spielvogel

[Mod] markderickson

gnembon

Confirmed

Platform

Very Important

Entities, Hitboxes

attack, damage, kill

Minecraft 1.4.3, Snapshot 13w05b, Minecraft 1.5.1, Minecraft 1.5.2, Minecraft 1.6.1, ..., 1.19.3, 1.19.4, 23w13a, 1.20.1, 23w32a

23w33a

Retrieved