1

I'm trying to make a command block setup that will spawn a fireball above the player when a specific named sword is used. I'd also like to copy the players direction to the fireball. Finally, I'd also like to add some potion effects. I've got the following commands:

/scoreboard objectives add IsHolding dummy
/scoreboard objectives add InfinityBlade stat.useitem.minecraft.golden_sword    

/scoreboard players set @a IsHolding 0
/scoreboard players set @a IsHolding 1 {SelectedItem:{tag:{display:{Name:"Infinity Blade"}}}}
/effect @a[score_IsHolding_min=1] minecraft:regeneration 1 1
/effect @a[score_IsHolding_min=1] minecraft:strength 1 1
/execute @a[score_IsHolding_min=1,score_InfinityBlade_min=1] ~ ~ ~ /summon Fireball ~ ~2 ~ 
/scoreboard players set @a InfinityBlade 0

The problems are that it's necessary to hit a mob in order to spawn the fireball, and that the fireball doesn't go in the direction that the sword is used.

  • There should be a way to test for a player that is swinging a sword, regardless if it actually contacts a mob, although on closer inspection, I'm not seeing anything useful in the wiki. – MBraedley Dec 15 '15 at 19:49
2

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.

  • 1
    "execute @p[score_IsHolding_min=1] ~ ~ ~ tp @e[name=LeftClick] ~ ~1.4 ~" This will cause players to teleport entities names LeftClick 1.4 blocks above the entity's current position, not above the player. You need two commands: one to teleport the entity to the player (/tp @e[name=LeftClick] @p) and another to teleport the entity up 1.4 blocks from its new position (/tp @e[name=LeftClick] ~ ~1.4 ~). – Skylinerw Dec 16 '15 at 13:41
  • Thanks, but I've decided that the whole fireball think is never going to work smoothly, so I decided to use only the potion effects. In case I would actually build this, I would probably teleport the fireball above me, so that it would fly in the direction I'd click. Then I would only need a way of detecting that the fireball is gone. – Jaïr Paalman Dec 16 '15 at 21:44
  • I wouldn't use MCEdit as I'm trying to keep it "vanilla". – Jaïr Paalman Dec 16 '15 at 21:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.