1

Currently, I have 3 bows that shoot arrows, and when each arrow strikes the ground (detects if in ground by inGround=1b tag), it will summon lightning, tnt, anvils, or whatever doohickey thing I'm able to think about.

This works pretty well, but sometimes, when I want to "target" a mob, I would have to shoot it at it's feet. And that's pretty annoying when sometimes, it will hit the mob, causing nothing to happen.

Is there a tag that detects if an arrow is in a mob? I remember there was a tag for detecting if an arrow is in a player (maybe player:1b?), but is there one for mobs?

If there isn't, is there a way to detect if an arrow is near a mob? That would be the closest thing I need for my project.

Thanks!

3
  • I'm almost certain you cannot detect an arrow in any entity, as the arrow itself isn't an entity anymore. If you think you can on a player, please provide the nbt.
    – BunnyMerz
    Nov 13, 2021 at 14:41
  • @BunnyMerz edited, maybe edit your answer?
    – AlexJaynMF
    Nov 14, 2021 at 11:10
  • Why? It answers your question. It detects both an arrow passing by an entity and when an arrow hits an entity. If you want to detect for how long the arrow stays in that entity, you can give them a score that decreases overtime.
    – BunnyMerz
    Nov 14, 2021 at 19:22

2 Answers 2

2

When the arrow is shot, summon an identical arrow with a marker riding it. Copy over the relevant nbt data, like motion. Now, you have replaced the original arrow with an arrow that has a marker riding it.

When the arrow hits the mob, the marker will be left over. You can use a predicate to check if your marker is no longer riding. Then, you can execute your commands with 100% certainty that it hit a target, and where.


A possible solution might look like this:

Repeating every tick:

#Replace arrow
execute as @e[type=arrow,tag=!new_arrow] at @s run summon arrow ~ ~ ~ {Tags:["new_arrow"],Passengers:[{id:"minecraft:marker",Tags:["arrow_rider"]}]}

execute as @e[type=arrow,tag=!new_arrow] at @s run data modify entity @e[type=arrow,tag=new_arrow,limit=1] Motion set from entity @s

kill @e[type=arrow,tag=!new_arrow]


#Event
execute as @e[type=marker,predicate=!<namespace>:is_riding_arrow] run summon lightning_bolt ~ ~ ~
execute as @e[type=marker,predicate=!<namespace>:is_riding_arrow] run playsound entity.wolf.hurt master @p

kill @e[type=marker,predicate=!<namespace>:is_riding_arrow]

Predicate file named is_riding_arrow.json located in <datapackname>/data/<namespace>/predicates/:

{
  "condition": "minecraft:entity_properties",
  "entity": "this",
  "predicate": {
    "nbt": "{Tags:[\"arrow_rider\"]}",
    "vehicle": {
      "type": "minecraft:arrow"
    }
  }
}
2
  • I'm terribly sorry, but would you mind writing the code for that? I'm a beginner in command blocks, I've learnt quite a lot of things, like execute and how to use scoreboards, but I'm still in the dark in some of these things. Thanks!
    – AlexJaynMF
    Nov 16, 2021 at 10:58
  • @AlexJaynMF I provided a possible solution. Keep in mind that it uses a datapack, and I haven't tested it.
    – ginkgo
    Nov 16, 2021 at 23:36
0

We are gonna:

  • Detect an entity who was hurt and has tag
  • Remove all tags
  • Tag all entities who are nearby an arrow

Which are translated to:

execute as @e[tag=possible,nbt={HurtTime:10s}] run <your command>
tag @e remove possible
execute as @e[type=minecraft:arrow,nbt={inGround:0b}] at @s run tag @e[distance=..4] add possible

Note here, at the last command, we have @e[distance=..4]. The reason we use 4 (a big number) is that arrows travel too fast. If you lower that number, arrows shot at max speed may not trigger this.

The problem with having such a big number, is that any mob hurt while an arrow is flying by will activate it. This requires timing, but it is easy to do on purpose.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .