#[1.21.5] Detect custom item

1 messages · Page 1 of 1 (latest)

pearl beacon
#

I Have 3 custom functions - Invoker, Item checker, and effect giver.

Invoker Function is as follows:

execute as @e[tag=racer] at @s run function horse_run:boostpad
execute as @e[tag=racer] at @s run function horse_run:offroad
execute as @e[tag=racer] at @s run function horse_run:jumppad
execute as @a run function horse_run:itemcheck
execute as @e[tag=racer] at @s run function horse_run:applepower```
**Item checker function is as follows:**
```execute as @a[scores={usedItem=1..}] if data entity @s SelectedItem.tag.custom_data.apple run scoreboard players set @s usedApplePower 1
#
execute as @a[scores={usedItem=1..}] run clear @p carrot_on_a_stick 1
execute as @a[scores={usedItem=1..}] run scoreboard players set @s usedItem 0```
**PowerUp function is as follows**
```execute if entity @p[scores={usedApplePower=1..}] run scoreboard players set @s applePowerStatus 82
execute if entity @p[scores={usedApplePower=1..}] run scoreboard players set @p usedApplePower 0
execute if entity @s[scores={applePowerStatus=1..}] run scoreboard players remove @s applePowerStatus 1

# Effects
execute if score @s applePowerStatus matches 1.. run effect give @s minecraft:speed 1 4 true
execute if score @s applePowerStatus matches 80 run playsound minecraft:entity.firework_rocket.launch master @a ~ ~ ~ 1 1.25 1
execute if score @s applePowerStatus matches 1.. run particle minecraft:soul ~ ~ ~ 0 0 0 0.2 2 force
execute if score @s applePowerStatus matches 1.. run particle minecraft:soul_fire_flame ~ ~ ~ 0 0 0 0.1 5 force
execute if score @s applePowerStatus matches 60 run playsound minecraft:entity.firework_rocket.launch master @a ~ ~ ~ 1 1.25 1
execute if score @s applePowerStatus matches 40 run playsound minecraft:entity.firework_rocket.launch master @a ~ ~ ~ 1 1.25 1
execute if score @s applePowerStatus matches 20 run playsound minecraft:entity.firework_rocket.launch master @a ~ ~ ~ 1 1.25 1
flint wingBOT
#

<@&1201956957406109788>

Someone will come and help soon!

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

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

pearl beacon
#

The problem:
When using item, it dissapears
but cant invoke the applepower function
by that
i mean that score usedApplePower does not add up

flint wingBOT
# flint wing <@&1201956957406109788>

<@&1166082198152159386> <@&1202694677766348840>

🙇 Helpers Arise!

Please note that you still might not immediately get a response since all helpers are human beings and volunteers (and also might be sleeping right now)

pearl beacon
#

i should also point out that when i manually add usedApplePower it works

#

so it is something with detecting, if user used the item

#

and giving the stat

vale trench
#

maybe try to describe your problem more precisely

pearl beacon
#

So im making mario kart thingy, right?

#

the apple in question, is retextured carrot on a stick

vale trench
#

cuz its gonna be easier to understand than reading code yk

pearl beacon
#

when player uses the item

#

it should give usedAppleItem stat to player (which it doesnt)

#

which then, activates applepower.mcfunction

#

which gives effects for the horse

vale trench
#

may i know the custom data of the apple?

#

like

pearl beacon
#

when manually invoking (/scoreboard set in the chat) both the stats, it works

vale trench
#

send a screenshot

pearl beacon
#

give @a carrot_on_a_stick[custom_name=[{"text":"Apple","bold":true,"color":"red"},{"text":" ","bold":true},{"text":":apple:","bold":true,"color":"white"}],unbreakable={},item_model="horse_run:apple_item",custom_data={apple:1},tooltip_display={hidden_components:[tooltip_display,unbreakable]}]

vale trench
#

so i see in item checker youre using SelectedItem.tag.custom_data.apple

pearl beacon
#

yeah

vale trench
#

which isnt really where the custom_data is stored

pearl beacon
#

awww

vale trench
#

its in SelectedItem.components."minecraft:custom_data".apple

pearl beacon
#

so if i change this to that

#

it should work

vale trench
#

i guess

#

aside from the fact that its really performance heavy

pearl beacon
#

yeah it does

#

thank you!

vale trench
#

i.e. youre running the item checker function as @a but then also using as @a in the function

pearl beacon
#

i mean

#

im no pro in this

#

i might optimize it sooner or later

#

its my first time making a datapack

#

instead of just using Cblocks

#

again, thank you!

vale trench
#

yeah, thats fine, but one good place to start is this easy optimization

#

just do if entity @s[scores={usedItem=1..}] in the item checker function

#

instead of as @s...

pearl beacon
#

oh yeah

#

cause invoker

#

yeah sure

vale trench
#

to explain, if there are 2 players, the item detect function will be run by both of them right?

#

so twice a tick

pearl beacon
#

i want every player seperately

#

like mario kart

#

if one person uses the shroom

vale trench
#

then if in the item detect function you use as @a again, it will once again split it into the players

pearl beacon
#

only they get the boost

#

no one else

#

oh okay

#

so it should be like this:

#
execute as @s[scores={usedItem=1..}] run clear @p carrot_on_a_stick 1
execute as @s[scores={usedItem=1..}] run scoreboard players set @s usedItem 0
vale trench
#

yeah so if 4 ppl are playing you'll have the function run 16 times a tick instead of 4 times

pearl beacon
#

okayy

#

yeah thanks again

vale trench
#
#
execute if entity @s[scores={usedItem=1..}] run clear @p carrot_on_a_stick 1
execute if entity @s[scores={usedItem=1..}] run scoreboard players set @s usedItem 0```
#

just changing all the as to if entity will help a lot

#

mkay good luck with the rest