… This all works great, as long as I’m only using 1 tileset. But if the tile to the right is actually from a different tileset, then actually I wouldn’t want this rule to apply, I’d want the corner rule to apply instead, to create a clear separation between the 2 tiles.
It’s possible, but probably not in the way you’d want: you’d have to enumerate the tiles you want to “count” instead of using NonEmpty, with an input layer for each different tile.
If you have more than a few tiles in this tileset, this can get very tedious to do. My Automap Helper script can help: it has an action to create automapping layers en masse (so if you need to match 50 tiles, you can create those 50 input layers all at once), and another action that lets you take the single-layer brush you get when you select those tiles in the tileset and transform it to instead place 1 tile onto each of those layers. So for N tiles in your tileset, you’d create N input layers using the “Generate AutoMap Layers” action, then select all those tiles, select the input layers you created, and then use the “Convert Brush to Layers” action, which should give you a brush with N layers that will paint to your N input layers all at once. If you need to switch to other tiles and then back to your stack of N tiles again, you can select those input layers and copy+paste one of the stacks from them, no need to repeat this whole scripted process.
There are Automapping-based ways you can avoid enumerating tiles in all your rules. For example, you can have Automapping generate a guide layer that has a representative tile for each tileset, so your other rules can look at these representative tiles instead. However, all such approaches will involve enumerating the relevant tiles at some point in the process, and whether it’s worthwhile depends on your exact circumstances.