How does one make a lightning sword in vanilla Minecraft?

I've been doing some research on making lightning swords or items, but the only working things seem to be server plugins. I'm trying to achieve the same effect with command blocks in Minecraft 1.8.8.

There probably is a way using scoreboard, execute and summon commands. The thing I'm trying, however, is to make the lightningBolt entity spawn where I click. Does anyone know how to do this?


Solution 1:

You can create a lightning stick using these commands in a command block:

/testfor @e[type=Player] {SelectedItemSlot:0}

/execute @e[type=*InsertMobNameHere*] ~ ~ ~ summon LightningBolt ~ ~ ~

You can also create lightning arrows:

/execute @e[type=Arrow,c11] ~ ~ ~ summon LightningBolt

/kill @e[type=Arrow]

To receive a command block, you can type in the command chat:

/give @p minecraft:command_block 64

Solution 2:

Late to the party, but you can use this. /execute at [player] run summon minecraft:lightning_bolt ~ ~ ~ Summons summons lightning bolt at player position. ~ ~ ~ is needed. You can also use @r, @a and others in place of [player]. Apparently you need the at part before the run part.