How to create invisible villager to execute the commands as soon as you click on them and do not open the shop. In the vanilla without additional plug-in. And with a command block.
/ scoreboard objectives add taked_villager minecraft.custom: minecraft.talked_to_villager
With this scoreboard you can find out whether someone clicked on a Villager. After that, you just have to kill him
And how do you create a villager that is invisible? And how does he know which Villager was tapped?
You spawn the Villager like this:
/ summon minecraft: villager ~ ~ ~ {Tags: ["klick"], ActiveEffects: [{Id: 14b, Amplifier: 1b, Duration: 1000000, ShowParticles: 0b}]}
And find out what it was, the easiest way to do it:
/ execute as @a [scores = {taked_villager = 1.}] positioned ^ 2 if entity @e [tag = click, distance = .2] run say @s tradet with a Villager
/ scoreboard players reset @a taked_villager
The villager spwnen says: Unable to summon object