#Detect snowball throw (and/or right click)

1 messages · Page 1 of 1 (latest)

lunar orbit
#

I'm trying to execute a function with a /playsound command inside whenever the player throws a snowball. I've tried using advancements, so that when the player throws the snowball they get an advancement that has that function as a reward, and then that function would also instantly revoke the advancement. This didn't work. When I granted the advancement with commands I did get the functon to execute, and revoke the advancement, but I couldn't get the advancement to trigger by throwing a snowball.

So does anyone know how I make this work? Or shouldn't I use advancements at all?

thick auroraBOT
#

<@&1201956957406109788>

Someone will come and help soon!

💬 While you wait, take this time to provide more context and details.

🙇 If nobody has answered you by <t:1734467460:t>, feel free to use the Summon Helpers button to ping our helper team.

✅ Once your question has been resolved (or you no longer need it), please click Resolve Question or run /resolve

viscid quiver
#

How does you advancement look like?

somber hazel
#

You could possibly use a scoreboard, or have a custom enchantment with the spawn_projectile field that runs whatever functions you need on the snowball

lunar orbit
#

{
"criteria": {
"snowball": {
"trigger": "minecraft:using_item",
"conditions": {
"item": {
"items": [
"minecraft:snowball"
]
}
}
}
},
"requirements": [],
"rewards": {
"function": "mkbl:warden_charge"
}
}

lunar orbit
#

The advancement does show up when I type the command to grant it

#

And it triggers with the command, but it doesn't trigger when throwing one

viscid quiver
#

ah, ok.

using_item only works for items that can be used constantly (eg. draw a bow)

lunar orbit
#

Oh I didn't know. So what should I use?

#

Or is it not possible to detect this with advancements?

viscid quiver
#

There is no advancement that can detect a single use without targeting a block. Like angelwings said, you have to use the using statistic scoreboard for snowballs and detect if that score is greater than 0.

#

or a enchantment but this will be impractiacal on snowballs

lunar orbit
#

I'm not that great with scoreboards. Could you perhabs help me set it up?

keen martenBOT
#

it's a little more simple than using an advancement:

  1. create a scoreboard in your load function:
#namespace:load
scoreboard objectives add <scoreboard name> minecraft.used:minecraft.snowball

(most scoreboard types track the statistics, and this one tracks the times you used a snowball)

  1. in the tick function, check if the score is bigger than 0:
#namespace:tick
execute as @a[scores={<scoreboard name>=1..}] run function <namespace>:foo
  1. reset the scoreboard for that player in the called function
#namespace:foo
scoreboard players reset @s <scoreboard name>
lunar orbit
#

Tysm, I'll try it as soon as I get home

lunar orbit
#

It worked, thanks!