Instead of all of this use updateDialog(), it is more efficient as it will know if the machine is being used or not before updating the dialogs of all the mobs around it, and it correctly updates for AIs.