0

I'm writing a function for a datapack in Minecraft. After /reloading, /function couldn't find the function, so I pasted each line into Minecraft to check for syntax and other errors. I found that the problem was in the commands that store the aoecloud's position into a scoreboard, and also in the ones that take those values and place them into the Motion nbt for an arrow. The issue is that according to Minecraft, only one entity is allowed in the target selector while my target selector is selecting multiple. I tried using a customName to fix this problem but it didn't work. How can I get the target selector to select the arrow/aoecloud created at the top of the function and not give me errors?

summon minecraft:arrow ^ ^ ^1 {pickup: 0, Tags:["sniperbullet"], CustomName:"\"sniperbullet\""}

summon minecraft:area_effect_cloud 0 0 0 {Tags:["sniperaoecloud"], CustomName:"\"sniperaoecloud\""}
execute as @e[type=minecraft:area_effect_cloud, tag=sniperaoecloud] at @e[type=minecraft:area_effect_cloud, tag=sniperaoecloud] rotated as @a[scores={gunshots=1..},nbt={SelectedItem:{tag:{display:{Name:"{\"text\":\"Sniper Rifle\"}"}}}}] run tp @s ^ ^ ^1

scoreboard objectives add sniperx dummy
scoreboard objectives add snipery dummy
scoreboard objectives add sniperz dummy

execute as @e[type=minecraft:area_effect_cloud, tag=sniperaoecloud, name=sniperaoecloud] store result score @s sniperx run data get entity @s Pos[0] 10000
execute as @e[type=minecraft:area_effect_cloud, tag=sniperaoecloud, name=sniperaoecloud] store result score @s snipery run data get entity @s Pos[1] 10000
execute as @e[type=minecraft:area_effect_cloud, tag=sniperaoecloud, name=sniperaoecloud] store result score @s sniperz run data get entity @s Pos[2] 10000

execute as @e[type=minecraft:arrow, tag=sniperbullet, name=sniperbullet] store result entity @s Motion[0] double 0.0001 run execute as @e[type=minecraft:area_effect_cloud, tag=sniperaoecloud, name=sniperaoecloud] run scoreboard players get @s sniperx
execute as @e[type=minecraft:arrow, tag=sniperbullet, name=sniperbullet] store result entity @s Motion[1] double 0.0001 run execute as @e[type=minecraft:area_effect_cloud, tag=sniperaoecloud, name=sniperaoecloud] run scoreboard players get @s snipery
execute as @e[type=minecraft:arrow, tag=sniperbullet, name=sniperbullet] store result entity @s Motion[2] double 0.0001 run execute as @e[type=minecraft:area_effect_cloud, tag=sniperaoecloud, name=sniperaoecloud] run scoreboard players get @s sniperz

scoreboard objectives remove sniperx
scoreboard objectives remove snipery
scoreboard objectives remove sniperz

scoreboard players set @e gunshots 0
scoreboard players set @s reloadSniper 50

FYI the goal of this function is to spawn an arrow in front of a player and get it to fly in the direction they are looking. Also, if you catch any other errors with my code please point them out to me.

Edit: Pasted my new code above. I redid the scoreboard stuff with EarthToAccess' suggestions, and now the function runs fine. I also added another execute to get the values from the scoreboard using @s as the area_effect_cloud but also be able to put them into the arrow's motion using @s. Unfortunately, the arrows go unpredictably flying everywhere from/around the coordinates 177 3 163 (I'm on a superflat test world) even when I'm nowhere near that point instead of spawning in one block in front of me. However, they are repeatedly unpredictable, so they might go flying off 10 blocks at 90 degrees and then stop dead and drop, but if I keep my cursor at the same angle they will do it again and again the same way. If someone could explain this behavior that would be very helpful.

  • Not wanting to be difficult but what could I change about my question to make it more acceptable on this forum? (asking because of the downvote) – Nik3141 Apr 14 at 4:37
1

the problem is that @e and any selectors you use with it can be ambiguous. if literally any other entities with your specified tags exist, it would work with them too, which is why it's throwing the error.

a workaround that i've used is execute as @e and continued from there, using @s as my selector at the end of my run segment. for example;

execute as @e[type=minecraft:area_effect_cloud,tag=sniperaoecloud,name=sniperaoecloud] store result score @s sniperx run data get entity @s
  • But how do I access the scoreboard data as the area of effect cloud and store it into the arrow's Motion nbt as the arrow? – Nik3141 Apr 14 at 1:18
  • @Nik3141 With execute store, but that's an entirely new question. – Fabian Röling Apr 14 at 9:33
  • 1
    also, which is MUCH more complicated, you can scoreboard players list and try to find which entity hash (the long numbers and letters with dashes) is the Area of Effect cloud, then run commands using that hash as the username (or name=<hash> if need be). that's a lot more involved and may take a while depending on how many entities other than players have scores to them, since you'd have to simply guess-and-check your way to finding which one is your aoe cloud. that method would also probably only work best for singleplayer worlds. – EarthToAccess Apr 15 at 3:40
  • Yeah I just used stacked execute functions because it's much simpler. – Nik3141 Apr 16 at 6:30

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.