I'm making more weapons in minecraft with command blocks. I have been able to create a bow with explosive arrows, but I can't figure out how to make it so you can shoot multiple arrows and then click with an item in your hand to explode the arrows. This would be like launching c4 with a bow. Thanks.
Minecraft Java Edition – How to Implement Remote Detonation Arrows
minecraft-commandsminecraft-java-edition
Related Solutions
This is not going to be that easy of a thing to implement.
Summoning mobs relative to anything other than the coordinates that the command block is sitting relies on the /execute
command, which executes a command relative to another entity. Particles aren't entities, so we cannot execute any command whatsoever relative to where the particles occur. It's not that it's difficult to do, it's simply not possible.
I'd suggest working relative to the snowball itself, except there's no way to tell when they hit something. They're destroyed once they hit something. However... we can do some magic with armor stands.
We're going to need a scoreboard too. So go ahead and set up a scoreboard called "AGE" (or call it whatever you want, but remember to replace it where relevant).
/scoreboard objectives add AGE dummy
This will keep track of how old our entities are. Kind of. You'll see in a minute.
Place 7 command blocks in a line. These should be set up using a repeat command block at the beginning, and chain command blocks through the rest of the line. Make sure all of them are set to unconditional/always on. This will continuously pulse them every game tick with minimal lag. We need 2 of these guys to increment the AGE
score for armor stands and snowballs:
/scoreboard players add @e[type=Snowball] AGE 1
/scoreboard players add @e[type=ArmorStand] AGE 1
For brand new snowballs (snowballs with an AGE score exactly 1), we need to summon an invisible armor stand at the position of that snowball:
/execute @e[type=Snowball,score_AGE=1,score_AGE_min=1] ~ ~ ~ summon ArmorStand ~ ~ ~ {NoGravity:1,Invisible:1}
These armor stands will have their age scores incremented by the previous command we set up. From here, we need to move that armor stand to the snowball that summoned it, which in for our purposes is the snowball nearest to it. The c=C
selector argument is useful here. It selects the nearest C entities that match the rest of the selector (selecting the oldest if there is a tie). So the command we'll want is as follows:
/execute @e[type=Snowball,score_AGE_min=2] ~ ~ ~ tp @e[type=ArmorStand,c=1] @e[type=Snowball,c=1]
What this command does is executes the /tp
command for all snowballs that are old enough to also have a matching armor stand, which moves the armor stand along the arc of the snowball as long as it exists.
We'll be using the AGE score from the armor stand to determine where creepers need to be sent, however, we don't want to do that as long as the snowball is still in the air. I handled this by setting the AGE score of all armor stands with a corresponding snowball to 0:
/execute @e[type=Snowball,score_AGE_min=2] ~ ~ ~ scoreboard players set @e[type=ArmorStand,c=1] AGE 0
This causes each snowball to set the AGE score of their corresponding armor stands to 0. Effectively, what this means is as long as the snowball is in flight, the corresponding armor stand will not age.
Finally, the creeper. For all armor stands that have aged, we want to summon a creeper and then kill that armor stand:
/execute @e[type=ArmorStand,score_AGE=2,score_AGE_min=2] ~ ~ ~ summon Creeper ~ ~ ~ {Fuse:0,NoAI:1}
/kill @e[type=ArmorStand,score_AGE_min=3]
This is quite a bit more complicated than you probably wanted, but it works well. The only real issue with it comes if you throw multiple snowballs in rapid (read: immediate) succession. In that case, you will end up with a creeper in your face (which is less than ideal). Think of it like your explosive snowball hit the other explosive snowball (which is essentially what is happening). Throwing them with reasonable timing, or in different directions produces good results.
In 1.8 you cannot rely on arrows items specifically, as no item data is transferred to the entity.
However, the bow will modify the arrow's damage
value depending on the Power enchantment level. You can provide the player with a bow containing a specific Power level and then target arrows that have a particular amount of damage.
damage
will normally be 2.0. If Power exists on the bow, the value is incremented by 0.5 and then for each level of Power, it will increase by another 0.5. For example, a Power 3 bow would result in a damage value of 4.0.
Example bow to provide:
/give @p minecraft:bow 1 0 {ench:[{id:48s,lvl:3s}]}
You can assign a score to arrow entities based on their damage
tag value.
Objective to create:
/scoreboard objectives add BowType dummy
Example commands to run on a clock, assigning scores to specific arrows (Power 3 to Power 5):
/scoreboard players set @e[type=Arrow] BowType 1 {damage:4.0}
/scoreboard players set @e[type=Arrow] BowType 2 {damage:4.5}
/scoreboard players set @e[type=Arrow] BowType 3 {damage:5.0}
And you can target arrows based on their score.
/say Arrows shot from a Power 3 bow: @e[type=Arrow,score_BowType_min=1,score_BowType=1]
Related Topic
- Minecraft Command Blocks – How to Create a Rain of Arrows in Vanilla Minecraft
- Minecraft – Shooting specific arrows from specific bows
- Minecraft – Making Arrows Fly Faster [1.12]
- Minecraft arrows with custom effects, choose what tipped arrow you shoot
- Minecraft – The repeating command block gives me a new bow when I try to shoot. How to fix that
Best Answer
What you have to do is put a tag on the arrow when the player is shooting it. If you have any special requirements and tags for the player, put it in the []. If there aren't any tags, get rid of the [].
If you put this on a repeating command block, all arrows shot from the player will have the c4 tag.
Then, create a scoreboard called "click".
Just for working with it, set it to the sidebar.
Now whenever you right click with a carrot on a stick, you will add 1 to your click score.
Make a chain coming from that first repeating command block with the following commands in this order.
If you want to add more effects to the arrows before they are killed, use
and add it after the first command block. I hope this helped!