Check this Stack Overflow answer by Mateen Ulhaq to see how to solve a ray plane intersection. To use the code in Godot, we could do something like this:
func _input(ev):
if ev is InputEventMouseMotion:
var camera = get_node("camera")
var camera_from = camera.project_ray_origin(ev.position)
var camera_to = camera.project_ray_normal(ev.position)
var n = Vector3(0, 1, 0) # plane normal
var p = camera_from # ray origin
var v = camera_to # ray direction
var d = 0 # distance of the plane from origin
var t = - (n.dot(p) + d) / n.dot(v) # solving for plain/ray intersection
var block_position = p + t * v
Assuming our camera node is named "camera". If we set the translation for block to the result, it will start following the mouse. To constrain the movement to individual cells, we can divide the result by cell size and round:
var block_size = 2
block_position.x = round(block_position.x / block_size) * block_size
block_position.z = round(block_position.z / block_size) * block_size
block.translation = block_position