How to detect a item in mainhand on MCPE using command block [duplicate]

Solution 1:

Note: This is designed for minecraft PC edition and probably won't work on mcpe so the short answer to your question is no it's impossible on mcpe but if you change to PC edition it is more than possible. The below explanation is for people who search for the same question on PC edition, sorry.

This is a fairly simple thing to do using a /testfor command and a comparator to activate a redstone system. Then using an and gate you can use other method described to test for the player atop a villager.

Detecting Shears In Hand

/testfor @a {SelectedItemSlot:0,Inventory:[Slot:0,(Place your Item Id Here),{tags:{(Item Tags Here)}}]}

Place the above command in a command block that is constantly being fed a redstone signal and then place a comparator, this will detect whenever a player is in this situation.

Detecting Atop Villager

/execute @e[type=Villager] ~ ~3 ~ /execute @p[r=1,type=Player] ~ ~ ~ /setblock (Block co-ordinates) redstone_block

Place this command in a command block that is also on a clock and then set the block co-ordinates to the other side of the and gate and then above those co-ordinates place a block with this command in it.

/setblock ~ ~-1 ~ air

Note: I haven't tested these commands so they might not work