1

(Solved) Detect Attack Damage of Held Item?

Drake__archer's Avatar Drake__archer3/8/24 9:51 pm history
1 emeralds 123 5
3/9/2024 9:00 am
mega7's Avatar mega7
In my Data Pack, I want to make it so if the Player holds an item with an Attack Damage 8 or greater, (like a Netherite Sword), then they will be given an advancement.

But I can't seem to figure it out, here's my command below in case I am doing something wrong:
/execute as @a[​nbt={SelectedItem:{tag:{AttributeModifiers:[{AttributeName:"generic.attack_damage",Amount:7s,Operation:0,UUID:[I;0,0,0,0]}]}}}] run execute as @s[​nbt={SelectedItem:{tag:{AttributeModifiers:[{AttributeName:"generic.attack_damage",Amount:8s..}]}}}] run advancement grant @s only minecraft:story/mine_stone

P.S, I am just using Stone Age as a placeholder to see if this even works.

If someone could make a single function/command that would accomplish this, that would be great!

Any help would be greatly appreciated!

EDIT: This problem has already been solved! If you want the solution for yourself, you can go down in the comments to the one before my latest one, and that comment by mega7 will contain the answer.
Posted by Drake__archer's Avatar
Drake__archer
Level 10 : Journeyman Modder
9

Create an account or sign in to comment.

5

1
03/09/2024 2:49 amhistory
Level 45 : Master Cupcake
mega7
mega7's Avatar
Perhaps you could run an execute result to a command that gets the value of the attack damage attribute of held item. and store it into a scoreboard. Then execute if it is above 8 it gives you the advancement.

I think you could even achieve that with one advancement if i'm correct.
If i have time today i'll send you the commands.
1
03/09/2024 4:03 am
Level 45 : Master Cupcake
mega7
mega7's Avatar
Yeah you can't do it with advancement alone. Use the way i provided first.
3
03/09/2024 4:19 amhistory
Level 45 : Master Cupcake
mega7
mega7's Avatar
Make a function and name it for example. "attack_damage_detector.mcfunction" or whatever you want.
Create a scoreboard objective and make it a dummy in load.mcfunction,

Put those three in the attack_damage_detector function:
execute store result score @s dummy_score_you_made run attribute @s generic.attack_damage get
execute if score @s dummy_score_you_made matches 8.. run advancement grant @s only (your advancement)
scoreboard players reset @s dummy_score_you_made

And make a command in tick.mcfunction that runs this function repeatedly for any person without your advancement.
Would look something like this:

execute as @a[​advancements={namespace:advancement_location=false}] run function namespace:attack_damage_detector

Note that you can put the location of the files whereever you want just don't forget to put its right directory
2
03/09/2024 8:20 am
Level 10 : Journeyman Modder
Drake__archer
Drake__archer's Avatar
Thank you so much! This worked so well!
1
03/09/2024 9:00 am
Level 45 : Master Cupcake
mega7
mega7's Avatar
Glad it worked thumb_up_alt
Planet Minecraft

Website

© 2010 - 2024
www.planetminecraft.com

Welcome