You can perhaps think of substances such as beancurd, cheese, butter, as being masses, uncountable except in packets, containers, etc. Things like salt, pepper, sugar, rice, etc, are collections of small particles, almost too small to see individually, so it's possible to think of the collections as uncountable masses. Slightly larger things, such as peas, lentils, and noodles, can be considered as things that are interesting only when there are many of them, so we normally use the plural form. Vegetables such as cabbage, cauliflower, spinach, are eaten boiled, sliced, shredded, so that we do not see them on the plate as individual vegetables, unlike carrots. When countable potatoes are mashed, they become uncountable mashed potato. When countable eggs are scrambled, they usually, but not always, become uncountable scrambled egg.
Looking at things in this way may help, but sometimes you just have to accept that some words appear to be used fairly arbitrarily in countable or uncountable ways.