Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

2
How to trigger a function to run as @s after advancement
Post Flair (click to view more posts with a particular flair)
Post Body

Hey there everyone, hoping someone can either confirm my suspicion and suggest an alternative approach or help me correct my mistake.

I am currently working on a data pack what I would like to do is create a damage indicator that shows after hitting a mob when the player is holding a particular item in their offhand. I had planned on doing this via a custom advancement using the player_hurt_entity trigger and a scoreboard set up to track minecraft.custom:minecraft.damage_dealt. Everything seems to work properly expect the damage number that displays is incorrect.

After loads of testing I think the issue is that the damage_dealt statistic is updated after the player_hurt_entity trigger is set off. So when the code runs I am always displaying the previous damage dealt and not the current. The only thing I could think of doing is running the display function as @s after the advancement has already completed and the statistic is updated but I can't think of how to do that automatically without the player triggering some other action. I tried using a different scoreboard and an 'execute if' statement in the tick function but I couldn't get anything to work as @s (which I assume is because there is no entity executing the function). Below is some of my code to try and help clarify a little.

Any help at all would be greatly appreciated!

load.json { "values": [ "DataPackName:load" ] }

load.mcfunction scoreboard objectives add damagetracker minecraft.custom:minecraft.damage_dealt scoreboard players set @a damagetracker 0 execute as @a run setblock -17 -62 -21 oak_sign{front_text:{color:"red",has_glowing_text:1b,messages:['[{"text":"Damage ","color":"red"},{"score":{"name":"@p","objective":"damagetracker"}}]','{"text":""}','{"text":""}','{"text":""}']}} replace

damage_indicator.json ``` { "criteria": { "name": { "trigger": "minecraft:player_hurt_entity", "conditions": { "entity": { "offhand":{ "item":"minecraft:carrot" }

            }
        }
    }
},
"rewards": {
    "function": "DataPackName:display_damage_dealt"
}

} ```

display_damage_dealt.mcfunction tag @s add this summon item ^ ^1.5 ^2 {CustomNameVisible:1b,Age:5990,PickupDelay:100,Motion:[0.05,0.3,0.05],Tags:["new"],CustomName:'{"text":"null"}',Item:{id:"minecraft:stone_button",Count:1b}} data merge block -17 -62 -21 {front_text:{color:"red",has_glowing_text:1b,messages:['[{"text":"Damage "},{"score":{"name":"@p","objective":"damagetracker"},"color":"red"}]','{"text":""}','{"text":""}','{"text":""}']}} data modify entity @e[type=item,tag=new,limit=1] CustomName set from block -17 -62 -21 front_text.messages[0] tag @e[type=item,tag=new] remove new tag @s remove this scoreboard players reset @s damagetracker advancement revoke @s only DataPackName:damage_indicator

Author
Account Strength
50%
Account Age
2 years
Verified Email
Yes
Verified Flair
No
Total Karma
5
Link Karma
4
Comment Karma
1
Profile updated: 1 week ago
Posts updated: 8 months ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
1 year ago