Why doesn't this command fill a 4x4x4 area with ice after a splash potion flies out?

Solution 1:

Your command works for me, but it does not do what you intend it to do.

Make sure that it is in a repeating command block and that the command block is actually loaded, it may have to be powered by redstone depending on how you set it up. Please give some more details about your problem if this does not help.

Altering the command does make it work the way you explained, as long as you are in a single player world and the potion actually gets far enough.

/execute at @e[type=potion] if entity @p[distance=3..5] run fill ~2 ~2 ~2 ~-2 ~-2 ~-2 ice

It may not always work as intended if you have multiple players in your world at the same time, in that case I would suggest a two commands solution like this:

/execute as @e[type=minecraft:potion,nbt={PortalCooldown:0}] run data modify entity @s PortalCooldown set value <time>
/execute at @e[type=minecraft:potion,nbt={PortalCooldown:1}] run fill ~2 ~2 ~2 ~-2 ~-2 ~-2 minecraft:ice

I set time to 10, it works quite well for me, but you may want it to fly for longer, or shorter

This solution is time based, so it is not affected by how many players are online. I am not sure if it works with lag though. You will not be able to throw the potion into another dimension through a portal, because this command uses the portal cooldown to keep track of time.

Neither of these solutions do anything if the splash potion breaks before the effect takes place (if the potion is not far enough away from you in the first case, or if it breaks too early in the second case)

Note: This part (~2 ~2 ~2 ~-2 ~-2 ~-2) specifies a 5x5x5 volume and not 4x4x4

Note 2: The potions will set everything close to it to ice, so it may potentially break barriers, bedrock, or any decoration that you may have. You can change that by putting replace air after the fill command. Doing this will prevent it from setting grass to ice though and it will not work under water anymore, so it may not always work in those situations.

/execute at @e[type=potion] if entity @p[distance=3..5] run fill ~2 ~2 ~2 ~-2 ~-2 ~-2 ice replace air

Note 3: Throwing the potion directly at your target may break it, before it "explodes", making it uneffective