Mojira Archive
MC-48616

All Mobs move extremely slowly in water

I tamed a group of dogs and then tried to go across a body of water on a boat. The dogs jumped in the water but almost couldn't move. They also never ported over to me as I moved away from them. I went 1000 blocks before I noticed they weren't following me. When I went back they were still stuck in the water where I first got on my boat. As a side note I've noticed most mobs moving slower than normal in water.


Comments from Ioan Vira:
Tested in 14w34c. Please add this into the description. Maybe Mojang will fix this before the 1.8 release.

Testcase:
1. Set creative mode. Find a lake. Equip enough zombie spawn eggs and a sword.
2. Set survival mode. Set night.
3. Spawn a zombie and attract him into the water, by keeping the same direction of movement.
Observed behavior: The zombie moves with a reasonable speed (just a bit slower in the water)
4. Change the direction of movement.
Observed behavior: The zombie will change direction to follow the player and his movement speed becomes almost 0.


I made some research based on the latest Forge.
The problem is located in class EntityLivingBase method onLivingUpdate

Here is a pseudo-code:

/**onLivingUpdate is called frequently so the entity can update its state every tick as required.*/
call onLivingUpdate 
    if motionX < 0.005 set motionX = 0
    if motionY < 0.005 set motionY = 0
    if motionZ < 0.005 set motionZ = 0

    call moveEntityWithHeading(float strafe=0, float forward=0.0067620003)
        if entity is in water then set friction = 0.02
        call moveFlying(float strafe, float forward, float friction)
            motionX = motionX + something what depends on strafe forward friction
            motionZ = motionZ + something what depends on strafe forward friction
        end moveFlying
        // for a normal zombie which is turning in water, motionX and motionZ will be approximately 0.0045.
        // this value will be reset to 0 at the next onLivingUpdate call
        // therefore entities will never be able to speed up in water if they make the mistake to stop and turn around

        // moveEntity tries to move the entity by the passed in displacement
        call moveEntity(motionX, motionY, motionZ)
    end moveEntityWithHeading
end onLivingUpdate

Note: moveFlying is called always. The name chosen by Forge guys is misleading.
A friction value = 0.03 would solve the problem. To be tested with diagonal movement!!
On ground covered by snow, the friction is 0.23.
The "friction" name for this coeficient may also be misleading.
Another parameter with the same purpose is jumpMovementFactor (also 0.02). It is applied when the entity is jumping in the water and for a short time is above the water (if is a zombie, will burn a little bit)