As @AakashM pointed out, Bresenham is not suitable for this problem.
I found this code and adapted it to work with negative coordinates and so on:
function lineBlocksIntersection(line) {
var oX = line[0][0], oY = line[0][1], oZ = line[0][2],
dX = line[1][0], dY = line[1][1], dZ = line[1][2],
x = Math.floor(oX), y = Math.floor(oY), z = Math.floor(oZ),
intBound = function(s,ds) { return ds > 0? (Math.ceil(s)-s)/ds: (s-Math.floor(s))/-ds; },
tMaxX = intBound(oX,dX), tMaxY = intBound(oY,dY), tMaxZ = intBound(oZ,dZ),
sign = function(x) { return x > 0 ? 1 : x < 0 ? -1 : 0; },
stepX = sign(dX), stepY = sign(dY), stepZ = sign(dZ),
deltaX = stepX/dX, deltaY = stepY/dY, deltaZ = stepZ/dZ,
fX, fY, fZ, ret, block;
for(;;) {
if(tMaxX <= tMaxY && tMaxX <= tMaxZ) {
x += stepX;
if(dX < 0? x < oX+dX: x > oX+dX)
break;
tMaxX += deltaX;
fX = stepX; fY = 0; fZ = 0;
} else if(tMaxY <= tMaxX && tMaxY <= tMaxZ) {
y += stepY;
if(dY < 0? y < oY+dY: y > oY+dY)
break;
tMaxY += deltaY;
fX = 0; fY = stepY; fZ = 0;
} else {
z += stepZ;
if(dZ < 0? z < oZ+dZ: z > oZ+dZ)
break;
tMaxZ += deltaZ;
fX = 0; fY = 0; fZ = stepZ;
}
block = getBlock(x,y,z);
if(block) {
if(!ret)
ret = [];
ret.push([[x,y,z],block,[fX,fY,fZ]]);
}
}
return ret;
}