This is fine if it can place the block, but if in your example, the block it tried to change was already stone, it would say that it can't place the block in chat, even with that set to false. So we can add a check and only replace the block if it's not already stone:
tellraw @a {"text":"block","clickEvent":{"action":"run_command","value":"/execute unless block ~ ~-1 ~ stone run setblock ~ ~-1 ~ stone"}}
The above is probably what you are after. Couple more options below though.
You could use the clickEvent to place a redstone block that powers two command blocks, the first command would remove the redstone block just placed so it can be placed again and run the command again, the second one would be whatever command you wanted.
You could change the command to:
/setblock ~ ~-1 ~ stone destroy
Although this would drop the block when activated which is probably not what you want.
No problem, although if it can't place the block it will still show the error in chat, which is why I added the check to only place the block if the block it's trying to replace is not the same. That way we don't get the ugly error message in chat either.
is it possible to make the command triggered by clicking on the text not displayed in the chat?
For example:
/tellraw @a {"text":"block","clickEvent":{"action":"run_command","value":"/setblock ~ ~-1 ~ stone"}}
but so that the information about the placement of the block is not shown in the chat.
Version: Java 1.19
You could use:
This is fine if it can place the block, but if in your example, the block it tried to change was already stone, it would say that it can't place the block in chat, even with that set to false. So we can add a check and only replace the block if it's not already stone:
The above is probably what you are after. Couple more options below though.
You could use the clickEvent to place a redstone block that powers two command blocks, the first command would remove the redstone block just placed so it can be placed again and run the command again, the second one would be whatever command you wanted.
You could change the command to:
Although this would drop the block when activated which is probably not what you want.
Oh, thank you. I didn't think it could be solved so easily with one gamerule.
No problem, although if it can't place the block it will still show the error in chat, which is why I added the check to only place the block if the block it's trying to replace is not the same. That way we don't get the ugly error message in chat either.