Algoritm for smooth terrain given cubes and wedges only

Introduction
I have a block system just like minecraft and I want to add sand blocks which, depending on their nearest neighbours, will either turn into a wedge or stay as a cube. Basically what I want to achieve is smooth terrain only using wedges and cubes.

Here’s an example of it could look:
image

The issues
The algoritm seems obvious at first but the more you think about it the harder it gets.
What’s stopping the current figuration from turning out like this:
image
Or turning into an infinity loop like this:
71dbd8b46b44277f26161472951f0ff6

Restrictions

  • You can not create new blocks (you may only modify the blocks that exist)
  • You can only use single wedges or single blocks

Anyone have any good reads or links on this topic?
Or straight up a solution/suggestion?

you could sample the neighbours, and have a dictionary of combinations, and use something like this:

--[[
1  2  3
8  #  4
7  6  5

Wedge:
0 - normal
1 - facing forward
2 - facing right
3 - facing back
4 - facing left
]]
local t = {
    ["4"] = 4,
    ["84"] = 0,
    ["468"] = 0,
    ["123"] = 3,
    ["128"] = 3,
    -- etc
}

Yea that’s my current configuration!

  • A neightbour is only counted if it’s a block (wedges counts as empty).
  • It only checks 2, 4, 6, 8, the rest is irrelevant.

Problem is, look at the second block from the left in the gif!

It’s switching between being a wedge and a block because the block to the left is switching.
They are co-dependent, causing the cyclic behaviour which I dont know how to solve…

Maybe make the blocks independent from your terrain state, so instead of looking at what the neighbours are, you could check from a table and not modify it.

Not sure I get what you’re saying, could you elaborate?

So what I’m guessing what you do right now is check the state of a block’s neighbours, what I’m saying is that the state should be stored somewhere else like in a table and not mutated (modified).

The point of sand is for it to be dynamic. If I delete one block it should change the shape of nearby sand blocks…

You can update the state of the blocks when you delete one or add one.