mojira.dev
MC-76416

Player can interact with dying mobs

The bug

Player can interact with with mob while their dying animation is happening. This can partwise result in mobs in invalid states, entity "duplication" and other unwanted situations.

Affected situations

Situation

Note

shearing sheep

-

taming wolf

results in alive tamed wolf with dying animation

taming ocelot

-

feeding (baby) animal

-

shearing mushroom

-

using name tag

-

using leash

leash is used but instantly dropped at position of mob

using flint and steel on creeper

creeper is not ignited but flint and steel loses durability

shearing snowman

-

saddling pig

-

using spawn egg on breedable mob

-

How to reproduce (sheep)

  1. Spawn a Sheep

  2. Punch sheep 7 times with bare hands

  3. Punch and shear the sheep at the same time (left and right click quickly)

  4. You will get 4 blocks of wool

Code analysis

Based on 1.11.2 decompiled using MCP 9.35 rc1

The problem is that the method net.minecraft.entity.player.EntityPlayer.interactOn(Entity, EnumHand) does not prevent interaction with dying mobs. Or all methods overriding the method net.minecraft.item.Item.itemInteractionForEntity(ItemStack, EntityPlayer, EntityLivingBase, EnumHand) or net.minecraft.entity.EntityLiving.processInteract(EntityPlayer, EnumHand).

Linked issues

Comments 8

Ezekiel

How do you shear and punch it at the same time?

Minecraft

Right and left click at the same time (you have to be fast)

KingSupernova

Confirmed. The description is slightly misleading, the actual bug is that dead sheep can be sheared. Kill the sheep and then shear the corpse.

Tan Chin Cheern

Confirmed.

marcono1234

Confirmed for

  • 16w06a

marcono1234

Please link to this comment in the description

The following is based on decompiled version of Minecraft 1.8 using MCP. All method and class names are the names used in the decompiled version.

The reason for this is that the method public final boolean interactFirst(EntityPlayer playerIn) of the class net.minecraft.entity.EntityLiving does not test if the entity is already dead. Because an entity is not instantaneously removed once it is dead, the player can still (like it is visible with this bug) interact with the entity even though it is dead. This could be fixed by only allowing interaction if the entity is not dead.

/**
 * First layer of player interaction
 */
public final boolean interactFirst(EntityPlayer playerIn)
{
	// Added this
	if (this.isDead || this.dead) {
		return false; 
	}
	else {
		// ...
	}
}
JUE13

Confirmed for 1.12.1.

You can also put a saddle on a dead pig, which could lead to the fact that the saddle disappears.

Kraif

Confirmed for 1.13.1.

Minecraft

migrated

Confirmed

Minecraft 1.8, Minecraft 1.8.1, Minecraft 1.8.2-pre1, Minecraft 1.8.2-pre4, Minecraft 1.8.3, ..., Minecraft 1.13-pre10, Minecraft 1.13, Minecraft 18w30b, Minecraft 18w31a, Minecraft 1.13.1

Minecraft 19w11a

Retrieved