Check the neighbour-tiles, and keep a list of neighbour-tiles that actually have influence on your new tile.
If you have 8 rivertiles and 8 grasstiles, then when placing a grasstile at a riverbank you can check the neighbour-tile of the place where you put the grass. you could for example use the rivertilenumber and use that for the grassnumber.
If you have 8 rivertiles and 8 grasstiles, then when placing a grasstile at a riverbank you can check the neighbour-tile of the place where you put the grass. you could for example use the rivertilenumber and use that for the grassnumber.