First create a clock with the following commands:
execute @e[name=TPSlimeBack] ~ ~ ~ tp @e[type=Slime,name=SlimeKnock,rm=1,r=2] @e[type=ArmorStand,c=1,name=TPSlimeBack,r=2]
And:
execute @e[name=TPSlimeBack] ~ ~ ~ /effect @a[r=2] minecraft:resistance 1 100
Then summon an invisible ArmorStand
and an invisible Slime
with a size of 1
on the block where you want it to knock the player back by doing:
/summon ArmorStand ~ ~ ~ {CustomName:TPSlimeBack}
And then on the same position:
/summon Slime ~ ~ ~ {CustomName:SlimeKnock,Size:1}
This will make a Slime that knocks the players back, but that can't move out of the block's radius because it teleports back to the armour stand all the time. The player also get's a resistance effect to make sure no one loses their lives.
Edit
A much easier way to do this is just to summon a Slime on the block with the Size
of 2
and NoAI
added. Do this by running the following command:
/summon Slime ~ ~ ~ {CustomName:SlimeKnock,Size:2,NoAI:1}
(Note: The custom name isn't really needed, just to kill the slime when you want to remove it.)
What you could do to test if you left-click the sword is have some mob (ex. an slime) that is made invisible, then teleported constantly to your head. For example, you could use this command:
summon Slime ~ ~1.4 ~ {NoAI:1,CustomName:"LeftClick",CustomNameVisible:0,Size:0,ActiveEffects:[{Id:14,Duration:1000000,Ambient:1}],Attributes:[{Name:generic.maxHealth,Base:1}]}
Basically, this command summons a Slime named LeftClick which is invisible and has half a heart of health. Then, you want to make a redstone clock attached to this command:
execute @p[score_IsHolding_min=1] ~ ~ ~ tp @e[name=LeftClick] ~ ~1.4 ~
This will constantly teleport that slime to your head. So, whenever you left click, you will hit the slime, which will add one to your InfinityBlade objective score count. Additionally, remember that you have to set up some sort of command to spawn a new LeftClick slime every time you left-click, since the previous one will be killed.
The only problem with this system is that you can't actually hit anything else with the sword, since the slime is constantly being teleported to you, so whenever you left-click, you hit the slime. Unfortunately, there's no way to get around this, so if this isn't what you want, you have to find another way to detect when you want to shoot a fireball.
However, if this idea works for you, you then have to be able to detect which way the player is facing to summon a fireball in that direction. To do this, you have to use an MCEdit filter called CPDirections. This video explains how to use the filter in great detail.
Hopefully I answered all of your questions.
Best Answer
The way I know how to do this is to track who gave damage and is holding a poison sword, then execute that target and give poison to the nearest player who has taken damage.
To track who has given or taken damage, use the following scoreboard:
These scoreboards accumulate player scores for damage they give and take.
Then place these command blocks in a repeating chain:
This lets players who have given damage and is holding a diamond "Poison Sword" to give poison to the nearest player who has taken damage.
These two commands refresh the scoreboards so the machine can run again later.
Name a diamond sword "Poison Sword" and try it out. If you don't want the name to be specified, replace the first command with:
(NOTE: There might be a more efficient method than this out there, but I never had the need to learn such a method so I'm sure this will do well for now.)