Java Code Examples for net.minecraft.entity.Entity#isSprinting()

The following examples show how to use net.minecraft.entity.Entity#isSprinting() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MobAI.java    From fabric-carpet with MIT License 6 votes vote down vote up
/**
 * Not a replacement for living entity jump() - this barely is to allow other entities that can't jump in vanilla to 'jump'
 * @param e
 */
public static void genericJump(Entity e)
{
    if (!e.onGround && !e.isInFluid(FluidTags.WATER) && !e.isInLava()) return;
    float m = e.world.getBlockState(new BlockPos(e)).getBlock().getJumpVelocityMultiplier();
    float g = e.world.getBlockState(new BlockPos(e.getX(), e.getBoundingBox().y1 - 0.5000001D, e.getZ())).getBlock().getJumpVelocityMultiplier();
    float jumpVelocityMultiplier = (double) m == 1.0D ? g : m;
    float jumpStrength = (0.42F * jumpVelocityMultiplier);
    Vec3d vec3d = e.getVelocity();
    e.setVelocity(vec3d.x, jumpStrength, vec3d.z);
    if (e.isSprinting())
    {
        float u = e.yaw * 0.017453292F;
        e.setVelocity(e.getVelocity().add((-MathHelper.sin(g) * 0.2F), 0.0D, (MathHelper.cos(u) * 0.2F)));
    }
    e.velocityDirty = true;
}